/*! * Version.js v0.2.0 * * Test a different script version with the switch of a query string. * * https://github.com/jstayton/version.js * * Copyright 2013 by Justin Stayton * Licensed MIT */ (function (window, document) { 'use strict'; var version = {}; // CDN constants for use in place of full URLs. version.CDN = { cdnjs: '//cdnjs.cloudflare.com/ajax/libs/{{LIBRARY}}/{{VERSION}}/{{FILE}}.js', google: '//ajax.googleapis.com/ajax/libs/{{LIBRARY}}/{{VERSION}}/{{FILE}}.js', jsdelivr: '//cdn.jsdelivr.net/{{LIBRARY}}/{{VERSION}}/{{FILE}}.js' }; // Get the version from a query string param. 'null' if unspecified. version.queryVersion = function (param) { var regex = new RegExp('[&\\?]' + param + '=([^&]+)'), match = regex.exec(window.location.search); return match && match[1]; }; // Build a script URL from a CDN constant or custom URL. Pass in optional // replacements for {{LIBRARY}}, {{VERSION}}, and {{FILE}}. version.scriptUrl = function (url, replacements) { var scriptUrl = version.CDN[url] || url; if (!scriptUrl) { return null; } // Prepend the protocol if the URL starts with '//'. if (scriptUrl.substr(0, 2) === '//') { scriptUrl = (window.location.protocol === 'https:' ? 'https:' : 'http:') + scriptUrl; } if (replacements) { scriptUrl = scriptUrl.replace(/\{\{LIBRARY\}\}/, replacements.library); scriptUrl = scriptUrl.replace(/\{\{VERSION\}\}/, replacements.version); scriptUrl = scriptUrl.replace(/\{\{FILE\}\}/, replacements.file || replacements.library); } return scriptUrl; }; // Build a script tag as a string. 'null' if 'src' unspecified. version.scriptString = function (src) { return src && '