PageSourceSearch

https://www.bvfe.es/templates/rt_acacia/js/rokmediaqueries.js

js bvfe.es collected 2026-10-02 07:08:38 UTC 4,676 bytes, 157 lines download raw bytes

1/**
2* @version	$Id: rokmediaqueries.js 12813 2013-08-16 21:57:09Z arifin $
3* @author		RocketTheme http://www.rockettheme.com
4* @copyright Copyright (C) 2007 - 2014 RocketTheme, LLC
5* @license	http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
6*/
7
8((function(){
9///*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
10// matchMedia polyfill
11window.matchMedia = window.matchMedia || window.msMatchMedia || (function(doc, undefined){
12		var bool,
13			docElem = doc.documentElement,
14			refNode = docElem.firstElementChild || docElem.firstChild,
15			// fakeBody required for <FF4 when executed in <head>
16			fakeBody = doc.createElement('body'),
17			div = doc.createElement('div');
18
19		div.id = 'mq-test-1';
20		div.style.cssText = "position:absolute;top:-100em";
21		fakeBody.style.background = "none";
22		fakeBody.appendChild(div);
23
24		return function(q){
25			div.innerHTML = '&shy;<style media="'+q+'"> #mq-test-1 { width: 42px; }</style>';
26
27			docElem.insertBefore(fakeBody, refNode);
28			bool = div.offsetWidth == 42;
29			docElem.removeChild(fakeBody);
30
31			return {
32				matches: bool,
33				media: q,
34				addListener: function(fn){
35					if (!Browser.ie9 && !window.opera) return "";
36
37					if (window.retrieve('rokmediaqueries:listener:' + q.replace(/[a-z]|[(|)|:|\s|-]/gi, ''), false)) return;
38
39					window.store('rokmediaqueries:listener:' + q.replace(/[a-z]|[(|)|:|\s|-]/gi, ''), true);
40					window[window.addListener ? 'addListener' : 'attachEvent']('resize', function(){
41						var sizes = {}, length = 0, winSize, passed = false;
42						q.replace(/(\w+-?\w+)\s?:\s?(\d+){1,}/g, function(match, p1, p2, p3, offset, string){
43							sizes[p1] = p2;
44							length++;
45						});
46						if (!length) return;
47						else if (length == 1){
48							winSize = window.getSize();
49							passed = false;
50							Object.each(sizes, function(size, dimension){
51								if (dimension == 'min-width') passed += winSize.x >= size;
52								else if (dimension == 'max-width') passed += winSize.x <= size;
53								else if (dimension == 'width') passed += winSize.x == size;
54							});
55						} else if (length > 1) {
56							winSize = window.getSize();
57							passed = true;
58							Object.each(sizes, function(size, dimension){
59								if (dimension == 'min-width') passed *= winSize.x >= size;
60								else if (dimension == 'max-width') passed *= winSize.x <= size;
61								else if (dimension == 'width') passed *= winSize.x == size;
62							});
63						}
64
65						if (passed) return fn.call(fn, q);
66					});
67
68				}
69			};
70		};
71
72	})(document);
73
74})());
75
76((function(win, doc){
77
78	if (typeof RokMediaQueries != 'undefined') return;
79
80	var RokMediaQuery = new Class({
81		Implements: [Events, Options],
82		options: {
83			/*
84				onChange: function(query){},
85			*/
86			queries: [
87				'(min-width: 1200px)',
88				'(min-width: 960px) and (max-width: 1199px)',
89				'(min-width: 768px) and (max-width: 959px)',
90				'(min-width: 481px) and (max-width: 767px)',
91				'(max-width: 480px)'
92			]
93		},
94		initialize: function(options){
95			this.setOptions(options);
96			this.queries = this.options.queries;
97			this.queriesEvents = {};
98			this.timers = [];
99
100			for (var i = this.queries.length - 1; i >= 0; i--) {
101				var media = win.matchMedia(this.queries[i]);
102				media.addListener(this._fireEvent.bind(this, this.queries[i]));
103				this.queriesEvents[this.queries[i]] = [];
104			}
105		},
106
107		on: function(query, funct){
108			if (query == 'every'){
109				for (var i = this.queries.length - 1; i >= 0; i--) this._addOnMatch(this.queries[i], funct);
110			} else {
111				this._addOnMatch(query, funct);
112			}
113		},
114
115		add: function(query){
116			if (!this.queries.contains(query)){
117				var media;
118				this.queries.push(query);
119				media = win.matchMedia(query);
120				media.addListener(this._fireEvent.bind(this, query));
121			}
122
123			if (!this.queriesEvents[query]) this.queriesEvents[query] = [];
124		},
125
126		getQuery: function(){
127			var current = "";
128
129			for (var i = this.queries.length - 1; i >= 0; i--) {
130				if (win.matchMedia(this.queries[i]).matches){
131					current = this.queries[i];
132					break;
133				}
134			}
135
136			return current;
137		},
138
139		/* private methods */
140		_fireEvent: function(query){
141			if (!win.matchMedia(query).matches || !Object.getLength(this.queriesEvents) || !this.queriesEvents[query]) return;
142
143			for (var i = this.queriesEvents[query].length - 1; i >= 0; i--) {
144				//this.queriesEvents[query][i].delay(5, this, query);
145				this.queriesEvents[query][i](query);
146			}
147		},
148
149		_addOnMatch: function(query, funct){
150			this.add(query);
151			this.queriesEvents[query].push(funct);
152		}
153	});
154
155	win.RokMediaQueries = new RokMediaQuery();
156
157})(window, document));

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.