marley 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2117 +0,0 @@
1
- /* Prevel Library v1.0.0
2
- * http://github.com/chernikovalexey/Prevel
3
- *
4
- * Copyright 2011-2012, Alexey Chernikov
5
- * Dual licensed under the:
6
- * - GNU LGPL (http://opensource.org/licenses/lgpl-license.php)
7
- * - MIT License (http://opensource.org/licenses/mit-license.php)
8
- *
9
- * =====
10
- *
11
- * Contains YASS v0.3.9
12
- * http://yass.webo.in
13
- *
14
- * Copyright 2008-2009, Nikolay Matsievsky (sunnybear)
15
- * Dual licensed under the:
16
- * - MIT License (http://opensource.org/licenses/mit-license.php)
17
- * - GNU GPL (http://opensource.org/licenses/gpl-license.php)
18
- **/
19
-
20
- (function(win, doc, proto, ael, ge, cn, nn, u, newRegExp, n, ef, uf) {
21
-
22
- /* Module: Core.js
23
- * Requirements: -
24
- **/
25
-
26
- (function() {
27
-
28
- // Short names for almost all types
29
- var types = {
30
- 'function': 'fn',
31
- object: 'obj',
32
- number: 'int',
33
- string: 'str',
34
- 'boolean': 'bool',
35
- regexp: 'regexp',
36
- date: 'date',
37
- undefined: u,
38
- array: 'arr'
39
- };
40
-
41
- var op = Object[proto];
42
-
43
- // Cached checks
44
- var accessors =
45
- !!op.__lookupGetter__ &&
46
- !!op.__lookupSetter__ &&
47
- !!op.__defineGetter__;
48
-
49
- var trim = !!''.trim,
50
- indexOf = !![].indexOf,
51
- toString = op.toString,
52
- json = win.JSON && win.JSON.parse;
53
-
54
- // Local copy of `pl`
55
- var pl = (function() {
56
- return function(o, context, index) {
57
- return pl.fn ? new pl.fn.init(o, context, index) : uf;
58
- };
59
- })();
60
-
61
- pl.extend = function(Child, Parent, flag) {
62
- if(!Parent) {
63
- Parent = Child;
64
- Child = pl;
65
- }
66
-
67
- var init = Child;
68
-
69
- // If accessors are supported, they will be considered in extending
70
- if(accessors) {
71
- var getter, setter;
72
- for(var key in Parent) {
73
- getter = Parent.__lookupGetter__(key);
74
- setter = Parent.__lookupSetter__(key);
75
-
76
- if(getter || setter) {
77
- if(getter) Child.__defineGetter__(key, getter);
78
- if(setter) Child.__defineSetter__(key, setter);
79
- } else if((!Child[key]) || (Child[key] && flag)) {
80
- Child[key] = Parent[key];
81
- }
82
- }
83
- } else {
84
- for(var key in Parent) {
85
- // It can reassign the parameter if flag equals true
86
- if((!Child[key]) || (Child[key] && flag)) {
87
- Child[key] = Parent[key];
88
- }
89
- }
90
- }
91
-
92
- if(init === pl.fn) {
93
- pl.implement(pl.fn.init, pl.fn);
94
- }
95
-
96
- init = u;
97
- return Child;
98
- };
99
-
100
- // User agent
101
- var ua = win.navigator.userAgent.toLowerCase();
102
-
103
- var opera = /opera/i.test(ua),
104
- chrome = /chrome/i.test(ua);
105
- var browsers = {
106
- opera: opera,
107
- ie: !opera && /msie/i.test(ua),
108
- ie6: !opera && /msie 6/i.test(ua),
109
- ie7: !opera && /msie 7/i.test(ua),
110
- ie8: !opera && /msie 8/i.test(ua),
111
- firefox: /firefox/i.test(ua),
112
- chrome: chrome,
113
- safari_khtml: !chrome && /khtml/i.test(ua),
114
- safari: !chrome && /webkit|safari/i.test(ua)
115
- };
116
-
117
- pl.extend({navigator: []});
118
- for(var key in browsers) {
119
- if(browsers[key]) {
120
- pl.navigator.push(key);
121
- }
122
- }
123
-
124
- // Public
125
- pl.extend({
126
- // Extend the Object.prototype
127
- implement: function(Child, Parent, flag) {
128
- return pl.extend(Child[proto], Parent, flag);
129
- },
130
-
131
- // Uses native method, if it's available
132
- isArray: Array.isArray || function(o) {
133
- return pl.type(o, 'arr');
134
- },
135
-
136
- type: function(o, is) {
137
- var t = o === n ?
138
- nn :
139
- o === uf ? u : (class2type[toString.call(o)] || 'obj');
140
- return is ? is === t : t;
141
- },
142
-
143
- empty: function(o) {
144
- // Separate check for an object
145
- if(pl.type(o, 'obj')) {
146
- for(var key in o) return false;
147
- return true;
148
- }
149
- return (pl.type(o, nn) || pl.type(o, u)) || !o.length;
150
- },
151
-
152
- trim: function(text) {
153
- // Uses native method, if it's availiable
154
- text = text || '';
155
- return trim ? text.trim() : text.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
156
- },
157
-
158
- each: function(arr, func) {
159
- var key = -1;
160
- var len = arr.length;
161
- while(++key < len) {
162
- func.call(arr[key], key, arr[key]);
163
- }
164
- },
165
-
166
- // Moved from Core Extension
167
- filter: function(array, reservation) {
168
- var output = [];
169
- pl.each(array, function(k, val) {
170
- if(reservation(val)) {
171
- output.push(val);
172
- }
173
- });
174
- return output;
175
- },
176
-
177
- inArray: function(a, c, b, r) {
178
- if(indexOf) return c.indexOf(a, b);
179
- for(b = b > 0 || -1, r = -1; ++b < c.length && !~r; r = c[b] === a ? b : r);
180
- return r;
181
- },
182
-
183
- error: function(msg) {
184
- throw new Error(msg);
185
- return false;
186
- },
187
-
188
- JSON: function(data) {
189
- // Use native function if possible
190
- return json ?
191
- win.JSON.parse(data) :
192
- (!(/[^,:{}[]0-9.-+Eaeflnr-u nrt]/.test(
193
- data.replace(/"(.|[^"])*"/g, ''))) && eval('(' + data + ')')
194
- );
195
- },
196
-
197
- browser: function(name) {
198
- return name ? !!~pl.inArray(name, pl.navigator) : pl.navigator[0];
199
- }
200
- });
201
-
202
- var class2type = {};
203
- pl.each('Array Boolean Number String Function Date RegExp Object'.split(' '), function(key, val) {
204
- class2type['[object ' + val + ']'] = types[val.toLowerCase()];
205
- });
206
-
207
- // Add `pl` to the global scope
208
- win.pl = pl;
209
-
210
- })();
211
-
212
- /* Module: Manipulate.js
213
- * Requirements: Core.js
214
- **/
215
-
216
- (function() {
217
-
218
- pl.extend({
219
- create: function(o, params) {
220
- var ns = doc.createElement(o);
221
-
222
- // To avoid using pl().attr() which is a module
223
- for(var key in params) {
224
- ns[pl.fixAttr ? pl.fixAttr[key] || key : key] = params[key];
225
- }
226
- return ns;
227
- },
228
-
229
- parent: function(elem, step) {
230
- return step > 0 ? pl.parent(elem.parentNode, --step) : elem;
231
- },
232
-
233
- __self__: uf
234
- });
235
-
236
- // ======
237
- // Public
238
-
239
- // Add `fn` to `pl`, at first (to reduce nested level)
240
- pl.extend({
241
- fn: {},
242
- find: function(selector, root) { // If there is no Prevel Find
243
- return doc.querySelectorAll(root ? root + ' ' + selector : selector);
244
- }
245
- });
246
-
247
- pl.extend(pl.fn, {
248
- init: (function() {
249
- return function(o, params, index) {
250
- var _int;
251
- switch(pl.type(o)) {
252
- case 'str':
253
- var ne = o.match(newRegExp);
254
- if(ne) {
255
- _int = [pl.create(ne[1], params)];
256
- } else {
257
- switch(pl.type(params)) {
258
- case 'str': // Get `o` from the context
259
- switch(pl.type(index)) {
260
- case 'int':
261
- _int = [pl.find(o, params)[index]];
262
- break;
263
- default:
264
- case u:
265
- _int = pl.find(o);
266
- break;
267
- }
268
- break;
269
- case 'int': // Work only with the element №{params}
270
- _int = [pl.find(o)[params]];
271
- break;
272
- default:
273
- case u: // Just find all the `o`
274
- _int = pl.find(o);
275
- break;
276
- }
277
- }
278
- break;
279
- case 'fn':
280
- pl.events.ready(o);
281
- break;
282
- case 'obj':
283
- _int = o[0] ? o : [o];
284
- break;
285
- }
286
-
287
- this.elements = _int;
288
- this.selector = arguments;
289
- pl.__self__ = this;
290
- return this;
291
- };
292
- })(),
293
-
294
- len: function() {
295
- return this.elements.length;
296
- },
297
-
298
- last: function() {
299
- var l = this.elements.length;
300
- this.elements = [
301
- l && !pl.type(this.elements[l - 1], u) ? this.elements[l - 1] : n
302
- ];
303
- return this;
304
- },
305
-
306
- get: function(index) {
307
- var e = this.elements;
308
- return e.length === 1 ? e[0] : (!pl.type(index, u) ? e[index] : e);
309
- },
310
-
311
- // Recursion's faster than loop here
312
- parent: function(step) {
313
- this.elements = [pl.parent(this.elements[0], step || 1)];
314
- return this;
315
- },
316
-
317
- remove: function() {
318
- pl.each(this.elements, function() {
319
- this.parentNode.removeChild(this);
320
- });
321
- return this;
322
- },
323
-
324
- each: function(fn) {
325
- pl.each(pl.__self__.elements, function() {
326
- fn.call(this);
327
- });
328
- return this;
329
- }
330
- });
331
-
332
- })();
333
-
334
- /* Module: Css.js
335
- * Requirements: Core.js, Manipulate.js
336
- **/
337
-
338
- (function() {
339
-
340
- pl.extend({
341
- camelCase: function(str) {
342
- if(!str.match('-')) return str;
343
- var parts = str.split('-');
344
- return parts[0] + parts[1].charAt(0).toUpperCase() + parts[1].substr(1);
345
- },
346
-
347
- curCSS: {
348
- rmvPostFix: {
349
- zIndex: true,
350
- fontWeight: true,
351
- opacity: true,
352
- zoom: true,
353
- lineHeight: true
354
- },
355
-
356
- // Get computed style
357
- get: function(o, style) {
358
- return o.currentStyle ? o.currentStyle[style] :
359
- win.getComputedStyle(o, n).getPropertyValue(style);
360
- }
361
- }
362
- });
363
-
364
- pl.extend(pl.fn, {
365
- css: function(style, set) {
366
- if(set) {
367
- style = pl.camelCase(style);
368
-
369
- if(pl.type(set, 'int') && !pl.curCSS.rmvPostFix[style]) {
370
- set += 'px';
371
- }
372
-
373
- pl.each(this.elements, function() {
374
- this.style[style] = set;
375
- });
376
- } else {
377
- if(pl.type(style, 'str')) {
378
- return pl.curCSS.get(this.elements[0], style);
379
- } else {
380
- for(var key in style) {
381
- pl.fn.css.call(this, key, style[key]);
382
- }
383
- }
384
- }
385
- return this;
386
- }
387
- });
388
-
389
- })();
390
-
391
- /* Module: Attr.js
392
- * Requirements: Core.js, Manipulate.js
393
- **/
394
-
395
- (function() {
396
-
397
- pl.extend({
398
- fixAttr: {
399
- 'class': 'className',
400
- 'float': 'cssFloat',
401
- 'for': 'htmlFor'
402
- }
403
- });
404
-
405
- pl.extend(pl.fn, {
406
- addClass: function(c) {
407
- pl.each(this.elements, function() {
408
- // If this class already exists
409
- if(~pl.inArray(c, this[cn].split(' '))) return;
410
- this[cn] += (this[cn] ? ' ' : '') + c;
411
- });
412
- return this;
413
- },
414
-
415
- hasClass: function(c) {
416
- return this.elements[0] && this.elements[0][cn] ?
417
- !!~pl.inArray(c, this.elements[0][cn].split(' ')) :
418
- false;
419
- },
420
-
421
- removeClass: function(c) {
422
- pl.each(this.elements, function() {
423
- if(!this[cn]) return;
424
- var cl = this[cn].split(' '),
425
- from = pl.inArray(c, cl);
426
-
427
- // If this class does not exist
428
- if(!~from) return;
429
-
430
- cl.splice(from, 1);
431
-
432
- this[cn] = (pl.empty(cl) ? cl.slice(from, 1) : cl).join(' ');
433
- });
434
- return this;
435
- },
436
-
437
- attr: function(attr, set) {
438
- attr = pl.fixAttr[attr] || attr;
439
-
440
- if(!pl.type(set, 'undef')) {
441
- pl.each(this.elements, function() {
442
- this[attr] = set;
443
- });
444
- } else {
445
- if(pl.type(attr, 'str')) {
446
- return this.elements[0][attr];
447
- } else {
448
- for(var key in attr) {
449
- pl.fn.attr.call(this, key, attr[key]);
450
- }
451
- }
452
- }
453
- return this;
454
- },
455
-
456
- removeAttr: function(attr) {
457
- attr = pl.fixAttr[attr] || attr;
458
-
459
- pl.each(this.elements, function() {
460
- this[attr] = n;
461
- });
462
- return this;
463
- }
464
- });
465
-
466
- })();
467
-
468
- /* Module: Ajax.js
469
- * Requirements: Core.js
470
- **/
471
-
472
- (function() {
473
-
474
- pl.extend({
475
- // Convert object to a 'param-string'
476
- toParams: function(o) {
477
- var pieces = [];
478
- for(var key in o) {
479
- pieces.push(
480
- encodeURIComponent(key) + '=' + encodeURIComponent(o[key])
481
- );
482
- }
483
- return pieces.join('&');
484
- },
485
-
486
- ajax: function(params) {
487
- var Request;
488
- var requestPrepare = function() {
489
- if(win.XMLHttpRequest) { // Modern browsers
490
- Request = new XMLHttpRequest();
491
-
492
- if(Request.overrideMimeType) {
493
- Request.overrideMimeType('text/html');
494
- }
495
- } else if(win.ActiveXObject) { // Obsolete IE
496
- try {
497
- Request = new ActiveXObject('Msxml2.XMLHTTP');
498
- } catch(e) {
499
- try {
500
- Request = new ActiveXObject('Microsoft.XMLHTTP');
501
- } catch(er) {}
502
- }
503
- }
504
-
505
- if(!Request) {
506
- pl.error('Could not create a XMLHttpRequest instance.');
507
- }
508
-
509
- // Fix related with `attachEvent`
510
- Request.onreadystatechange = function(e) {
511
- if(Request.readyState === 1) {
512
- (params.load || ef)();
513
- } else if(Request.readyState === 4) {
514
- if(Request.status > 199 && Request.status < 300) {
515
- (params.success || ef)(
516
- params.dataType === 'json' ? // Parse JSON if necessary
517
- pl.JSON(Request.responseText) :
518
- Request.responseText,
519
- Request.status
520
- );
521
- } else {
522
- (params.error || ef)(Request.status, Request.responseText);
523
- }
524
- }
525
-
526
- params.always = params.always || ef;
527
-
528
- try {
529
- params.always(Request.readyState, Request.status, Request.responseText);
530
- } catch(e) {
531
- params.always(Request.readyState);
532
- }
533
- };
534
- };
535
-
536
- // Common headers
537
- var headers = function(type) {
538
- // To identify that it's XHR
539
- Request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
540
-
541
- if(type) {
542
- Request.setRequestHeader(
543
- 'Content-type',
544
- 'application/x-www-form-urlencoded; charset=' +
545
- (params.charset || 'utf-8')
546
- );
547
- }
548
- };
549
-
550
- params.data = pl.toParams(params.data || {});
551
- params.async = params.async || true;
552
- requestPrepare();
553
-
554
- if(params.type === 'POST') {
555
- Request.open('POST', params.url, params.async);
556
- headers(1);
557
- Request.send(params.data);
558
- } else {
559
- Request.open('GET', params.url + '&' + params.data, params.async);
560
- headers();
561
- Request.send(n);
562
- }
563
- }
564
- });
565
-
566
- })();
567
-
568
-
569
- /* Module: Events.js
570
- * Requirements: Core.js, Manipulate.js
571
- **/
572
-
573
- (function() {
574
-
575
- pl.extend({
576
- events: {
577
- // DOMContentLoaded
578
- ready: (function() {
579
- this.readyList = []; // Functions to be called
580
- this.bindReady = function(handler) {
581
- var called = false;
582
-
583
- function ready() {
584
- if(called) return;
585
- called = true;
586
- handler();
587
- }
588
-
589
- if(doc[ael]) {
590
- pl.events.attaches.bind(doc, 'DOMContentLoaded', ready);
591
- } else if(doc.attachEvent) {
592
- if(doc.documentElement.doScroll && win === win.top) {
593
- function tryScroll() {
594
- if(called) return;
595
- if(!doc.body) return;
596
- try {
597
- doc.documentElement.doScroll('left');
598
- ready();
599
- } catch(e) {
600
- setTimeout(tryScroll, 0);
601
- }
602
- }
603
- tryScroll();
604
- }
605
-
606
- pl.events.attaches.bind(doc, 'readystatechange', function() {
607
- if(doc.readyState === 'complete') {
608
- ready();
609
- }
610
- });
611
- }
612
-
613
- pl.events.attaches.bind(win, 'load', ready);
614
- };
615
-
616
- var that = this;
617
-
618
- return function(handler) {
619
- if(!that.readyList.length) {
620
- that.bindReady(function() {
621
- pl.each(that.readyList, function(k) {
622
- this();
623
- });
624
- });
625
- }
626
-
627
- that.readyList.push(handler);
628
- };
629
- })(),
630
-
631
- mend: function(event) {
632
- event = event || win.event;
633
-
634
- if(event.fixed) {
635
- return event;
636
- }
637
- event.fixed = true;
638
-
639
- event.preventDefault = event.preventDefault || function() {
640
- this.returnValue = false;
641
- };
642
- event.stopPropagation = event.stopPropagation || function() {
643
- this.cancelBubble = true;
644
- };
645
-
646
- if(!event.target) {
647
- event.target = event.srcElement;
648
- }
649
-
650
- if(event.pageX == n && event.clientX != n) {
651
- var html = doc.documentElement,
652
- body = doc.body;
653
- event.pageX =
654
- event.clientX +
655
- (html && html.scrollLeft || body && body.scrollLeft || 0) -
656
- (html.clientLeft || 0);
657
- event.pageY =
658
- event.clientY +
659
- (html && html.scrollTop || body && body.scrollTop || 0) -
660
- (html.clientTop || 0);
661
- }
662
-
663
- if(pl.type(event.which, u)) {
664
- event.which = (event.button & 1 ?
665
- 1 :
666
- (event.button & 2 ?
667
- 3 :
668
- (event.button & 4 ? 2 : 0)
669
- )
670
- );
671
- }
672
-
673
- return event;
674
- },
675
-
676
- // Cross-browser event adding and removing
677
- // http://javascript.ru/tutorial/events/crossbrowser
678
- attaches: (function() {
679
- var turns = 0;
680
-
681
- function handleCommon(e) {
682
- e = pl.events.mend(e);
683
-
684
- var handlerList = this.evt[e.type];
685
-
686
- for(var key in handlerList) {
687
- var updated = handlerList[key].call(this, e);
688
-
689
- if(updated === false) {
690
- e.preventDefault();
691
- e.stopPropagation();
692
- }
693
- }
694
- }
695
-
696
- return {
697
- bind: function(el, evt, fn) {
698
- if(el.setInterval && !el.frameElement) {
699
- if(el !== win) el = win;
700
-
701
- if(~pl.inArray(evt, pl.__fwe__)) {
702
- return (window.onload = function() {
703
- pl(doc.body).bind(evt, fn);
704
- });
705
- }
706
- }
707
-
708
- if(!fn.turnID) {
709
- fn.turnID = ++turns;
710
- }
711
-
712
- if(!el.evt) {
713
- el.evt = {};
714
-
715
- el.handleEvt = function(e) {
716
- if(!pl.type(pl.events.attaches, u)) {
717
- return handleCommon.call(el, e);
718
- }
719
- };
720
- }
721
-
722
- if(!el.evt[evt]) {
723
- el.evt[evt] = {};
724
-
725
- if(el[ael]) {
726
- el[ael](evt, el.handleEvt, false);
727
- } else {
728
- el.attachEvent('on' + evt, el.handleEvt);
729
- }
730
- }
731
-
732
- el.evt[evt][fn.turnID] = fn;
733
- },
734
-
735
- unbind: function(el, evt, fn) {
736
- var handlerList = el.evt;
737
-
738
- if(pl.type(fn, u)) {
739
- if(!handlerList) return;
740
- for(var handle in handlerList) {
741
- if(pl.type(evt, u) || evt === handle) {
742
- for(var key in handlerList[handle]) {
743
- pl.events.attaches.unbind(el, handle, handlerList[handle][key]);
744
- }
745
- }
746
- }
747
- return;
748
- }
749
-
750
- handlerList = handlerList && handlerList[evt];
751
- if(!handlerList) return;
752
-
753
- delete handlerList[fn.turnID];
754
-
755
- for(var key in handlerList) return;
756
-
757
- if(el.removeEventListener) {
758
- el.removeEventListener(evt, el.handleEvt, false);
759
- } else {
760
- el.detachEvent('on' + evt, el.handleEvt);
761
- }
762
-
763
- delete el.evt[evt];
764
-
765
- for(var key in el.evt) return;
766
-
767
- try {
768
- delete el.handleEvt;
769
- delete el.evt;
770
- } catch(e) {
771
- el.removeAttribute('handleEvt');
772
- el.removeAttribute('evt');
773
- }
774
- }
775
- };
776
- })(),
777
-
778
- routeEvent: function(evt, fn, flag) {
779
- if(pl.type(evt, 'obj')) {
780
- for(var key in evt) {
781
- pl.events.routeEvent(key, evt[key], flag);
782
- }
783
- } else if((fn && evt) || (!fn && evt) || (!fn && !evt)) {
784
- if(flag) {
785
- pl.each(pl.__self__.elements, function() {
786
- pl.events.attaches.bind(this, evt, fn);
787
- });
788
- } else {
789
- pl.each(pl.__self__.elements, function() {
790
- pl.events.attaches.unbind(this, evt, fn);
791
- });
792
- }
793
- }
794
- return pl.__self__;
795
- }
796
- },
797
-
798
- __fwe__: [
799
- 'click', 'mouseover', 'mouseout',
800
- 'keyup', 'keydown', 'dblclick',
801
- 'mousedown', 'mouseup', 'keypress'
802
- ]
803
- });
804
-
805
- pl.extend(pl.fn, {
806
- bind: function(evt, fn) {
807
- // Delegate to the common method
808
- return pl.events.routeEvent(evt, fn, 1);
809
- },
810
-
811
- unbind: function(evt, fn) {
812
- // The same as in pl().bind()
813
- return pl.events.routeEvent(evt, fn, 0);
814
- }
815
- });
816
-
817
- })();
818
-
819
- /* Module: Find.js
820
- * Requirements: Core.js
821
- * Copyright 2008-2009, Nikolay Matsievsky (sunnybear) - http://yass.webo.in
822
- **/
823
-
824
- (function() {
825
-
826
- var classSupport = !!doc[ge + 'sByClassName'],
827
- qsSupport = !!doc.querySelectorAll;
828
-
829
- pl.find = (function(_) {
830
- pl.extend(_, {
831
- attr: {
832
- '': function(child, attr) {
833
- return !!child.getAttribute(attr);
834
- },
835
- '=': function(child, attr, value) {
836
- return (attr = child.getAttribute(attr)) && attr === value;
837
- },
838
- '&=': function(child, attr, value) {
839
- return
840
- (attr = child.getAttribute(attr)) &&
841
- (new RegExp('(^| +)' + value + '($| +)').test(attr));
842
- },
843
- '^=': function(child, attr, value) {
844
- return
845
- (attr = child.getAttribute(attr) + '') && !attr.indexOf(value);
846
- },
847
- '$=': function(child, attr, value) {
848
- return
849
- (attr = child.getAttribute(attr) + '') &&
850
- attr.indexOf(value) === attr.length - value.length;
851
- },
852
- '*=': function(child, attr, value) {
853
- return
854
- (attr = child.getAttribute(attr) + '') &&
855
- attr.indexOf(value) != -1;
856
- },
857
- '|=': function(child, attr, value) {
858
- return
859
- (attr = child.getAttribute(attr) + '') &&
860
- (attr === value || !!attr.indexOf(value + '-'));
861
- },
862
- '!=': function(child, attr, value) {
863
- return
864
- !(attr = child.getAttribute(attr)) ||
865
- !(new RegExp('(^| +)' + value + '($| +)').test(attr)) ||
866
- true;
867
- }
868
- },
869
-
870
- mods: {
871
- 'first-child': function(child) {
872
- return child.parentNode.getElementsByTagName('*')[0] !== child;
873
- },
874
- 'last-child': function(child) {
875
- var brother = child;
876
- while((brother = brother.nextSibling) && brother.nodeType != 1) {}
877
- return !!brother;
878
- },
879
- root: function(child) {
880
- return child.nodeName.toLowerCase() !== 'html';
881
- },
882
- 'nth-child': function(child, ind) {
883
- var i = child.nodeIndex || 0,
884
- a = ind[3] = ind[3] ? (ind[2] === '%' ? -1 : 1) * ind[3] : 0,
885
- b = ind[1];
886
-
887
- if(i) {
888
- return !( (i + a) % b);
889
- } else {
890
- var brother = child.parentNode.firstChild;
891
- i++;
892
-
893
- do {
894
- if(
895
- brother.nodeType == 1 &&
896
- (brother.nodeIndex = ++i) &&
897
- child === brother &&
898
- ((i + a) % b)
899
- ) {
900
- return 0;
901
- }
902
- } while(brother = brother.nextSibling);
903
- return 1;
904
- }
905
- },
906
- 'nth-last-child': function(child, ind) {
907
- var i = child.nodeIndexLast || 0,
908
- a = ind[3] ? (ind[2] === '%' ? -1 : 1) * ind[3] : 0,
909
- b = ind[1];
910
- if(i) {
911
- return !( (i + a) % b);
912
- } else {
913
- var brother = child.parentNode.lastChild;
914
- i++;
915
- do {
916
- if(
917
- brother.nodeType == 1 &&
918
- (brother.nodeLastIndex = i++) &&
919
- child === brother &&
920
- ((i + a) % b)
921
- ) {
922
- return 0;
923
- }
924
- } while(brother = brother.previousSibling);
925
- return 1;
926
- }
927
- },
928
- empty: function(child) {
929
- return !!child.firstChild;
930
- },
931
- parent: function(child) {
932
- return !child.firstChild;
933
- },
934
- 'only-child': function(child) {
935
- return child.parentNode[ge + 'sByTagName']('*').length != 1;
936
- },
937
- checked: function(child) {
938
- return !child.checked;
939
- },
940
- lang: function(child, ind) {
941
- return child.lang !== ind && doc.documentElement.lang !== ind;
942
- },
943
- enabled: function(child) {
944
- return child.disabled || child.type === 'hidden';
945
- },
946
- disabled: function(child) {
947
- return !child.disabled;
948
- },
949
- selected: function(elem){
950
- child.parentNode.selectedIndex;
951
- return !child.selected;
952
- }
953
- }
954
- });
955
-
956
- return function(selector, root) {
957
- if(root) {
958
- selector = root + ' ' + selector;
959
- }
960
-
961
- root = doc;
962
- var sets = [];
963
-
964
- if(selector === 'body *') {
965
- return doc.body[ge + 'sByTagName']('*');
966
- } else if(/^[\w[:#.][\w\]*^|=!]*$/.test(selector)) {
967
- var idx = 0;
968
-
969
- switch(selector.charAt(0)) {
970
- case '#':
971
- idx = selector.slice(1);
972
- sets = doc[ge + 'ById'](idx);
973
-
974
- if(pl.browser('ie') && sets.id !== idx) {
975
- sets = doc.all[idx];
976
- }
977
-
978
- sets = sets ? [sets] : [];
979
- break;
980
- case '.':
981
- var klass = selector.slice(1);
982
-
983
- if(classSupport) {
984
- sets = (
985
- idx = (sets = root[ge + 'sByClassName'](klass)).length
986
- ) ? sets : [];
987
- } else {
988
- klass = ' ' + klass + ' ';
989
- var nodes = root[ge + 'sByTagName']('*'),
990
- i = 0,
991
- node;
992
-
993
- while(node = nodes[i++]) {
994
- if((' ' + node[cn] + ' ').indexOf(klass) != -1) {
995
- sets[idx++] = node;
996
- }
997
- }
998
- sets = idx ? sets : [];
999
- }
1000
- break;
1001
- case ':':
1002
- var node,
1003
- nodes = root[ge + 'sByTagName']('*'),
1004
- i = 0,
1005
- ind = selector.replace(/[^(]*\(([^)]*)\)/, "$1"),
1006
- mod = selector.replace(/\(.*/,'');
1007
-
1008
- while(node = nodes[i++]) {
1009
- if(_.mods[mod] && !_.mods[mod](node, ind)) {
1010
- sets[idx++] = node;
1011
- }
1012
- }
1013
- sets = idx ? sets : [];
1014
- break;
1015
- case '[':
1016
- var nodes = root[ge + 'sByTagName']('*'),
1017
- node,
1018
- i = 0,
1019
- attrs = /\[([^!~^*|$ [:=]+)([$^*|]?=)?([^ :\]]+)?\]/.exec(
1020
- selector
1021
- ),
1022
- attr = attrs[1],
1023
- eql = attrs[2] || '',
1024
- value = attrs[3];
1025
-
1026
- while(node = nodes[i++]) {
1027
- console.log('216:', eql);
1028
-
1029
- if(
1030
- _.attr[eql] &&
1031
- (
1032
- _.attr[eql](node, attr, value) ||
1033
- (
1034
- attr === 'class' &&
1035
- _.attr[eql](node, cn, value)
1036
- )
1037
- )
1038
- ) {
1039
- sets[idx++] = node;
1040
- }
1041
- }
1042
- sets = idx ? sets : [];
1043
- break;
1044
- default:
1045
- sets = (
1046
- idx = (sets = root[ge + 'sByTagName'](selector)).length
1047
- ) ? sets : [];
1048
- break;
1049
- }
1050
- } else {
1051
- if(qsSupport && !~selector.indexOf('!=')) {
1052
- sets = root.querySelectorAll(
1053
- selector.replace(/=([^\]]+)/, '="$1"')
1054
- );
1055
- } else {
1056
- var groups = selector.split(/ *, */),
1057
- gl = groups.length - 1,
1058
- concat = !!gl,
1059
- group, singles, singles_length, single, i, ancestor,
1060
- nodes, tag, id, klass, attr, eql, mod, ind, newNodes,
1061
- idx, J, child, last, childs, item, h;
1062
-
1063
- while(group = groups[gl--]) {
1064
- singles_length = (
1065
- singles = group
1066
- .replace(/(\([^)]*)\+/,"$1%")
1067
- .replace(/(\[[^\]]+)~/,"$1&")
1068
- .replace(/(~|>|\+)/," $1 ")
1069
- .split(/ +/)
1070
- ).length;
1071
- i = 0;
1072
- ancestor = ' ';
1073
- nodes = [root];
1074
-
1075
- while(single = singles[i++]) {
1076
- if(
1077
- single !== ' ' &&
1078
- single !== '>' &&
1079
- single !== '~' &&
1080
- single !== '+' &&
1081
- nodes
1082
- ) {
1083
- single = single.match(/([^[:.#]+)?(?:#([^[:.#]+))?(?:\.([^[:.]+))?(?:\[([^!&^*|$[:=]+)([!$^*|&]?=)?([^:\]]+)?\])?(?:\:([^(]+)(?:\(([^)]+)\))?)?/);
1084
- tag = single[1] || '*';
1085
- id = single[2];
1086
- klass = single[3] ? ' ' + single[3] + ' ' : '';
1087
- attr = single[4];
1088
- eql = single[5] || '';
1089
- mod = single[7];
1090
- ind =
1091
- mod === 'nth-child' ||
1092
- mod === 'nth-last-child' ?
1093
- /(?:(-?\d*)n)?(?:(%|-)(\d*))?/.exec(
1094
- single[8] === 'even' &&
1095
- '2n' ||
1096
- single[8] === 'odd' &&
1097
- '2n%1' ||
1098
- !/\D/.test(single[8]) &&
1099
- '0n%' + single[8] ||
1100
- single[8]
1101
- ) :
1102
- single[8];
1103
-
1104
- newNodes = [];
1105
- idx = J = 0;
1106
- last = i == singles_length;
1107
-
1108
- while(child = nodes[J++]) {
1109
- switch(ancestor) {
1110
- case ' ':
1111
- childs = child[ge + 'sByTagName'](tag);
1112
- h = 0;
1113
-
1114
- console.log('304: ...');
1115
-
1116
- while(item = childs[h++]) {
1117
- if(
1118
- (!id || item.id === id) &&
1119
- (
1120
- !klass ||
1121
- (' ' + item[cn] + ' ')
1122
- .indexOf(klass) != -1
1123
- ) && (
1124
- !attr ||
1125
- (
1126
- _.attr[eql] &&
1127
- (
1128
- _.attr[eql](item, attr, single[6]) ||
1129
- (
1130
- attr === 'class' &&
1131
- _.attr[eql](
1132
- item, cn, single[6]
1133
- )
1134
- )
1135
- )
1136
- )
1137
- ) &&
1138
- !item.yeasss &&
1139
- !(
1140
- _.mods[mod] ?
1141
- _.mods[mod](item, ind) :
1142
- mod
1143
- )
1144
- ) {
1145
- console.log('Passed.');
1146
-
1147
- if(last) {
1148
- item.yeasss = 1;
1149
- }
1150
- newNodes[idx++] = item;
1151
- }
1152
- }
1153
- break;
1154
- case '~':
1155
- tag = tag.toLowerCase();
1156
-
1157
- while(
1158
- (child = child.nextSibling) &&
1159
- !child.yeasss
1160
- ) {
1161
- if(
1162
- child.nodeType == 1 &&
1163
- (
1164
- tag === '*' ||
1165
- child.nodeName.toLowerCase() === tag
1166
- ) &&
1167
- (!id || child.id === id) &&
1168
- (
1169
- !klass ||
1170
- (' ' + child[cn] + ' ')
1171
- .indexOf(klass) != -1
1172
- ) && (
1173
- !attr ||
1174
- (
1175
- _.attr[eql] &&
1176
- (
1177
- _.attr[eql](item, attr, single[6]) ||
1178
- (
1179
- attr === 'class' &&
1180
- _.attr[eql](
1181
- item, cn, single[6]
1182
- )
1183
- )
1184
- )
1185
- )
1186
- ) &&
1187
- !child.yeasss &&
1188
- !(
1189
- _.mods[mod] ?
1190
- _.mods[mod](child, ind) :
1191
- mod
1192
- )
1193
- ) {
1194
- if(last) {
1195
- child.yeasss = 1;
1196
- }
1197
- newNodes[idx++] = child;
1198
- }
1199
- }
1200
- break;
1201
- case '+':
1202
- while(
1203
- (child = child.nextSibling) &&
1204
- child.nodeType != 1
1205
- ) {}
1206
- if(
1207
- child &&
1208
- (
1209
- child.nodeName.toLowerCase() ===
1210
- tag.toLowerCase() ||
1211
- tag === '*'
1212
- ) && (
1213
- !id ||
1214
- child.id === id
1215
- ) && (
1216
- !klass ||
1217
- (' ' + item[cn] + ' ')
1218
- .indexOf(klass) != -1
1219
- ) && (
1220
- !attr ||
1221
- (
1222
- _.attr[eql] &&
1223
- (
1224
- _.attr[eql](item, attr, single[6]) ||
1225
- (
1226
- attr === 'class' &&
1227
- _.attr[eql](
1228
- item, cn, single[6]
1229
- )
1230
- )
1231
- )
1232
- )
1233
- ) &&
1234
- !child.yeasss &&
1235
- !(
1236
- _.mods[mod] ?
1237
- _.mods[mod](child, ind) :
1238
- mod
1239
- )
1240
- ) {
1241
- if(last) {
1242
- child.yeasss = 1;
1243
- }
1244
- newNodes[idx++] = child;
1245
- }
1246
- break;
1247
- case '>':
1248
- childs = child[ge + 'sByTagName'](tag);
1249
- i = 0;
1250
- while(item = childs[i++]) {
1251
- if(
1252
- item.parentNode === child &&
1253
- (!id || item.id === id) &&
1254
- (
1255
- !klass ||
1256
- (' ' + item[cn] + ' ')
1257
- .indexOf(klass) != -1
1258
- ) && (
1259
- !attr ||
1260
- (
1261
- _.attr[eql] &&
1262
- (
1263
- _.attr[eql](item, attr, single[6]) ||
1264
- (
1265
- attr === 'class' &&
1266
- _.attr[eql](
1267
- item, cn, single[6]
1268
- )
1269
- )
1270
- )
1271
- )
1272
- ) &&
1273
- !item.yeasss &&
1274
- !(
1275
- _.mods[mod] ?
1276
- _.mods[mod](item, ind) :
1277
- mod
1278
- )
1279
- ) {
1280
- if(last) {
1281
- item.yeasss = 1;
1282
- }
1283
- newNodes[idx++] = item;
1284
- }
1285
- }
1286
- break;
1287
- }
1288
- }
1289
- nodes = newNodes;
1290
- } else {
1291
- ancestor = single;
1292
- }
1293
- }
1294
-
1295
- if(concat) {
1296
- if(!nodes.concat) {
1297
- newNodes = [];
1298
- h = 0;
1299
-
1300
- while(item = nodes[h]) {
1301
- newNodes[h++] = item;
1302
- }
1303
- nodes = newNodes;
1304
- }
1305
- sets = nodes.concat(sets.length == 1 ? sets[0] : sets);
1306
- } else {
1307
- sets = nodes;
1308
- }
1309
- }
1310
- idx = sets.length;
1311
-
1312
- while(idx--) {
1313
- sets[idx].yeasss = sets[idx].nodeIndex =
1314
- sets[idx].nodeIndexLast = n;
1315
- }
1316
- }
1317
- }
1318
-
1319
- return sets;
1320
- };
1321
- })({});
1322
-
1323
- })();
1324
-
1325
- /* Module: Visibility.js
1326
- * Requirements: Core.js, Manipulate.js, Css.js
1327
- **/
1328
-
1329
- (function() {
1330
-
1331
- pl.extend(pl.fn, {
1332
- show: function() {
1333
- pl.each(this.elements, function() {
1334
- this.style.display = this.plrd ? this.plrd : '';
1335
- if(pl.curCSS.get(this, 'display') === 'none') {
1336
- this.style.display = 'block';
1337
- }
1338
- });
1339
- return this;
1340
- },
1341
-
1342
- hide: function() {
1343
- pl.each(this.elements, function() {
1344
- this.plrd = this.plrd || pl.curCSS.get(this, 'display');
1345
- if(this.plrd === 'none') {
1346
- this.plrd = 'block';
1347
- }
1348
- this.style.display = 'none';
1349
- });
1350
- return this;
1351
- }
1352
- });
1353
-
1354
- })();
1355
-
1356
- /* Module: Insert.js
1357
- * Requirements: Core.js, Manipulate.js
1358
- **/
1359
-
1360
- (function() {
1361
-
1362
- pl.extend({
1363
- innerText: pl.browser('ie') ? 'innerText' : 'textContent',
1364
-
1365
- innerContent: {
1366
- midst: function(e, method, ins, to) {
1367
- var init = e;
1368
- var e = init.elements[0];
1369
-
1370
- if(pl.type(ins, u)) {
1371
- return e[method];
1372
- } else {
1373
- if(pl.type(ins, 'obj')) {
1374
- var temp = doc.createElement('div');
1375
- temp.appendChild(ins);
1376
- ins = temp.innerHTML;
1377
- }
1378
-
1379
- pl.each(init.elements, function() {
1380
- if(!to) {
1381
- this[method] = ins;
1382
- } else if(~to) {
1383
- this[method] += ins;
1384
- } else {
1385
- this[method] = ins + this[method];
1386
- }
1387
- });
1388
- return init;
1389
- }
1390
- },
1391
-
1392
- edge: function(_this, args, table, dir, fn) {
1393
- var a = pl.clean(args);
1394
- for(var i = (dir < 0 ? a.length - 1 : 0); i != (dir < 0 ? dir : a.length); i += dir) {
1395
- fn(_this, a[i]);
1396
- }
1397
- }
1398
- },
1399
-
1400
- clean: function(a) {
1401
- var r = [];
1402
- var len = a.length;
1403
-
1404
- for(var i = 0; i < len; ++i) {
1405
- if(pl.type(a[i], 'str')) {
1406
- var table = '';
1407
-
1408
- if(!a[i].indexOf('<thead') || !a[i].indexOf('<tbody')) {
1409
- table = 'thead';
1410
- a[i] = '<table>' + a[i] + '</table>';
1411
- } else if(!a[i].indexOf('<tr')) {
1412
- table = 'tr';
1413
- a[i] = '<table>' + a[i] + '</table>';
1414
- } else if(!a[i].indexOf('<td') || !a[i].indexOf('<th')) {
1415
- table = 'td';
1416
- a[i] = '<table><tbody><tr>' + a[i] + '</tr></tbody></table>';
1417
- }
1418
-
1419
- var div = doc.createElement('div');
1420
- div.innerHTML = a[i];
1421
-
1422
- if(table) {
1423
- div = div.firstChild;
1424
- if(table !== 'thead') div = div.firstChild;
1425
- if(table === 'td') div = div.firstChild;
1426
- }
1427
-
1428
- var cn_len = div.childNodes.length;
1429
- for(var j = 0; j < cn_len; ++j) {
1430
- r.push(div.childNodes[j]);
1431
- }
1432
- } else if(a[i] !== n) {
1433
- r.push(a[i].nodeType ? a[i] : doc.createTextNode(a[i].toString()));
1434
- }
1435
- }
1436
-
1437
- return r;
1438
- }
1439
- });
1440
-
1441
- pl.extend(pl.fn, {
1442
- html: function(ins, to) {
1443
- // Delegate to the common method
1444
- return pl.innerContent.midst(this, 'innerHTML', ins, to);
1445
- },
1446
-
1447
- text: function(ins, to) {
1448
- // The same as in pl().html()
1449
- return pl.innerContent.midst(this, pl.innerText, ins, to);
1450
- },
1451
-
1452
- after: function() {
1453
- var args = arguments;
1454
- pl.each(this.elements, function() {
1455
- pl.innerContent.edge(this, args, false, -1, function(o, a) {
1456
- o.parentNode.insertBefore(a, o.nextSibling);
1457
- });
1458
- });
1459
- return this;
1460
- },
1461
-
1462
- before: function() {
1463
- var args = arguments;
1464
- pl.each(this.elements, function() {
1465
- pl.innerContent.edge(this, args, false, 1, function(o, a) {
1466
- o.parentNode.insertBefore(a, o);
1467
- });
1468
- });
1469
- return this;
1470
- },
1471
-
1472
- append: function() {
1473
- var args = arguments;
1474
- pl.each(this.elements, function() {
1475
- pl.innerContent.edge(this, args, true, 1, function(o, a) {
1476
- o.appendChild(a);
1477
- });
1478
- });
1479
- return this;
1480
- },
1481
-
1482
- prepend: function() {
1483
- var args = arguments;
1484
- pl.each(this.elements, function() {
1485
- pl.innerContent.edge(this, args, true, -1, function(o, a){
1486
- o.insertBefore(a, o.firstChild);
1487
- });
1488
- });
1489
- return this;
1490
- },
1491
-
1492
- appendTo: function(selector, context, index) {
1493
- pl.each(this.elements, function() {
1494
- pl(selector, context, index).append(this);
1495
- });
1496
- return this;
1497
- },
1498
-
1499
- prependTo: function(selector, context, index) {
1500
- pl.each(this.elements, function() {
1501
- pl(selector, context, index).prepend(this);
1502
- });
1503
- return this;
1504
- }
1505
- });
1506
-
1507
- })();
1508
-
1509
- /* Prevel Ajax Extension
1510
- * Requirements: Core.js, Ajax.js
1511
- **/
1512
-
1513
- (function(win, doc, undefined) {
1514
-
1515
- pl.extend({
1516
- get: function(params, callback, type) {
1517
- pl.ajax(pl.type(params, 'obj') ? params : {
1518
- url: params,
1519
- success: callback,
1520
- dataType: type
1521
- });
1522
- },
1523
-
1524
- post: function(params, data, callback, type) {
1525
- pl.ajax(pl.type(params, 'obj') ? pl.extend(params, {type: 'POST'}) : {
1526
- url: params,
1527
- type: 'POST',
1528
- data: data,
1529
- success: callback,
1530
- dataType: type
1531
- });
1532
- },
1533
-
1534
- put: function(params) {
1535
- params.data = params.data || {};
1536
- params.data.action = 'put';
1537
- pl.post(params);
1538
- },
1539
-
1540
- del: function(params) {
1541
- params.data = params.data || {};
1542
- params.data.action = 'delete';
1543
- pl.post(params);
1544
- },
1545
-
1546
- // Adding and removing
1547
- ajaxDefaults: function(params) {
1548
- pl.each(['ajax', 'get', 'post', 'put', 'del'], function(k, val) {
1549
- if(params === 'remove') {
1550
- pl[val] = pl['_' + val];
1551
- pl['_' + val] = undefined;
1552
- } else {
1553
- pl['_' + val] = pl[val];
1554
- pl[val] = function(p) {
1555
- pl['_' + val](pl.extend(p, params));
1556
- };
1557
- }
1558
- });
1559
- },
1560
-
1561
- serialize: function(form) {
1562
- var o = {};
1563
- pl('form#' + form + ' input, form#' + form + ' textarea').each(function() {
1564
- if(this.type !== 'submit') {
1565
- o[this.name] = this.value;
1566
- }
1567
- });
1568
- return o;
1569
- }
1570
- });
1571
-
1572
- })(window, document);
1573
-
1574
- /* Prevel Core Extension
1575
- * Requirements: Core.js
1576
- **/
1577
-
1578
- (function(win, doc, undefined) {
1579
-
1580
- var proto = 'prototype',
1581
- slice = Array[proto].slice,
1582
- stringify = win.JSON && win.JSON.stringify;
1583
-
1584
- pl.extend({
1585
- map: function(array, fn) {
1586
- var output = [];
1587
- pl.each(array, function() {
1588
- output.push(fn(this));
1589
- });
1590
- return output;
1591
- },
1592
-
1593
- every: function(array, reservation) {
1594
- var flag = true;
1595
- pl.each(array, function(k, val) {
1596
- if(!reservation(val)) {
1597
- flag = false;
1598
- }
1599
- });
1600
- return flag;
1601
- },
1602
-
1603
- some: function(array, reservation) {
1604
- var flag = false;
1605
- pl.each(array, function(k, val) {
1606
- if(reservation(val)) {
1607
- flag = true;
1608
- }
1609
- });
1610
- return flag;
1611
- },
1612
-
1613
- unique: function(array) {
1614
- var a = [];
1615
- var l = array.length;
1616
- for(var i = 0; i < l; ++i) {
1617
- for(var j = i + 1; j < l; ++j) {
1618
- if(array[i] === array[j]) {
1619
- j = ++i;
1620
- }
1621
- }
1622
- a.push(array[i]);
1623
- }
1624
- return a;
1625
- },
1626
-
1627
- // Is window
1628
- isWin: function(Obj) {
1629
- return pl.type(Obj, 'obj') && 'setInterval' in Obj;
1630
- },
1631
-
1632
- // Attach script or css
1633
- attach: function(params) {
1634
- var add;
1635
- params.load = params.load || function() {};
1636
-
1637
- if(params.url.substr(-3) === '.js') {
1638
- add = pl('<script>', pl.extend({
1639
- src: params.url,
1640
- type: params.type || 'text/javascript'
1641
- }, params.charset ? {charset: params.charset} : {})).get();
1642
-
1643
- var _load = params.load;
1644
- params.load = function() {
1645
- _load(params.url, +new Date());
1646
- };
1647
-
1648
- // attachEvent doesn't support adding events to objects, so
1649
- // it's not possible to use `pl.events.attaches.bind`
1650
- add.onreadystatechange = function(e) {
1651
- if(e.readyState === 'complete') {
1652
- params.load();
1653
- }
1654
- };
1655
- add.onload = params.load;
1656
- } else {
1657
- add = pl('<link>', {
1658
- href: params.url,
1659
- rel: 'stylesheet',
1660
- type: 'text/css'
1661
- }).get();
1662
-
1663
- var sheet, cssRules;
1664
- if('sheet' in add) {
1665
- sheet = 'sheet';
1666
- cssRules = 'cssRules';
1667
- } else {
1668
- sheet = 'styleSheet';
1669
- cssRules = 'rules';
1670
- }
1671
-
1672
- var timeout = setInterval(function() {
1673
- try {
1674
- if(add[sheet] && add[sheet][cssRules].length) {
1675
- clearInterval(timeout);
1676
- params.load.call(params.url, +new Date());
1677
- }
1678
- } catch(e) {}
1679
- }, 10);
1680
- }
1681
-
1682
- pl('head').append(add);
1683
- return this;
1684
- },
1685
-
1686
- proxy: function(context, source) {
1687
- if(!pl.type(context, 'fn')) {
1688
- return undefined;
1689
- }
1690
-
1691
- return function() {
1692
- return context.apply(
1693
- source,
1694
- slice.call(arguments, 2).concat(slice.call(arguments))
1695
- );
1696
- };
1697
- },
1698
-
1699
- stringify: stringify ? win.JSON.stringify : function(obj) {
1700
- var t = pl.type(obj);
1701
- if(t === 'null') {
1702
- return String(obj);
1703
- } else {
1704
- var n, v, json = [], arr = pl.type(obj, 'arr');
1705
-
1706
- for(n in obj) {
1707
- v = obj[n];
1708
- t = pl.type(v);
1709
-
1710
- if(t === 'str') {
1711
- v = '"' + v + '"';
1712
- } else if(t === 'obj') {
1713
- v = pl.stringify(v);
1714
- }
1715
-
1716
- json.push((arr ? '' : '"' + n + '":') + String(v));
1717
- }
1718
- return (arr ? '[' : '{') + String(json) + (arr ? ']' : '}');
1719
- }
1720
- }
1721
- });
1722
-
1723
- })(window, document);
1724
-
1725
- /* Prevel Observer Extension
1726
- * (provides basic implementation of "observer" pattern)
1727
- *
1728
- * Requirements: Core.js
1729
- **/
1730
-
1731
- (function() {
1732
-
1733
- pl.extend({
1734
- Observer: function(fns) {
1735
- this.fns = fns ? (pl.type(fns, 'fn') ? [fns] : fns) : [];
1736
-
1737
- this.subscribe = function(fn) {
1738
- this.fns.push(fn);
1739
- };
1740
-
1741
- this.unsubscribe = function(fn) {
1742
- var pos = pl.inArray(fn, this.fns);
1743
-
1744
- if(~pos) {
1745
- this.fns.splice(pos, 1);
1746
- }
1747
- };
1748
-
1749
- this.clean = function() {
1750
- this.fns = [];
1751
- };
1752
-
1753
- this.has = function(fn) {
1754
- return !!~pl.inArray(fn, this.fns);
1755
- };
1756
-
1757
- this.publish = function(that, args) {
1758
- if(!pl.type(args, 'arr')) {
1759
- args = [args];
1760
- }
1761
-
1762
- pl.each(this.fns, function() {
1763
- this.apply(that, args);
1764
- });
1765
- };
1766
- }
1767
- });
1768
-
1769
- })();
1770
-
1771
- /* Prevel Dom Extension
1772
- * Requirements: Core.js, Manipulate.js, Attr.js, Insert.js
1773
- **/
1774
-
1775
- (function(win, doc, undefined) {
1776
-
1777
- /* NOTE:
1778
- * this.elements (in pl() instance) always exists, so checking if this.elements equals true
1779
- * is senseless, it will be always true. Much better will be checking if it's empty or
1780
- * trying to compare the first element with false values (false, null, undefined).
1781
- *
1782
- * Examples:
1783
- * this.elements[0] || ...
1784
- * pl.empty(this.elements)
1785
- * this.elements[0] !== undefined
1786
- **/
1787
-
1788
- pl.extend({
1789
- selectedBy: function(elem, selector) {
1790
- var elems = pl(selector).get();
1791
- return elems === elem || pl.filter(elems, function(el) {
1792
- return el === elem;
1793
- }).length > 0;
1794
- },
1795
-
1796
- related: function(elem, fn, mod) {
1797
- if(pl.type(mod, 'undef')) {
1798
- mod = 1;
1799
- }
1800
-
1801
- var get;
1802
- var ret = pl();
1803
- ret.selector = [elem.id, fn, mod];
1804
-
1805
- if(pl.type(mod, 'int')) {
1806
- get = function(e, step) {
1807
- return step > 0 ? get(e[fn], --step) : e;
1808
- };
1809
- } else {
1810
- get = function(e, selector) {
1811
- var ret = [];
1812
- var rel, i;
1813
-
1814
- if(rel = e[fn]) {
1815
- if(!selector || pl.selectedBy(rel, selector)) {
1816
- ret.push(rel);
1817
- }
1818
-
1819
- if(i = get(rel, selector)) {
1820
- return ret.concat(i);
1821
- }
1822
-
1823
- return ret;
1824
- }
1825
- };
1826
- }
1827
-
1828
- ret.elements = get(elem, mod);
1829
- return ret;
1830
- }
1831
- });
1832
-
1833
- pl.extend(pl.fn, {
1834
- toggleClass: function(c) {
1835
- pl.each(this.elements, function() {
1836
- pl(this)[pl(this).hasClass(c) ? 'removeClass' : 'addClass'](c);
1837
- });
1838
- return this;
1839
- },
1840
-
1841
- blur: function() {
1842
- pl.each(this.elements, function() {
1843
- this.blur();
1844
- });
1845
- return this;
1846
- },
1847
-
1848
- focus: function() {
1849
- pl.each(this.elements, function() {
1850
- this.focus();
1851
- });
1852
- return this;
1853
- },
1854
-
1855
- empty: function() {
1856
- return pl(this.elements).html('');
1857
- },
1858
-
1859
- tag: function(is) {
1860
- var tn = this.elements[0].tagName.toLowerCase();
1861
- return is ? is === tn : tn;
1862
- },
1863
-
1864
- val: function(insert) {
1865
- if(!pl.type(insert, 'undef')) {
1866
- pl.each(this.elements, function() {
1867
- this.value = insert;
1868
- });
1869
- return this;
1870
- } else {
1871
- return this.elements[0].value;
1872
- }
1873
- },
1874
-
1875
- prev: function(iterations) {
1876
- return pl.related(this.elements[0], 'previousSibling', iterations);
1877
- },
1878
-
1879
- next: function(iterations) {
1880
- return pl.related(this.elements[0], 'nextSibling', iterations);
1881
- },
1882
-
1883
- children: function(selector) {
1884
- var children = pl.related(this.elements[0] || this, 'children');
1885
- if(selector) {
1886
- children.elements = pl.filter(children.elements, function(e) {
1887
- return pl.selectedBy(e, selector);
1888
- });
1889
- }
1890
- return children;
1891
- },
1892
-
1893
- find: function(selector) {
1894
- var children = pl.related(this.elements[0] || this, 'children');
1895
- var list = [];
1896
- pl.each(children.elements, function(k, v) {
1897
- if(pl.selectedBy(this, selector)) {
1898
- list.push(v);
1899
- } else if(pl.type(v, 'obj')) {
1900
- var found = pl(this).find(selector).get();
1901
- found = pl.type(found, 'arr') ? found : [found];
1902
- list = list.concat(found);
1903
- }
1904
- });
1905
-
1906
- children.elements = list;
1907
- return children;
1908
- },
1909
-
1910
- parents: function(selector) {
1911
- return pl.related(this.elements[0] || this, 'parentNode', selector || '*');
1912
- },
1913
-
1914
- replaceWith: function(el, options) {
1915
- el = pl.type(el, 'str') ? pl(el, options || {}).get() : el;
1916
- pl.each(this.elements, function() {
1917
- this.parentNode.replaceChild(el, this);
1918
- });
1919
- return this;
1920
- },
1921
-
1922
- wrap: function(w, options) {
1923
- w = pl.type(w, 'str') ? pl(w, options || {}).get() : w;
1924
- pl.each(this.elements, function() {
1925
- pl(this).replaceWith(w).appendTo(w);
1926
- });
1927
- return this;
1928
- }
1929
- });
1930
-
1931
- })(this, document);
1932
-
1933
- /* Prevel Storage Extension
1934
- * (provides functionality for interacting with cookies, localstorage, ...)
1935
- *
1936
- * Requirements: Core.js
1937
- **/
1938
-
1939
- (function(win, doc, undefined) {
1940
-
1941
- var prefixes = {
1942
- localStorage: 'ls_',
1943
- sessionStorage: 'ss_'
1944
- },
1945
-
1946
- cookieAsSession = 60 * 60 * 24,
1947
- cookieAsStorage = cookieAsSession * 31 * 12 * 4,
1948
-
1949
- stringify = pl.stringify ?
1950
- pl.stringify :
1951
- win.JSON && win.JSON.stringify ?
1952
- win.JSON.stringify :
1953
- function(o) {return o;};
1954
-
1955
- pl.extend({
1956
- getStorage: function(name, type) {
1957
- var support = !!type;
1958
- return support ? type.getItem(name) : pl.storage.cookie(prefixes[String(type)] + name);
1959
- },
1960
-
1961
- setStorage: function(name, val, type) {
1962
- var support = !!type;
1963
-
1964
- if(support) {
1965
- if(pl.type(val, 'obj')) {
1966
- val = stringify(val);
1967
- }
1968
-
1969
- type.setItem(name, val);
1970
- } else {
1971
- pl.storage.cookie.set(prefixes[String(type)] + name, val, {
1972
- expires: type === 'localStorage' ? cookieAsStorage : cookieAsSession
1973
- });
1974
- }
1975
-
1976
- return storage[type];
1977
- },
1978
-
1979
- delStorage: function(name, type) {
1980
- var support = !!type;
1981
-
1982
- if(support) {
1983
- type.removeItem(name);
1984
- } else {
1985
- pl.storage.cookie.del(prefixes[String(type)] + name);
1986
- }
1987
-
1988
- return storage[type];
1989
- }
1990
- });
1991
-
1992
- // Main Router
1993
- var storage = (function() {
1994
- return function(name) {
1995
- return new storage.complexGet(name);
1996
- };
1997
- })();
1998
-
1999
- pl.extend(storage, {
2000
- // Storage Cookie Router
2001
- cookie: (function() {
2002
- return function(name) {
2003
- return new storage.cookie.get(name);
2004
- };
2005
- })(),
2006
-
2007
- // Storage LocalStorage Router
2008
- ls: (function() {
2009
- return function(name) {
2010
- return new storage.ls.get(name);
2011
- };
2012
- })(),
2013
-
2014
- session: (function() {
2015
- return function(name) {
2016
- return new storage.session.get(name);
2017
- };
2018
- })(),
2019
-
2020
- // Complex storage (based on all the technics)
2021
- complexGet: function(name) {
2022
- var token = [
2023
- storage.cookie(name),
2024
- storage.ls(name),
2025
- storage.session(name)
2026
- ];
2027
-
2028
- var ret, _break = false;
2029
- pl.each(token, function(key, val) {
2030
- if(_break) return;
2031
- if(val) {
2032
- ret = val;
2033
- _break = true;
2034
- }
2035
- });
2036
- return ret;
2037
- },
2038
- set: function(name, val) {
2039
- storage.cookie.set(name, val, {expires: cookieAsStorage});
2040
- storage.session.set(name, val);
2041
- return storage.ls.set(name, val);
2042
- },
2043
- del: function(name) {
2044
- storage.cookie.del(name);
2045
- storage.ls.del(name);
2046
- storage.session.del(name);
2047
- }
2048
- });
2049
-
2050
- // Storage Cookie Model
2051
- pl.extend(storage.cookie, {
2052
- get: function(name) {
2053
- var matches = doc.cookie.match(new RegExp(
2054
- '(?:^|; )' +
2055
- name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') +
2056
- '=([^;]*)'
2057
- ));
2058
- return matches ? decodeURIComponent(matches[1]) : null;
2059
- },
2060
- set: function(name, val, options) {
2061
- options = options || {};
2062
- var exp = options.expires;
2063
- if(exp) {
2064
- if(exp.toUTCString) {
2065
- exp = exp.toUTCString();
2066
- } else if(pl.type(exp, 'int')) {
2067
- exp = exp * 1000 + (+new Date());
2068
- }
2069
- options.expires = exp;
2070
- }
2071
-
2072
- var cookie = [name + '=' + encodeURIComponent(val)];
2073
- for(var o in options) {
2074
- cookie.push(options[o] === true ? o : o + '=' + options[o]);
2075
- }
2076
- doc.cookie = cookie.join('; ');
2077
-
2078
- return storage.cookie;
2079
- },
2080
- del: function(name) {
2081
- return storage.cookie.set(name, '', {expires: -1});
2082
- }
2083
- });
2084
-
2085
- // Local Storage Model
2086
- pl.extend(storage.ls, {
2087
- get: function(name) {
2088
- return pl.getStorage(name, localStorage);
2089
- },
2090
- set: function(name, val) {
2091
- return pl.setStorage(name, val, localStorage);
2092
- },
2093
- del: function(name) {
2094
- return pl.delStorage(name, localStorage);
2095
- }
2096
- });
2097
-
2098
- // Session Storage Model
2099
- pl.extend(storage.session, {
2100
- get: function(name) {
2101
- return pl.getStorage(name, sessionStorage);
2102
- },
2103
- set: function(name, val) {
2104
- return pl.setStorage(name, val, sessionStorage);
2105
- },
2106
- del: function(name) {
2107
- return pl.delStorage(name, sessionStorage);
2108
- }
2109
- });
2110
-
2111
- pl.extend({storage: storage});
2112
-
2113
- })(this, document);
2114
-
2115
- })(this, document, 'prototype', 'addEventListener',
2116
- 'getElement', 'className', 'null', 'undef',
2117
- '<([A-z]+[1-6]*)>', null, function() {});