PageSourceSearch

https://rasptut.co.uk/rw_common/themes/kuler_react/jquery/browsereject.js

js rasptut.co.uk collected 2026-10-04 14:13:05 UTC 16,863 bytes, 526 lines download raw bytes

1/*
2 * jReject (jQuery Browser Rejection Plugin)
3 * Version 1.0.0
4 * URL: http://jreject.turnwheel.com/
5 * Description: jReject is a easy method of rejecting specific browsers on your site
6 * Author: Steven Bower (TurnWheel Designs) http://turnwheel.com/
7 * Copyright: Copyright (c) 2009-2011 Steven Bower under dual MIT/GPL license.
8 */
9
10(function($) {
11$.reject = function(opts) {
12	var opts = $.extend(true,{
13		reject : { // Rejection flags for specific browsers
14			all: false, // Covers Everything (Nothing blocked)
15			msie7: true, msie6: true // Covers MSIE 5-6 (Blocked by default)
16			/*
17			 * Possibilities are endless...
18			 *
19			 * // MSIE Flags (Global, 5-8)
20			 * msie, msie5, msie6, msie7, msie8,
21			 * // Firefox Flags (Global, 1-3)
22			 * firefox, firefox1, firefox2, firefox3,
23			 * // Konqueror Flags (Global, 1-3)
24			 * konqueror, konqueror1, konqueror2, konqueror3,
25			 * // Chrome Flags (Global, 1-4)
26			 * chrome, chrome1, chrome2, chrome3, chrome4,
27			 * // Safari Flags (Global, 1-4)
28			 * safari, safari2, safari3, safari4,
29			 * // Opera Flags (Global, 7-10)
30			 * opera, opera7, opera8, opera9, opera10,
31			 * // Rendering Engines (Gecko, Webkit, Trident, KHTML, Presto)
32			 * gecko, webkit, trident, khtml, presto,
33			 * // Operating Systems (Win, Mac, Linux, Solaris, iPhone)
34			 * win, mac, linux, solaris, iphone,
35			 * unknown // Unknown covers everything else
36			 */
37		},
38		display: [], // What browsers to display and their order (default set below)
39		browserInfo: { // Settings for which browsers to display
40			firefox: {
41				text: 'Firefox 8', // Text below the icon
42				url: 'http://www.mozilla.com/firefox/' // URL For icon/text link
43			},
44			safari: {
45				text: 'Safari 5',
46				url: 'http://www.apple.com/safari/download/'
47			},
48			opera: {
49				text: 'Opera 11',
50				url: 'http://www.opera.com/download/'
51			},
52			chrome: {
53				text: 'Chrome 15',
54				url: 'http://www.google.com/chrome/'
55			},
56			msie: {
57				text: 'Internet Explorer 9',
58				url: 'http://www.microsoft.com/windows/Internet-explorer/'
59			}
60		},
61
62		// Header of pop-up window
63		header: 'Did you know your version Internet Explorer has been updated?',
64		// Paragraph 1
65		paragraph1: 'Your browser is out of date, and may not be compatible with '+
66					'our website. A list of the most popular web browsers can be '+
67					'found below.',
68		// Paragraph 2
69		paragraph2: 'Just click on the icons to get to the download page',
70		close: true, // Allow closing of window
71		// Message displayed below closing link
72		closeMessage: 'NOTE: This website is not optimized for Internet Explorer 6',
73		closeLink: 'Close This Window', // Text for closing link
74		closeURL: '#', // Close URL
75		closeESC: true, // Allow closing of window with esc key
76
77		// If cookies should be used to remmember if the window was closed
78		// See cookieSettings for more options
79		closeCookie: false,
80		// Cookie settings are only used if closeCookie is true
81		cookieSettings: {
82			// Path for the cookie to be saved on
83			// Should be root domain in most cases
84			path: '/',
85			// Expiration Date (in seconds)
86			// 0 (default) means it ends with the current session
87			expires: 0
88		},
89
90		imagePath: './images/', // Path where images are located
91		overlayBgColor: '#000', // Background color for overlay
92		overlayOpacity: 0.8, // Background transparency (0-1)
93
94		// Fade in time on open ('slow','medium','fast' or integer in ms)
95		fadeInTime: 'fast',
96		// Fade out time on close ('slow','medium','fast' or integer in ms)
97		fadeOutTime: 'fast',
98
99		// Google Analytics Link Tracking (Optional)
100		// Set to true to enable
101		// Note: Analytics tracking code must be added separately
102		analytics: false
103	},opts);
104
105	// Set default browsers to display if not already defined
106	if (opts.display.length < 1)
107		opts.display = ['safari', 'chrome', 'firefox','msie','opera'];
108
109	// beforeRject: Customized Function
110	if ($.isFunction(opts.beforeReject)) opts.beforeReject(opts);
111
112	// Disable 'closeESC' if closing is disabled (mutually exclusive)
113	if (!opts.close) opts.closeESC = false;
114
115	// This function parses the advanced browser options
116	var browserCheck = function(settings) {
117		// Check 1: Look for 'all' forced setting
118		// Check 2: Operating System (eg. 'win','mac','linux','solaris','iphone')
119		// Check 3: Rendering engine (eg. 'webkit', 'gecko', 'trident')
120		// Check 4: Browser name (eg. 'firefox','msie','chrome')
121		// Check 5: Browser+major version (eg. 'firefox3','msie7','chrome4')
122		return (settings['all'] ? true : false) ||
123			(settings[$.os.name] ? true : false) ||
124			(settings[$.layout.name] ? true : false) ||
125			(settings[$.browser.name] ? true : false) ||
126			(settings[$.browser.className] ? true : false);
127	};
128
129	// Determine if we need to display rejection for this browser, or exit
130	if (!browserCheck(opts.reject)) {
131		// onFail: Customized Function
132		if ($.isFunction(opts.onFail)) opts.onFail(opts);
133		return false;
134	}
135
136	// If user can close and set to remmember close, initiate cookie functions
137	if (opts.close && opts.closeCookie) {
138		// Local global setting for the name of the cookie used
139		var COOKIE_NAME = 'jreject-close';
140
141		// Cookies Function: Handles creating/retrieving/deleting cookies
142		// Cookies are only used for opts.closeCookie parameter functionality
143		var _cookie = function(name, value) {
144			if (typeof value != 'undefined') {
145				var expires = '';
146
147				// Check if we need to set an expiration date
148				if (opts.cookieSettings.expires != 0) {
149					var date = new Date();
150					date.setTime(date.getTime()+(opts.cookieSettings.expires));
151					var expires = "; expires="+date.toGMTString();
152				}
153
154				// Get path from settings
155				var path = opts.cookieSettings.path || '/';
156
157				// Set Cookie with parameters
158				document.cookie = name+'='+
159					encodeURIComponent(value == null ? '' : value)+expires+
160					'; path='+path;
161			}
162			else { // Get cookie value
163				var cookie,val = null;
164
165				if (document.cookie && document.cookie != '') {
166					var cookies = document.cookie.split(';');
167
168					// Loop through all cookie values
169					var clen = cookies.length;
170					for (var i = 0; i < clen; ++i) {
171						cookie = $.trim(cookies[i]);
172
173						// Does this cookie string begin with the name we want?
174						if (cookie.substring(0,name.length+1) == (name+'=')) {
175							var len = name.length;
176							val = decodeURIComponent(cookie.substring(len+1));
177							break;
178						}
179					}
180				}
181
182				return val; // Return cookie value
183			}
184		};
185
186		// If cookie is set, return false and don't display rejection
187		if (_cookie(COOKIE_NAME) != null) return false;
188	}
189
190	// Load background overlay (jr_overlay) + Main wrapper (jr_wrap) +
191	// Inner Wrapper (jr_inner) w/ opts.header (jr_header) +
192	// opts.paragraph1/opts.paragraph2 if set
193	var html = '<div id="jr_overlay"></div><div id="jr_wrap"><div id="jr_inner">'+
194		'<h1 id="jr_header">'+opts.header+'</h1>'+
195		(opts.paragraph1 === '' ? '' : '<p>'+opts.paragraph1+'</p>')+
196		(opts.paragraph2 === '' ? '' : '<p>'+opts.paragraph2+'</p>')+'<ul>';
197
198	var displayNum = 0; // Tracks number of browsers being displayed
199	// Generate the browsers to display
200	for (var x in opts.display) {
201		var browser = opts.display[x]; // Current Browser
202		var info = opts.browserInfo[browser] || false; // Browser Information
203
204		// If no info exists for this browser
205		// or if this browser is not suppose to display to this user
206		if (!info || (info['allow'] != undefined && !browserCheck(info['allow']))) {
207			continue;
208		}
209
210		var url = info.url || '#'; // URL to link text/icon to
211		// Generate HTML for this browser option
212		html += '<li id="jr_'+browser+'"><div class="jr_icon"></div>'+
213				'<div><a href="'+url+'">'+(info.text || 'Unknown')+'</a>'+
214				'</div></li>';
215		++displayNum; // Increment number of browser being displayed
216	}
217
218	// Close list and #jr_list
219	html += '</ul><div id="jr_close">'+
220	// Display close links/message if set
221	(opts.close ? '<a href="'+opts.closeURL+'">'+opts.closeLink+'</a>'+
222		'<p>'+opts.closeMessage+'</p>' : '')+'</div>'+
223	// Close #jr_inner and #jr_wrap
224	'</div></div>';
225
226	var element = $('<div>'+html+'</div>'); // Create element
227	var size = _pageSize(); // Get page size
228	var scroll = _scrollSize(); // Get page scroll
229
230	// This function handles closing this reject window
231	// When clicked, fadeOut and remove all elements
232	element.bind('closejr', function() {
233		// Make sure the permission to close is granted
234		if (!opts.close) return false;
235
236		// Customized Function
237		if ($.isFunction(opts.beforeClose)) opts.beforeClose(opts);
238
239		// Remove binding function so it
240		// doesn't get called more than once
241		$(this).unbind('closejr');
242
243		// Fade out background and modal wrapper
244		$('#jr_overlay,#jr_wrap').fadeOut(opts.fadeOutTime,function() {
245			$(this).remove(); // Remove element from DOM
246
247			// afterClose: Customized Function
248			if ($.isFunction(opts.afterClose)) opts.afterClose(opts);
249		});
250
251		// Show elements that were hidden for layering issues
252		$('embed, object, select, applet').show();
253
254		// Set close cookie for next run
255		if (opts.closeCookie) _cookie(COOKIE_NAME,'true');
256		return true;
257	});
258
259	// Tracks clicks in Google Analytics (category 'External Links')
260	// only if opts.analytics is enabled
261	var analytics = function (url) {
262		if (!opts.analytics) return false;
263
264		// Get just the hostname
265		var host = url.split(/\/+/g)[1];
266
267		// Send external link event to Google Analaytics
268		// Attempts both versions of analytics code. (Newest first)
269		try {
270			// Newest analytics code
271			_gaq.push(['_trackEvent','External Links',  host, url]);
272		} catch (e) {
273			try {
274				// Older analytics code
275				pageTracker._trackEvent('External Links', host, url);
276			} catch (e) { };
277		}
278	};
279
280	// Called onClick for browser links (and icons)
281	// Opens link in new window
282	var openBrowserLinks = function(url) {
283		// Send link to analytics if enabled
284		analytics(url);
285
286		// Open window, generate random id value
287		window.open(url, 'jr_'+ Math.round(Math.random()*11));
288
289		return false;
290	};
291
292	/*
293	 * Trverse through element DOM and apply JS variables
294	 * All CSS elements that do not require JS will be in
295	 * css/jquery.jreject.css
296	 */
297
298	// Creates 'background' (div)
299	element.find('#jr_overlay').css({
300		width: size[0],
301		height: size[1],
302		background: opts.overlayBgColor,
303		opacity: opts.overlayOpacity
304	});
305
306	// Wrapper for our pop-up (div)
307	element.find('#jr_wrap').css({
308		top: scroll[1]+(size[3]/4),
309		left: scroll[0]
310	});
311
312	// Wrapper for inner centered content (div)
313	element.find('#jr_inner').css({
314		minWidth: displayNum*100,
315		maxWidth: displayNum*140,
316		// min/maxWidth not supported by IE
317		width: $.layout.name == 'trident' ? displayNum*155 : 'auto'
318	});
319
320	element.find('#jr_inner li').css({ // Browser list items (li)
321		background: 'transparent url("'+opts.imagePath+'background_browser.gif")'+
322					'no-repeat scroll left top'
323	});
324
325	element.find('#jr_inner li .jr_icon').each(function() {
326		// Dynamically sets the icon background image
327		var self = $(this);
328		self.css('background','transparent url('+opts.imagePath+'browser_'+
329				(self.parent('li').attr('id').replace(/jr_/,''))+'.gif)'+
330					' no-repeat scroll left top');
331
332		// Send link clicks to openBrowserLinks
333		self.click(function () {
334			var url = $(this).next('div').children('a').attr('href');
335			openBrowserLinks(url);
336		});
337	});
338
339	element.find('#jr_inner li a').click(function() {
340		openBrowserLinks($(this).attr('href'));
341		return false;
342	});
343
344	// Bind closing event to trigger closejr
345	// to be consistant with ESC key close function
346	element.find('#jr_close a').click(function() {
347		$(this).trigger('closejr');
348
349		// If plain anchor is set, return false so there is no page jump
350		if (opts.closeURL === '#') return false;
351	});
352
353	// Set focus (fixes ESC key issues with forms and other focus bugs)
354	$('#jr_overlay').focus();
355
356	// Hide elements that won't display properly
357	$('embed, object, select, applet').hide();
358
359	// Append element to body of document to display
360	$('body').append(element.hide().fadeIn(opts.fadeInTime));
361
362	// Handle window resize/scroll events and update overlay dimensions
363	$(window).bind('resize scroll',function() {
364		var size = _pageSize(); // Get size
365
366		// Update overlay dimensions based on page size
367		$('#jr_overlay').css({
368			width: size[0],
369			height: size[1]
370		});
371
372		var scroll = _scrollSize(); // Get page scroll
373
374		// Update modal position based on scroll
375		$('#jr_wrap').css({
376			top: scroll[1] + (size[3]/4),
377			left: scroll[0]
378		});
379	});
380
381	// Add optional ESC Key functionality
382	if (opts.closeESC) {
383		$(document).bind('keydown',function(event) {
384			// ESC = Keycode 27
385			if (event.keyCode == 27) element.trigger('closejr');
386		});
387	}
388
389	// afterReject: Customized Function
390	if ($.isFunction(opts.afterReject)) opts.afterReject(opts);
391
392	return true;
393};
394
395// Based on compatibility data from quirksmode.com
396var _pageSize = function() {
397	var xScroll = window.innerWidth && window.scrollMaxX ?
398				window.innerWidth + window.scrollMaxX :
399				(document.body.scrollWidth > document.body.offsetWidth ?
400				document.body.scrollWidth : document.body.offsetWidth);
401
402	var yScroll = window.innerHeight && window.scrollMaxY ?
403				window.innerHeight + window.scrollMaxY :
404				(document.body.scrollHeight > document.body.offsetHeight ?
405				document.body.scrollHeight : document.body.offsetHeight);
406
407	var windowWidth = window.innerWidth ? window.innerWidth :
408				(document.documentElement && document.documentElement.clientWidth ?
409				document.documentElement.clientWidth : document.body.clientWidth);
410
411	var windowHeight = window.innerHeight ? window.innerHeight :
412				(document.documentElement && document.documentElement.clientHeight ?
413				document.documentElement.clientHeight : document.body.clientHeight);
414
415	return [
416		xScroll < windowWidth ? xScroll : windowWidth, // Page Width
417		yScroll < windowHeight ? windowHeight : yScroll, // Page Height
418		windowWidth,windowHeight
419	];
420};
421
422
423// Based on compatibility data from quirksmode.com
424var _scrollSize = function() {
425	return [
426		// scrollSize X
427		window.pageXOffset ? window.pageXOffset : (document.documentElement &&
428				document.documentElement.scrollTop ?
429				document.documentElement.scrollLeft : document.body.scrollLeft),
430
431		// scrollSize Y
432		window.pageYOffset ? window.pageYOffset : (document.documentElement &&
433				document.documentElement.scrollTop ?
434				document.documentElement.scrollTop : document.body.scrollTop)
435	];
436};
437})(jQuery);
438
439/*
440 * jQuery Browser Plugin
441 * Version 2.4 / jReject 1.0.0
442 * URL: http://jquery.thewikies.com/browser
443 * Description: jQuery Browser Plugin extends browser detection capabilities and
444 * can assign browser selectors to CSS classes.
445 * Author: Nate Cavanaugh, Minhchau Dang, Jonathan Neal, & Gregory Waxman
446 * Updated By: Steven Bower for use with jReject plugin
447 * Copyright: Copyright (c) 2008 Jonathan Neal under dual MIT/GPL license.
448 */
449
450(function ($) {
451	$.browserTest = function (a, z) {
452		var u = 'unknown',
453			x = 'X',
454			m = function (r, h) {
455				for (var i = 0; i < h.length; i = i + 1) {
456					r = r.replace(h[i][0], h[i][1]);
457				}
458
459				return r;
460			}, c = function (i, a, b, c) {
461				var r = {
462					name: m((a.exec(i) || [u, u])[1], b)
463				};
464
465				r[r.name] = true;
466
467				if (!r.opera) {
468					r.version = (c.exec(i) || [x, x, x, x])[3];
469				}
470				else {
471					r.version = window.opera.version();
472				}
473
474				if (/safari/.test(r.name) && r.version > 400) {
475					r.version = '2.0';
476				}
477				else if (r.name === 'presto') {
478					r.version = ($.browser.version > 9.27) ? 'futhark' : 'linear_b';
479				}
480
481				r.versionNumber = parseFloat(r.version, 10) || 0;
482				var minorStart = 1;
483				if (r.versionNumber < 100 && r.versionNumber > 9) {
484					minorStart = 2;
485				}
486				r.versionX = (r.version !== x) ? r.version.substr(0, minorStart) : x;
487				r.className = r.name + r.versionX;
488
489				return r;
490			};
491
492		a = (/Opera|Navigator|Minefield|KHTML|Chrome/.test(a) ? m(a, [
493			[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/, ''],
494			['Chrome Safari', 'Chrome'],
495			['KHTML', 'Konqueror'],
496			['Minefield', 'Firefox'],
497			['Navigator', 'Netscape']
498		]) : a).toLowerCase();
499
500		$.browser = $.extend((!z) ? $.browser : {}, c(a,
501			/(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/, [],
502			/(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/
503			)
504		);
505
506		$.layout = c(a, /(gecko|konqueror|msie|opera|webkit)/, [
507			['konqueror', 'khtml'],
508			['msie', 'trident'],
509			['opera', 'presto']
510		], /(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);
511
512		$.os = {
513			name: (/(win|mac|linux|sunos|solaris|iphone)/.
514					exec(navigator.platform.toLowerCase()) || [u])[0]
515						.replace('sunos', 'solaris')
516		};
517
518		if (!z) {
519			$('html').addClass([$.os.name, $.browser.name, $.browser.className,
520				$.layout.name, $.layout.className].join(' '));
521		}
522	};
523
524	$.browserTest(navigator.userAgent);
525}(jQuery));
526

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.