if( !String.prototype.format ) { String.prototype.format = function() { var formatted = this; for (var i = 0; i < arguments.length; i++) { var regexp = new RegExp('\\{'+i+'\\}', 'gi'); formatted = formatted.replace(regexp, arguments[i]); } return formatted; }; }; if (!String.linkify) { String.prototype.linkify = function() { var inputText = this.replace(/\u200B/g, ""); //URLs starting with http://, https://, or ftp:// var replacePattern1 = /(src="|href="|">|\s>)?(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;ï]*[-A-Z0-9+&@#\/%=~_|ï]/gim; var replacedText = inputText.replace(replacePattern1, function($0, $1) { return $1 ? $0 : '' + $0 + ''; }); //URLS starting with www and not the above var replacePattern2 = /(src="|href="|">|\s>|https?:\/\/|ftp:\/\/)?www\.[-A-Z0-9+&@#\/%?=~_|!:,.;ï]*[-A-Z0-9+&@#\/%=~_|ï]/gim; replacedText = replacedText.replace(replacePattern2, function($0, $1) { return $1 ? $0 : '' + $0 + ''; }); //Change email addresses to mailto:: links var replacePattern3 = /([\.\w]+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim; replacedText = replacedText.replace(replacePattern3, '$1'); return replacedText; }; } if (!window.GITWidget) { var GITWidget = (function () { var gitWidgetPrefix = 'sgf-git-templates'; // Contains the prefix to the widgets var gitWidgetUrl = 'https://gitwidgets.golf.se:443'; // Contains the main widget script base url (protocol & host (and port)) var widgetIndex = 0; var loadedWidgets = {}; var gitRequireJSScriptId = '{0}-requirejs-script'.format(gitWidgetPrefix); var initialized = false; var activeInstanceCount = 0; var initializing = false; var maxTries = 100; // // Create storage for the local copy of jquery // var jQuery; // // Cross browser function to add event listener // function addEvent(ev, el, fn) { if (el.addEventListener) // W3C standard { el.addEventListener(ev, fn, false); // NB **not** 'onload' } else if (el.attachEvent) // Microsoft { el.attachEvent('on{0}'.format(ev), fn); } }; function runWithVerifiedComponents(components, callback) { execute(components, callback); } function execute(components, callback) { // Indicate a running instance. activeInstanceCount++; var script = document.getElementById(gitRequireJSScriptId); var head = (document.getElementsByTagName("head")[0] || document.documentElement); if (!script) { initializing = true; script = document.createElement('script'); script.type = 'text/javascript'; script.src = '{0}/Widget/UI/Js/require.js?v=1.24'.format(gitWidgetUrl); script.id = gitRequireJSScriptId; includeCss('{0}/widget/base.css'.format(gitWidgetUrl)); if (script.readyState) { addEvent('readystatechange', script, function () { if (script.readyState == 'complete' || script.readyState == 'loaded') { initialize(); run(components, callback); } }); } else { // Other browsers addEvent('load', script, function () { initialize(); run(components, callback); }); }; head.appendChild(script); } else { run(components, callback); } } function initialize() { if (!initialized) { var datePickerUrl = '{0}/Widget/UI/Js/ui.datepicker-sv'.format(gitWidgetUrl); var jQueryUIUrl = '{0}/Widget/UI/Js/jquery-ui.custom'.format(gitWidgetUrl); var competitionUrl = '{0}/Widget/UI/Js/competition'.format(gitWidgetUrl); var validateUrl = '{0}/Widget/UI/Js/jquery.validate'.format(gitWidgetUrl); GITWidget_requirejs.config({ baseUrl: "/Widget/UI/", paths: { "jquery": "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min", "jqueryui": jQueryUIUrl, "jqueryui.datepicker-sv": datePickerUrl, "competition": competitionUrl, "validate": validateUrl, //"validateAdditional": "https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/additional-methods" }, shim: { "jquery": { exports: "jQuery" }, "jqueryui": { deps: ["jquery"] }, "jqueryui.datepicker-sv": { deps: ["jqueryui"] }, "competition": { deps: ["jquery"] }, "validate": { deps: ["jquery"] } //, //"validateAdditional": { // deps: ["jquery", "validate"] //} } }); initialized = true; initializing = false; } } function run(components, callback) { tryRun(components, callback, 0); } function tryRun(components, callback, tries) { if (initializing) { if (maxTries > tries) { setTimeout(function () { tryRun(components, callback, tries + 1); }, 20); } return; } GITWidget_requirejs(["jquery"], function ($) { jQuery = $.noConflict(true); GITWidget_requirejs(components, function () { callback(); unload(); }); }); } function unload() { activeInstanceCount--; if (activeInstanceCount <= 0) { jQuery("#{0}".format(gitRequireJSScriptId)).remove(); initialized = false; initializing = false; activeInstanceCount = 0; } } function includeCss(href) { var head = (document.getElementsByTagName("head")[0] || document.documentElement); var style = document.createElement('link'); style.href = href; style.rel = 'stylesheet'; style.type = 'text/css'; head.appendChild(style); } // // Adds a placeholder for the widget // function createWidgetPlaceholder(id) { document.write('
'.format(id, '{0}-widget-placeholder'.format(gitWidgetPrefix), '{0}-widget-loading'.format(gitWidgetPrefix))); }; // // Generate a new widget id // function generateId() { return "{0}-widget-{1}".format(gitWidgetPrefix, widgetIndex++); }; // // Add widget placeholder and return the id // function generateWidgetPlaceholder() { // // Generate widget id // var id = generateId(); // // Add the placeholder where the script is called // createWidgetPlaceholder(id); return id; }; // // Helper // function createRequestData(controller, cfg) { cfg.requestUrl = '/{0}/widget'.format(controller); cfg.callback = 'GITWidget.jsonpCallback'; var query = jQuery.param(cfg); var url = '/{0}/widget'.format(controller); return { query: query, url: url }; }; // // Executes the widget // function executeWidget(url, query, id) { // // Create url to the jsonp function in the home controller on main script server // var url = "{0}/jsonp/".format(gitWidgetUrl); // // Create jsonp script tag // var script = document.createElement('script'); script.type = 'text/javascript'; script.src = '{0}?{1}'.format(url, query); script.id = "{0}-jsonp-script-tag".format(id); // // Get head tag from DOM // var head = (document.getElementsByTagName("head")[0] || document.documentElement); // // Insert script tag // head.appendChild(script); }; // // Parses a query string into an array. // function parseQuery(queryString) { var arr = new Array(); var keyValues = queryString.split(/&/); for (var i = 0; i < keyValues.length; i++) { var key = keyValues[i].split(/=/); arr[key[0]] = key[1]; } return arr; } // // Jsonp callback function. Inserts the [content] into the placeholder [id] // function jsonpCallback(response) { var query = parseQuery(response.query); var id = query['widgetId']; var content = response.content; if (response.error != undefined) { content = "Ett okänt fel har uppstått
Tillbaka