Browse Source

initial commit

master
Scott Barker 8 years ago
commit
fdee60868c
2 changed files with 136 additions and 0 deletions
  1. 19
    0
      LICENSE
  2. 117
    0
      jquery.loadScriptForBrowser.js

+ 19
- 0
LICENSE View File

@@ -0,0 +1,19 @@
Copyright (c) 2011 Scott D. Barker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

+ 117
- 0
jquery.loadScriptForBrowser.js View File

@@ -0,0 +1,117 @@
/*
jQuery loadScriptForBrowser Plugin
* Author/Copyright: Scott D. Barker
* Version: 1.0
* Date: 2011/11/01

Copyright (c) 2011 Scott D. Barker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

-----

Portions of this software based on jQuery Browser Plugin version 2.3:

http://jquery.thewikies.com/browser/

Used under the terms of the MIT license.
In turn, this software is also licensed under the MIT license.
*/

(function($){
var browserKeys = [ ];
$.browserTest = function (a, z) {
var u = 'unknown', x = 'X', m = function (r, h) {
for (var i = 0; i < h.length; i = i + 1) {
r = r.replace(h[i][0], h[i][1]);
}

return r;
}, c = function (i, a, b, c) {
var r = {
name: m((a.exec(i) || [u, u])[1], b)
};

r[r.name] = true;

r.version = (c.exec(i) || [x, x, x, x])[3];

if (r.name.match(/safari/) && r.version > 400) {
r.version = '2.0';
}

if (r.name === 'presto') {
r.version = ($.browser.version > 9.27) ? 'futhark' : 'linear_b';
}
r.versionNumber = parseFloat(r.version, 10) || 0;
r.versionX = (r.version !== x) ? (r.version + '').substr(0, 1) : x;
r.className = r.name + r.versionX;

return r;
};

a = (a.match(/Opera|Navigator|Minefield|KHTML|Chrome/) ? m(a, [
[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/, ''],
['Chrome Safari', 'Chrome'],
['KHTML', 'Konqueror'],
['Minefield', 'Firefox'],
['Navigator', 'Netscape']
]) : a).toLowerCase();

$.browser = $.extend((!z) ? $.browser : {}, c(a, /(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/, [], /(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));

$.layout = c(a, /(gecko|konqueror|msie|opera|webkit)/, [
['konqueror', 'khtml'],
['msie', 'trident'],
['opera', 'presto']
], /(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);

$.os = {
name: (/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase()) || [u])[0].replace('sunos', 'solaris')
};

browserKeys = [$.os.name, $.browser.name, $.browser.className, $.layout.name, $.layout.className];
};

$.browserTest(navigator.userAgent);

$.loadScriptForBrowser = function(scripts) {
for (var i = 0; i < browserKeys.length; i++) {
var key = browserKeys[i];
// console.log('loading scripts for ' + key);
if (scripts[key]) {
for (var j = 0; j < scripts[key].length; j++) {
var script = scripts[key][j];
if (typeof script === 'string') {
// console.log('... script "' + script + '"');
document.write('\x3Cscript type="text/javascript" src="' + script + '">\x3C/script>');
}
else if (typeof script === 'function') {
// console.log('... function "' + script + '"');
script();
}
else {
throw new Error("Unsupported script type. Expected either a string (path to a script file) or function (to execute)");
}
}
}
}
};
})(jQuery);

Loading…
Cancel
Save