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 = 'http://gitwidgets.golf.se'; // 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
"; } // // Insert content and remove class indicating widget loading // jQuery('#' + id).html(content).removeClass('{0}-widget-loading'.format(gitWidgetPrefix)); // // Remove script tag // jQuery("#{0}-jsonp-script-tag".format(id)).remove(); }; // // // function loadWidget(widgetType, id, cfg, extend) { // // Make sure cfg is an object // cfg = cfg || {}; // // Get the widget with the current id (if exist) // var currentWidget = loadedWidgets[id]; // // If we have a widget, then it is an update to an existing widget. // if (currentWidget) { var previousCfg = jQuery.extend({}, currentWidget.history[0]); // // Always use guid from previous request if no guid submitted in current // if (!cfg.guid) { cfg.guid = previousCfg.guid; }; // // Should we completely extend the previous config to the submitted one? // if (extend) { cfg = jQuery.extend(previousCfg, cfg); }; // // Never user defer on existing widget // delete cfg.defer; // // Add configuration to history (adding to position 0) // currentWidget.history.splice(0, 0, cfg); }; // // If no widget then it is a new one. Create it and add it to "loadedWidgets" // if (!currentWidget) { currentWidget = {}; currentWidget.type = widgetType; currentWidget.history = new Array(); currentWidget.history.push(cfg); loadedWidgets[id] = currentWidget; }; cfg.widgetId = id; //cfg.callback = 'GITWidget.jsonpCallback'; var request = createRequestData(widgetType, cfg); if (!cfg.defer) { executeWidget(request.url, request.query, id); }; }; // // Internal function to add slope calculator widget // function addSlopeCalculator(id, cfg) { loadWidget('slopecalculator', id, cfg); }; // // Internal function to add slope calculator widget // function addMemberApplication(id, cfg) { loadWidget('memberapplication', id, cfg); }; // // Internal function to add golf news widget // function addGolfNews(id, cfg) { loadWidget('golfnews', id, cfg); }; // // Internal function to add golf Login widget // function addGolfLogin(id, cfg) { loadWidget('golflogin', id, cfg); }; // // Internal function to add golf Login widget // function addCompetitions(id, cfg) { loadWidget('competition', id, cfg); }; // // Internal function to add score card widget // function addScoreCard(id, cfg) { loadWidget('scorecard', id, cfg); }; // // Internal function to add score card widget // function addBookings(id, cfg) { loadWidget('bookings', id, cfg); }; // // Public functions // return { getBaseURL: function () { return gitWidgetUrl; }, // // Slope widget // addSlopeCalculator: function (cfg) { // // Generate widget id and add placeholder // var id = generateWidgetPlaceholder(); runWithVerifiedComponents([], function () { addSlopeCalculator(id, cfg); }); return id; }, addMemberApplication: function (cfg) { // // Generate widget id and add placeholder // var id = generateWidgetPlaceholder(); runWithVerifiedComponents(["jquery", "validate" //, "validateAdditional" ], function () { addMemberApplication(id, cfg); }); //runWithVerifiedComponents([], function () { //}); return id; }, // // Golf News widget // addGolfNews: function (cfg) { // // Generate widget id and add placeholder // var id = generateWidgetPlaceholder(); runWithVerifiedComponents([], function () { addGolfNews(id, cfg); }); return id; }, refreshWidget: function (id, cfg, extend) { var currentWidget = loadedWidgets[id]; if (currentWidget) { var type = currentWidget.type; loadWidget(type, id, cfg, extend); }; }, ValidateMemberForm: function() { return true; }, // // Min Golf Login widget // addGolfLogin: function (cfg) { // // Generate widget id and add placeholder // var id = generateWidgetPlaceholder(); runWithVerifiedComponents([], function () { addGolfLogin(id, cfg); }); return id; }, // // Tävlingswidget // addCompetitions: function (cfg) { // // Generate widget id and add placeholder // var id = generateWidgetPlaceholder(); //includeCss('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css'); includeCss('{0}/widget/ui/css/bootstrap.competition.css'.format(gitWidgetUrl)); runWithVerifiedComponents(["jqueryui", "competition"], function () { addCompetitions(id, cfg); }); return id; }, // // Tävlingswidget // addScoreCard: function (cfg) { // // Generate widget id and add placeholder // var id = generateWidgetPlaceholder(); runWithVerifiedComponents([], function () { addScoreCard(id, cfg); }); return id; }, // // Tävlingswidget // addBookings: function (cfg) { // // Generate widget id and add placeholder // var id = generateWidgetPlaceholder(); includeCss('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.css'); includeCss('{0}/widget/ui/css/bootstrap.custom.css'.format(gitWidgetUrl)); runWithVerifiedComponents(["jqueryui", "jqueryui.datepicker-sv"], function () { addBookings(id, cfg); }); return id; }, // // Allow access to internal version of jQuery // jQuery: function () { return jQuery.apply(this, arguments); }, back: function (id) { if (loadedWidgets[id]) { var type = loadedWidgets[id].type; var cfg = loadedWidgets[id].history.splice(0, 2)[1]; loadWidget(type, id, cfg); }; }, jsonpCallback: function (response) { jsonpCallback(response); } }; } ()); };