This repository has been archived by the owner on Feb 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
potlite.js
20733 lines (20524 loc) · 560 KB
/
potlite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* PotLite.js - JavaScript library
*
* PotLite.js is an implemental utility library
* that can execute JavaScript without burdening the CPU.
*
* Version 1.3.9, 2014-12-16
* Copyright (c) 2012-2014 polygon planet <[email protected]>
* Dual licensed under the MIT or GPL v2 licenses.
* https://github.com/polygonplanet/Pot.js
* http://polygonplanet.github.com/Pot.js/
*/
/**
* Project PotLite.js
*
* @description
* <p>
* Pot.js is a JavaScript library that can be performed without causing
* stress to the UI and the CPU load by using easy loop iteration functions.
* With respect to load, you can implement a particular application without
* requiring the programmer to be aware of.
* Pot.js is built around the asynchronous processing
* and iterator with Deferred.
* Pot.Deferred is a Deferred object like MochiKit (or JSDeferred like).
* That makes it possible to various iterations (forEach, filter, map,
* reduce, zip, repeat, some etc.).
* Moreover, Pot.js is an utility library that handles string processes with
* various algorithms,
* and it has the Signal object that can write like aspect-oriented (AOP),
* and it has the Event object for DOM listener,
* and treats it the File API for HTML5. etc.
* And, Pot.js never pollute the prototype of the global objects.
* We only define the 'Pot' object in the global scope basically.
* You can use Pot.js with other available libraries without fear of conflict.
* Pot.js is a cross-browser library that works on a Web browser, Node.js,
* userscript (Greasemonkey, Scriptish) XUL, or (Firefox Add-ons) etc.
* PotLite.js is a light version that extracts only the part of asynchronous
* processing (Deferred etc.) has been implemented in Pot.js.
* </p>
*
* @description
* <p>
* Pot.js は、
* JavaScript のループ処理における CPU 負荷を抑え、
* UI にストレスを与えることなく実行できるライブラリです。
* 負荷に関して、とくにプログラマが意識する必要なく
* アプリケーションを実装することができます。
* Pot.js は、Deferred による非同期処理や、
* 非同期イテレータを中心に作られています。
* MochiKit ライク (または JSDeferred ライク) な Pot.Deferred によって、
* 多様なイテレート (forEach, filter, map, reduce, zip, repeat, some など)
* を可能とします。
* また、様々なアルゴリズムを扱った文字列処理や、
* アスペクト指向 (AOP) で書ける シグナルやイベント処理、
* HTML5 に関する File API などを扱うことができる
* 汎用ユーティリティライブラリです。
* そして、グローバルオブジェクトの prototype を汚染しません。
* 基本的にグローバルに定義されるのは 'Pot' オブジェクトだけなので
* コンフリクトの心配なく、他の JavaScript ライブラリと共に利用できます。
* Pot.js は、クロスブラウザであり、Web ブラウザ上や Node.js、
* userscript (Greasemonkey, Scriptish) や
* XUL (Firefox アドオン) 上などで動きます。
* PotLite.js は、
* Pot.js で実装されている Deferred などの
* 非同期処理の部分だけを抽出したライトバージョンです。
* </p>
*
*
* @fileoverview PotLite.js library
* @author polygon planet
* @version 1.3.9
* @date 2014-12-16
* @link https://github.com/polygonplanet/Pot.js
* @link http://polygonplanet.github.com/Pot.js/
* @copyright Copyright (c) 2012-2014 polygon planet <[email protected]>
* @license Dual licensed under the MIT or GPL v2 licenses.
*
* Based:
* - JSDeferred
* http://github.com/cho45/jsdeferred
* - MochiKit.Async
* http://mochikit.com/
* - jQuery.Deferred
* http://jquery.com/
* - Tombloo library (Firefox Add-On)
* https://github.com/to/tombloo/wiki
*/
/*
* JSDoc Comment
* http://code.google.com/intl/ja/closure/compiler/docs/js-for-compiler.html
*/
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
/**
* @namespace PotLite.js
*/
(function PotScriptImplementation(globals) {
'use strict';
/**
* Define the object Pot.
*
* @name Pot
* @type Object
* @class
* @static
* @public
*/
var Pot = {VERSION : '1.38', TYPE : 'lite'},
// Refer the Pot properties/functions.
PotSystem,
PotPlugin,
PotToString,
PotBrowser,
PotLang,
PotOS,
PotGlobal,
PotNoop,
PotTmp,
PotInternal,
// Asynchronous/Iteration methods/properties.
PotInternalCallInBackground,
PotInternalSetTimeout,
PotInternalClearTimeout,
PotStopIteration,
// is* : object typing.
typeOf,
typeLikeOf,
isBoolean,
isNumber,
isString,
isFunction,
isArray,
isDate,
isRegExp,
isObject,
isError,
isTypedArray,
isArrayBuffer,
isArrayLike,
isNumeric,
isStopIter,
isDeferred,
isHash,
isIter,
isWorkeroid,
isWindow,
isDocument,
isElement,
isNodeList,
isNodeLike,
// Constructors.
Deferred,
Iter,
PotInternalLightIterator,
Signal,
DropFile,
Workeroid,
// A shortcut of prototype methods/functions.
ArrayProto = Array.prototype,
ObjectProto = Object.prototype,
StringProto = String.prototype,
FunctionProto = Function.prototype,
push = ArrayProto.push,
slice = ArrayProto.slice,
splice = ArrayProto.splice,
concat = ArrayProto.concat,
unshift = ArrayProto.unshift,
indexOf = ArrayProto.indexOf,
lastIndexOf = ArrayProto.lastIndexOf,
toString = ObjectProto.toString,
hasOwnProperty = ObjectProto.hasOwnProperty,
toFuncString = FunctionProto.toString,
fromCharCode = String.fromCharCode,
/**
* faster way of String.fromCharCode(c).
* @ignore
*/
fromUnicode = (function() {
var i, maps = [];
for (i = 0; i <= 0xFFFF; i++) {
maps[i] = fromCharCode(i);
}
return function(c) {
return maps[c & 0xFFFF];
};
}()),
// Regular expression patterns.
RE_RESCAPE = /([-.*+?^${}()|[\]\/\\])/g,
RE_PERCENT_ENCODED = /^(?:[a-zA-Z0-9_~.-]|%[0-9a-fA-F]{2})*$/,
RE_ARRAYLIKE = /List|Collection/i,
RE_TRIM = /^[\s\u00A0\u3000]+|[\s\u00A0\u3000]+$/g,
// Mozilla XPCOM Components.
Ci, Cc, Cr, Cu;
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
(function(nv) {
// Define environment properties.
update(Pot, {
/**
* @lends Pot
*/
/**
* Name of the Pot.
*
* @const
* @ignore
*/
NAME : 'Pot',
/**
* Execution environment.
*
*
* @example
* if (Pot.System.isWebBrowser) {
* document.write('on Web Browser');
* }
*
*
* @type Object
* @class
* @static
* @const
* @public
*
* @property {Boolean} isWebBrowser
* Whether the environment is running on web browser.
* @property {Boolean} isNonBrowser
* Whether the environment is running on non-browser.
* @property {Boolean} isNodeJS
* Whether the environment is running on Node.js.
* @property {Boolean} isWaitable
* Whether the user agent can to wait as synchronously.
* @property {Boolean} hasComponents
* Whether the environment has Components (XPCOM).
* @property {Boolean} hasActiveXObject
* Whether the environment has ActiveXObject.
* @property {Boolean} isYieldable
* Whether the environment can use "yield" operator.
* @property {Boolean} isFirefoxExtension
* Whether the environment is running on Firefox extension.
* @property {Boolean} isChromeExtension
* Whether the environment is running on Chrome extension.
* @property {Boolean} isSafariExtension
* Whether the environment is running on Safari extension.
* @property {Boolean} isGreasemonkey
* Whether the environment is running on Greasemonkey.
* @property {Boolean} isJetpack
* Whether the environment is running on Jetpack.
* @property {Boolean} isNotExtension
* Whether the environment is running on non browser-extension.
*/
System : {},
/**
* Pot plugin object.
*
*
* @example
* // Register my plugin function.
* Pot.addPlugin('myFunc', function(msg) {
* alert('myFunc: ' + msg);
* });
* // Call function that is able to refer from the Pot object.
* Pot.myFunc('Hello!'); // 'myFunc: Hello!'
* // Check exists.
* debug( Pot.hasPlugin('myFunc') ); // true
* // Register other plugin function.
* Pot.addPlugin('myFunc2', function(a, b) {
* return a + b;
* });
* // Call other function.
* debug( Pot.myFunc2(1, 2) ); // 3
* // addPlugin does not overwrite function on default.
* debug( Pot.addPlugin('myFunc', function() {}) ); // false
* // View list of plugins.
* debug( Pot.listPlugin() ); // ['myFunc', 'myFunc2']
* // Remove my plugin.
* Pot.removePlugin('myFunc');
* debug( Pot.hasPlugin('myFunc') ); // false
* debug( Pot.listPlugin() ); // ['myFunc2']
*
*
* @example
* Pot.addPlugin({
* foo : function() { return 'foo!'; },
* bar : function() { return 'bar!'; },
* baz : function() { return 'baz!'; }
* });
* debug(Pot.foo() + Pot.bar() + Pot.baz()); // 'foo!bar!baz!'
*
*
* @example
* // Register function.
* Pot.addPlugin('foo', function() { return 'foo!'; });
* // Try change function.
* var newFoo = function() { return 'NewFoo!' };
* debug( Pot.addPlugin('foo', newFoo) ); // false
* // Overwrite plugin function.
* debug( Pot.addPlugin('foo', newFoo, true) ); // true
* debug( Pot.foo() ); // 'NewFoo!'
*
*
* @example
* var toArray = function(string) {
* return string.split('');
* };
* // Plugin function has 'deferred' method.
* Pot.addPlugin('toArray', toArray);
* // Synchronous
* debug( Pot.toArray('abc') ); // ['a', 'b', 'c']
* // Asynchronous
* Pot.toArray.deferred('abc').then(function(res) {
* debug(res); // ['a', 'b', 'c']
* });
*
*
* @example
* var string = '\t abc\n \t ';
* // Original Pot.trim().
* debug(Pot.trim(string)); // 'abc'
* // Overwrite Pot.trim().
* Pot.addPlugin('trim', function(s) {
* return s.replace(/^ +| +$/g, '');
* });
* // New Pot.trim().
* debug(Pot.trim(string)); // '\t abc\n \t'
* // Removes new Pot.trim().
* Pot.removePlugin('trim');
* // Back to the original.
* debug(Pot.trim(string)); // 'abc'
*
*
* @type Object
* @class
* @static
* @public
*/
Plugin : {},
/**
* toString.
*
* @return Return formatted string of object.
* @type Function
* @function
* @static
*/
toString : function() {
return buildObjectString(this.NAME || this.name || typeof this);
},
/**
* Detect the browser running.
*
* @example
* if (Pot.Browser.firefox) {
* debug('Firefox version:' + Pot.Browser.firefox.version);
* }
*
* @type Object
* @class
* @static
* @const
*
* @property {Object} webkit WebKit engine.
* @property {Object} opera Opera.
* @property {Object} msie MSIE.
* @property {Object} mozilla Mozilla engine.
* @property {Object} firefox Mozilla Firefox.
* @property {Object} chrome Google Chrome.
* @property {Object} safari Safari.
* @property {Object} iphone iPhone.
* @property {Object} ipod iPod.
* @property {Object} ipad iPad.
* @property {Object} android Android.
* @property {Object} blackberry BlackBerry.
*/
Browser : (function(n) {
var r = {}, m, ua, ver, i, len, re = {
webkit : /(webkit)(?:.*version|)[\s\/]+([\w.]+)/,
opera : /(opera)(?:.*version|)[\s\/]+([\w.]+)/,
msie : /(msie)[\s\/]+([\w.]+)/,
mozilla : /(?!^.*compatible.*$).*(mozilla)(?:.*?\s+rv[:\s\/]+([\w.]+)|)/
},
rs = [
/webkit.*version[\s\/]+([\w.]+).*(safari)/,
/webkit.*(chrome|safari)[\s\/]+([\w.]+)/,
/(iphone|ipod|ipad|android).*version[\s\/]+([\w.]+)/,
/(blackberry)(?:[\s\d]*|.*version)[\s\/]+([\w.]+)/,
re.webkit,
re.opera,
re.msie,
/(?!^.*compatible.*$).*mozilla.*?(firefox)(?:[\s\/]+([\w.]+)|)/,
re.mozilla
],
u = ('' + (n && n.userAgent)).toLowerCase();
if (u) {
for (i = 0, len = rs.length; i < len; i++) {
if ((m = rs[i].exec(u))) {
break;
}
}
if (m) {
if (/[^a-z]/.test(m[1])) {
ua = m[2];
ver = m[1];
} else {
ua = m[1];
ver = m[2];
}
if (ua) {
r[ua] = {version : '' + (ver || 0)};
}
}
m = re.webkit.exec(u) || re.opera.exec(u) ||
re.msie.exec(u) || re.mozilla.exec(u) || [];
if (m && m[1]) {
r[m[1]] = {version : '' + (m[2] || 0)};
}
}
return r;
}(nv)),
/**
* Detect the browser/user language.
*
* @example
* if (Pot.LANG == 'ja') {
* debug('ハローワールド');
* }
*
* @type String
* @static
* @const
*/
LANG : (function(n) {
return ((n && (n.language || n.userLanguage ||
n.browserLanguage || n.systemLanguage)) ||
'en').split(/[^a-zA-Z0-9]+/).shift().toLowerCase();
}(nv)),
/**
* Detect the user operating system.
*
* @example
* if (Pot.OS.win) {
* debug('OS : ' + Pot.OS.toString());
* }
*
* @type Object
* @class
* @static
* @const
*
* @property {Boolean} iphone iPhone.
* @property {Boolean} ipod iPod.
* @property {Boolean} ipad iPad.
* @property {Boolean} blackberry BlackBerry.
* @property {Boolean} android Android.
* @property {Boolean} mac Mac.
* @property {Boolean} win Windows.
* @property {Boolean} linux Linux.
* @property {Boolean} x11 X11.
* @property {Function} toString Represents OS as a string.
*/
OS : (function(nv) {
var r = {}, n = nv || {}, i, len, o,
pf = ('' + (n.platform)).toLowerCase(),
ua = ('' + (n.userAgent)).toLowerCase(),
av = ('' + (n.appVersion)).toLowerCase(),
maps = [
{s : 'iphone', p : pf},
{s : 'ipod', p : pf},
{s : 'ipad', p : ua},
{s : 'blackberry', p : ua},
{s : 'android', p : ua},
{s : 'mac', p : pf},
{s : 'win', p : pf},
{s : 'linux', p : pf},
{s : 'x11', p : av}
];
for (i = 0, len = maps.length; i < len; i++) {
o = maps[i];
if (~o.p.indexOf(o.s)) {
r[o.s] = true;
}
}
if (r.android && !~ua.indexOf('mobile')) {
r.androidtablet = true;
}
if (r.ipad || r.androidtablet) {
r.tablet = true;
}
/**
* @return {String} Return the platform as a string.
* @ignore
*/
r.toString = function() {
var s = [], p;
for (p in r) {
if (r[p] === true) {
s.push(p);
}
}
return s.join('/');
};
return r;
}(nv)),
/**
* Global object. (e.g. window)
*
* @type Object
* @static
* @public
*/
Global : (function() {
var g = (new Function('return this;'))();
if (!globals ||
typeof globals !== 'object' || !('setTimeout' in globals)) {
globals = this || g || {};
}
return this || g || {};
}()),
/**
* Noop function.
*
* @type Function
* @function
* @const
*/
noop : function() {},
/**
* Temporary storage place.
*
* @type Object
* @private
* @ignore
*/
tmp : {},
/**
* Treats the internal properties/methods.
*
* @internal
* @type Object
* @class
* @private
* @ignore
*/
Internal : {
/**
* @lends Pot.Internal
*/
/**
* Numbering the magic numbers for the constructor.
*
* @private
* @ignore
*/
getMagicNumber : (function(sn) {
var c = 0, n = +sn;
return function() {
var i = n + (c++);
if (!isFinite(i) || isNaN(i)) {
c = n = i = 0;
}
return i;
};
}('0xC26BEB642C0A')),
/**
* Get the export object.
*
* @private
* @ignore
*/
getExportObject : function(forGlobalScope) {
var outputs, id, valid;
if (forGlobalScope) {
if (PotSystem.isNonBrowser) {
outputs = PotGlobal || globals;
} else {
outputs = (isWindow(globals) && globals) ||
(isWindow(PotGlobal) && PotGlobal) ||
Pot.currentWindow();
}
if (!outputs &&
typeof window !== 'undefined' && isWindow(window)) {
outputs = window;
}
if (outputs) {
do {
id = buildSerial(Pot, '');
} while (id in outputs);
outputs[id] = 1;
valid = (new Function('try{return ' + id + '===1;}catch(e){}'))();
try {
delete outputs[id];
} catch (e) {
try {
outputs[id] = void 0;
} catch (e) {}
}
if (!valid) {
outputs = PotGlobal;
}
}
}
if (!outputs) {
if (PotSystem.isNodeJS) {
if (typeof module === 'object' &&
typeof module.exports === 'object') {
outputs = module.exports;
} else if (typeof exports === 'object') {
outputs = exports;
} else {
outputs = globals;
}
} else {
outputs = globals;
}
if (!outputs) {
outputs = globals || PotGlobal || Pot.currentWindow();
}
}
return outputs;
},
/**
* Pot.js Script Implementation.
*
* @private
* @ignore
*/
ScriptImplementation : PotScriptImplementation
},
/**
* @lends Pot
*/
/**
* Extend target object from arguments.
*
*
* @example
* var obj = {foo: 'v1', bar: 'v2'};
* var src = {baz: 'v3'};
* update(obj, src);
* debug(obj);
* // @results obj = {foo: 'v1', bar: 'v2', baz: 'v3'}
*
*
* @param {Object} target Target object.
* @param {...Object} (...) Subject objects.
* @return {Object} Updated object. (first argument).
* @static
* @function
* @public
*/
update : update,
/**
* Refer Pot object.
*
* @ignore
*/
Pot : Pot
});
}(typeof navigator !== 'undefined' && navigator || {}));
// Refer the Pot properties.
PotSystem = Pot.System;
PotPlugin = Pot.Plugin;
PotToString = Pot.toString;
PotBrowser = Pot.Browser;
PotLang = Pot.LANG;
PotOS = Pot.OS;
PotGlobal = Pot.Global;
PotNoop = Pot.noop;
PotTmp = Pot.tmp;
PotInternal = Pot.Internal;
// Definition of System.
update(PotSystem, (function() {
var o = {}, g, ws, b, u, ua, ca;
o.isWaitable = false;
if (typeof window === 'object' && 'setTimeout' in window &&
window.window == window &&
typeof document === 'object' && document.nodeType > 0 &&
typeof document.documentElement === 'object'
) {
o.isWebBrowser = true;
if (window.location &&
/^(?:chrome|resource):?$/.test(window.location.protocol)) {
try {
if (typeof Components !== 'object') {
throw false;
}
Cc = Components.classes;
Ci = Components.interfaces;
Cr = Components.results;
Cu = Components.utils;
o.isWaitable = true;
o.hasComponents = true;
if (PotBrowser.firefox || PotBrowser.mozilla) {
o.isFirefoxExtension = true;
}
} catch (e) {
// If you need XPCOM, try following privilege.
// e.g.
// netscape.security.PrivilegeManager
// .enablePrivilege('UniversalXPConnect');
// or
// about:config :
// signed.applets.codebase_principal_support : true (default=false)
//
Ci = Cc = Cr = Cu = null;
}
}
} else {
o.isNonBrowser = true;
if (typeof process !== 'undefined' && process && process.version &&
typeof require === 'function' &&
(typeof exports === 'object' ||
(typeof module === 'object' && typeof module.exports === 'object'))
) {
o.isNodeJS = true;
}
}
if (PotGlobal && PotGlobal.ActiveXObject ||
typeof ActiveXObject !== 'undefined' && ActiveXObject) {
o.hasActiveXObject = true;
}
if (!o.isFirefoxExtension) {
if (PotBrowser.chrome || PotBrowser.webkit || PotBrowser.safari) {
if (typeof chrome === 'object' &&
typeof chrome.extension === 'object') {
o.isChromeExtension = true;
} else if (typeof safari === 'object' &&
typeof safari.extension === 'object') {
o.isSafariExtension = true;
}
}
}
if (!o.isChromeExtension && !o.isSafariExtension) {
if (typeof GM_log === 'function' &&
typeof GM_xmlhttpRequest === 'function') {
o.isGreasemonkey = true;
} else if (typeof require === 'function') {
try {
if ('title' in require('windows').browserWindows.activeWindow) {
o.isJetpack = true;
}
} catch (e) {}
}
if (o.isWebBrowser && !o.isGreasemonkey && !o.isFirefoxExtension) {
o.isNotExtension = true;
}
}
try {
/**@ignore*/
g = (new Function('yield(0);'))();
if (g && typeof g.next === 'function') {
o.isYieldable = true;
}
} catch (e) {}
try {
if (typeof FileReader !== 'undefined' &&
typeof FileReader.LOADING !== 'undefined' &&
typeof (new FileReader()).readAsText === 'function') {
o.hasFileReader = true;
}
} catch (e) {}
try {
if (typeof Blob === 'function' &&
toString.call(new Blob()) === '[object Blob]' &&
typeof Blob.prototype.slice === 'function') {
o.hasBlob = true;
}
} catch (e) {}
try {
b = (typeof BlobBuilder !== 'undefined') ? BlobBuilder :
(typeof MozBlobBuilder !== 'undefined') ? MozBlobBuilder :
(typeof WebKitBlobBuilder !== 'undefined') ? WebKitBlobBuilder :
(typeof MSBlobBuilder !== 'undefined') ? MSBlobBuilder : null;
if (!b ||
typeof b !== 'function' ||
typeof b.prototype.append !== 'function' ||
typeof b.prototype.getBlob !== 'function'
) {
b = null;
} else {
o.BlobBuilder = b;
if (b &&
typeof MozBlobBuilder !== 'undefined' && b === MozBlobBuilder) {
o.isMozillaBlobBuilder = true;
}
}
} catch (e) {}
/**@ignore*/
o.createBlob = function() {
if (o.hasBlob) {
return function(value, type) {
var arr = concat.call([], value);
if (type) {
return new Blob(arr, {type : type});
} else {
return new Blob(arr);
}
};
} else if (o.BlobBuilder) {
return function(value, type) {
var blb = new o.BlobBuilder();
blb.append(value);
if (type) {
return blb.getBlob(type);
} else {
return blb.getBlob();
}
};
}
}();
try {
u = (typeof URL !== 'undefined') ? URL :
(typeof webkitURL !== 'undefined') ? webkitURL : null;
if (!u || typeof u.createObjectURL !== 'function') {
u = null;
} else {
o.BlobURI = u;
}
} catch (e) {}
ws = [];
if (typeof Worker === 'function') {
ws.push([Worker, 'Worker']);
}
if (typeof ChromeWorker === 'function') {
ws.push([ChromeWorker, 'ChromeWorker']);
}
while (ws.length) {
(function() {
var item = ws.shift(),
worker = item[0],
key = item[1],
hasWorker = 'has' + key,
canWorkerDataURI = 'can' + key + 'DataURI',
canWorkerBlobURI = 'can' + key + 'BlobURI',
canWorkerPostObject = 'can' + key + 'PostObject',
ref, msg, w, wb;
/**@ignore*/
ref = function() {
return 1;
};
msg = {
/**@ignore*/
a : function() {
return ref();
}
};
try {
if (typeof worker.prototype.postMessage === 'function') {
// hasWorker: 'hasWorker' or 'hasChromeWorker'
o[hasWorker] = true;
w = new worker(
'data:application/javascript;base64,' +
// base64:
// onmessage = function(e) {
// postMessage(
// (e && e.data &&
// ((typeof e.data.a === 'function' && e.data.a()) ||
// e.data
// )
// ) + 1
// )
// }
'b25tZXNzYWdlPWZ1bmN0aW9uKGUpe3Bvc3RNZXNzYWdlKChlJiZlLmRhdGEmJ' +
'igodHlwZW9mIGUuZGF0YS5hPT09J2Z1bmN0aW9uJyYmZS5kYXRhLmEoKSl8fG' +
'UuZGF0YSkpKzEpfQ=='
);
/**@ignore*/
w.onmessage = function(ev) {
if (ev) {
switch (ev.data) {
case (msg.a() + 1):
// canWorkerPostObject:
// 'canWorkerPostObject' or 'canChromeWorkerPostObject'
PotSystem[canWorkerPostObject] = true;
// FALL THROUGH
case (msg + 1):
case 'x1':
// canWorkerDataURI:
// 'canWorkerDataURI' or 'canChromeWorkerDataURI'
PotSystem[canWorkerDataURI] = true;
}
}
try {
w.terminate();
} catch (ex) {}
};
try {
w.postMessage(msg);
} catch (ex) {
w.postMessage('x');
}
}
} catch (e) {}
if (o[hasWorker] && o.createBlob && o.BlobURI) {
try {
wb = new worker(o.BlobURI.createObjectURL(o.createBlob(
'onmessage=function(e){' +
'postMessage(' +
'(e&&e.data&&' +
'((typeof e.data.a==="function"&&e.data.a())||e.data)' +
')+1' +
')' +
'}'
)));
/**@ignore*/
wb.onmessage = function(ev) {
if (ev) {
switch (ev.data) {
case (msg.a() + 1):
PotSystem[canWorkerPostObject] = true;
// FALL THROUGH
case (msg + 1):
case 'x1':
// canWorkerBlobURI:
// 'canWorkerBlobURI' or 'canChromeWorkerBlobURI'
PotSystem[canWorkerBlobURI] = true;
}
}
try {
wb.terminate();
} catch (ex) {}
};
try {
wb.postMessage(msg);
} catch (ex) {
wb.postMessage('x');
}
} catch (e) {}
}
}());
}
try {
if (typeof ArrayBuffer !== 'undefined' &&
(new ArrayBuffer(10)).byteLength === 10 &&
typeof Uint8Array !== 'undefined' &&
(new Uint8Array([0, 312])).subarray(1)[0] === 56
) {
o.hasTypedArray = true;
try {
ua = new Uint8Array([1, 2]);
ca = new Uint8Array(ua.subarray(0));
ca[0] = 5;
if (ua[0] === 1 && ca[0] === 5) {
o.canCopyTypedArray = true;
}
ua = ca = null;
} catch (ex) {}
try {
if (typeof Uint8ClampedArray !== 'undefined' &&
(new Uint8ClampedArray([0, 312])).subarray(1)[0] === 255) {
o.hasUint8ClampedArray = true;
}
} catch (ex) {}
if (typeof DataView !== 'undefined' &&
(new DataView(new Uint8Array([
0x10, 0x20, 0x40, 0x80
]).buffer)).getUint32(0) === 0x10204080) {
o.hasDataView = true;
}
}
} catch (e) {}
return o;
}()));
/**
* Creates methods to detect the type definition.
*
* <pre>
* Pot.is*
*
* * ::= Boolean | Number | String | Function |
* Array | Date | RegExp | Object | Error
* </pre>
*
*
* @example
* Pot.isString(100); // false
* Pot.isObject('hoge'); // false
* Pot.isArray([1, 2, 3]); // true
*
*
* @param {*} A target object
* @return {Boolean} Returns whether the proper object
* @lends Pot
* @static
* @public
*
* @property {Function} isBoolean Detect the Boolean type. (static)