-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
1763 lines (1429 loc) · 47 KB
/
index.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
/**
* Require the module at `name`.
*
* @param {String} name
* @return {Object} exports
* @api public
*/
function require(name) {
var module = require.modules[name];
if (!module) throw new Error('failed to require "' + name + '"');
var definition = module.definition;
if (definition) {
delete module.definition;
definition.call(this, module.exports = {}, module);
}
return module.exports;
}
/**
* Registered modules.
*/
require.modules = {};
/**
* Register module at `name` with callback `definition`.
*
* @param {String} name
* @param {Function} definition
* @api private
*/
require.register = function (name, definition) {
require.modules[name] = {
definition: definition
};
};
require.register("barberboy/[email protected]/src/utils/separate-selector", function (exports, module) {
module.exports = function(selector){
return selector.split(/\s*,\s*/);
};
});
require.register("barberboy/[email protected]/src/scope/", function (exports, module) {
var separateSelector = require("barberboy/[email protected]/src/utils/separate-selector");
module.exports = function(selector, method){
var selectors = separateSelector(selector);
var scopedSelectors = selectors.map(method);
return scopedSelectors.join();
};
// normalize:common:info: rewriting dependency "../utils/separate-selector" to "../utils/separate-selector.js"
});
require.register("barberboy/[email protected]/src/scope/support", function (exports, module) {
try {
document.createElement('i').querySelector(':scoped *');
module.exports = true;
} catch (e) {
module.exports = false;
}
});
require.register("barberboy/[email protected]/src/elements/", function (exports, module) {
// as it is a circular dependency, we need to keep `module.exports` on top.
module.exports = Elements;
var pushUniq = require("barberboy/[email protected]/src/utils/pushuniq");
var elementsPrototype = Elements.prototype = [];
var methods = require("barberboy/[email protected]/src/methods/");
function Elements() {}
// Elements.queryAll(selector);
elementsPrototype.queryAll = function (selector) {
var pusher = pushUniq();
return this.reduce(function(results, element){
return pusher(methods.queryAll.call(element, selector));
}, null);
};
// Elements.query(selector);
elementsPrototype.query = function (selector) {
return elementsPrototype.queryAll.call(this, selector)[0] || null;
};
// normalize:common:info: rewriting dependency "../utils/pushuniq" to "../utils/pushuniq.js"
// normalize:common:info: rewriting dependency "../methods" to "../methods/index.js"
});
require.register("barberboy/[email protected]/src/utils/expando", function (exports, module) {
module.exports = String(Math.random()).replace(/\D/g, '');
});
require.register("barberboy/[email protected]/src/utils/pushuniq", function (exports, module) {
var Elements = require("barberboy/[email protected]/src/elements/");
var expando = require("barberboy/[email protected]/src/utils/expando");
var propertyName = 'domElementsId' + expando;
var id = -1;
/**
* pushUniq
*
* returns a function that pushes elements not yet in `target`.
* as the internal API only uses it before making the array
* available, we can use a `map` cache to store the elements
* already in the newly built array, letting us prevent extensive looping.
*/
module.exports = function (original) {
var target = new Elements();
var map = {};
function pusher(source) {
var index = -1;
var length = source.length;
var item;
while (++index < length) {
item = source[index];
if (!item || item.nodeType !== 1) {
continue;
}
if (propertyName in item && map.hasOwnProperty(item[propertyName])) {
continue;
}
item[propertyName] = ++id;
map[id] = 1;
target.push(item);
}
return target;
}
if(arguments.length) {
pusher(original);
}
return pusher;
};
// normalize:common:info: rewriting dependency "../elements" to "../elements/index.js"
// normalize:common:info: rewriting dependency "./expando" to "./expando.js"
});
require.register("barberboy/[email protected]/src/methods/", function (exports, module) {
var scope = require("barberboy/[email protected]/src/scope/");
var supportsScoped = require("barberboy/[email protected]/src/scope/support");
var methods = module.exports = {};
var Elements = require("barberboy/[email protected]/src/elements/");
var toArray = require("barberboy/[email protected]/src/utils/to-array");
var attributeName = require("barberboy/[email protected]/src/methods/attribute-name");
var scopeSelector = require("barberboy/[email protected]/src/methods/scope-selector");
var absolutizeSelector = require("barberboy/[email protected]/src/methods/absolutize-selector");
var unique = -1;
methods.query = function(selector){
return methods.queryAll.call(this, selector)[0] || null;
};
methods.queryAll = function(sourceSelector){
var element = this;
var elements;
var selector;
var result;
if(!supportsScoped) {
element.setAttribute(attributeName, ++unique);
}
selector = supportsScoped ?
scope(sourceSelector, scopeSelector) :
scope(sourceSelector, absolutizeSelector(unique));
elements = element.querySelectorAll(selector);
if (!supportsScoped) {
element.removeAttribute(attributeName);
}
result = new Elements();
result.push.apply(result, toArray(elements));
return result;
};
methods.queryAllWrapper = function(selector){
var elements = this.querySelectorAll(selector);
var result = new Elements();
result.push.apply(result, toArray(elements));
return result;
};
methods.queryWrapper = function(selector){
return this.querySelector(selector);
};
// normalize:common:info: rewriting dependency "../scope" to "../scope/index.js"
// normalize:common:info: rewriting dependency "../scope/support" to "../scope/support.js"
// normalize:common:info: rewriting dependency "../elements" to "../elements/index.js"
// normalize:common:info: rewriting dependency "../utils/to-array" to "../utils/to-array.js"
// normalize:common:info: rewriting dependency "./attribute-name" to "./attribute-name.js"
// normalize:common:info: rewriting dependency "./scope-selector" to "./scope-selector.js"
// normalize:common:info: rewriting dependency "./absolutize-selector" to "./absolutize-selector.js"
});
require.register("barberboy/[email protected]/src/utils/to-array", function (exports, module) {
module.exports = function(nodeList){
var index = -1;
var length = nodeList.length;
var array = Array(length);
while (++index < length) {
array[index] = nodeList[index];
}
return array;
};
});
require.register("barberboy/[email protected]/src/methods/attribute-name", function (exports, module) {
module.exports = 'data-dom-elements-id-' + require("barberboy/[email protected]/src/utils/expando");
// normalize:common:info: rewriting dependency "../utils/expando" to "../utils/expando.js"
});
require.register("barberboy/[email protected]/src/methods/scope-selector", function (exports, module) {
module.exports = function (item) {
return ':scoped ' + item;
};
});
require.register("barberboy/[email protected]/src/methods/absolutize-selector", function (exports, module) {
var attributeName = require("barberboy/[email protected]/src/methods/attribute-name");
module.exports = function (attributeValue) {
return function (item){
return '[' + attributeName + '="' + attributeValue + '"] ' + item;
};
};
// normalize:common:info: rewriting dependency "./attribute-name" to "./attribute-name.js"
});
require.register("barberboy/[email protected]/src/utils/is-native", function (exports, module) {
var nativeToString = Function.prototype.toString;
var nativeQuerySelector = nativeToString.call(document.querySelector);
var nameRE = /\bquerySelector\b/g;
module.exports = function(context, name){
if (!context[name]) {
return false;
}
return (
nativeToString.call(context[name]) ===
nativeQuerySelector.replace(nameRE, name)
);
};
});
require.register("barberboy/[email protected]/src/", function (exports, module) {
var methods = require("barberboy/[email protected]/src/methods/");
var isNative = require("barberboy/[email protected]/src/utils/is-native");
var array = [];
if (
typeof Document === 'undefined' ||
!('map' in array) ||
!('reduce' in array) ||
!('querySelectorAll' in document)
) {
throw new TypeError('Missing browser features to initiantiate dom-elements');
}
if('Element' in window) {
if(!isNative(Element.prototype, 'query')) {
Element.prototype.query = methods.query;
}
if(!isNative(Element.prototype, 'queryAll')) {
Element.prototype.queryAll = methods.queryAll;
}
}
['Document', 'DocumentFragment'].forEach(function (ParentNode) {
var prototype;
// Don't throw errors if these globals don't exist — just move on.
if (!(ParentNode in window)) {
return;
}
prototype = window[ParentNode].prototype;
if (!isNative(prototype, 'query')) {
prototype.query = methods.queryWrapper;
}
if (!isNative(prototype, 'queryAll')) {
prototype.queryAll = methods.queryAllWrapper;
}
});
// normalize:common:info: rewriting dependency "./methods" to "./methods/index.js"
// normalize:common:info: rewriting dependency "./utils/is-native" to "./utils/is-native.js"
});
require.register("barberboy/[email protected]", function (exports, module) {
module.exports = require("barberboy/[email protected]/src/")
});
require.register("webreflection/[email protected]/build/dom4", function (exports, module) {
/*! (C) WebReflection Mit Style License */
(function(e){"use strict";function t(t){return typeof t=="string"?e.document.createTextNode(t):t}function n(n){if(n.length===1)return t(n[0]);for(var r=e.document.createDocumentFragment(),i=v.call(n),s=0;s<n.length;s++)r.appendChild(t(i[s]));return r}for(var r=Object.defineProperty||function(e,t,n){e.__defineGetter__(t,n.get)},i=[].indexOf||function(t){var n=this.length;while(n--)if(this[n]===t)break;return n},s,o,u,a,f=/^\s+|\s+$/g,l=/\s+/,c=" ",h=function(t,n){if(this.contains(t))n||this.remove(t);else if(n===undefined||n)n=!0,this.add(t);return!!n},p=(e.Element||e.Node||e.HTMLElement).prototype,d=["matches",p.matchesSelector||p.webkitMatchesSelector||p.khtmlMatchesSelector||p.mozMatchesSelector||p.msMatchesSelector||p.oMatchesSelector||function(t){var n=this.parentNode;return!!n&&-1<i.call(n.querySelectorAll(t),this)},"prepend",function(){var t=this.firstChild,r=n(arguments);t?this.insertBefore(r,t):this.appendChild(r)},"append",function(){this.appendChild(n(arguments))},"before",function(){var t=this.parentNode;t&&t.insertBefore(n(arguments),this)},"after",function(){var t=this.parentNode,r=this.nextSibling,i=n(arguments);t&&(r?t.insertBefore(i,r):t.appendChild(i))},"replace",function(){var t=this.parentNode;t&&t.replaceChild(n(arguments),this)},"remove",function(){var t=this.parentNode;t&&t.removeChild(this)}],v=d.slice,m=d.length;m;m-=2)o=d[m-2],o in p||(p[o]=d[m-1]);"classList"in document.documentElement?(a=document.createElement("div").classList,a.add("a","b","a"),"a b"!=a&&(p=a.constructor.prototype,"add"in p||(p=e.DOMTokenList.prototype),u=function(e){return function(){var t=0;while(t<arguments.length)e.call(this,arguments[t++])}},p.add=u(p.add),p.remove=u(p.remove),p.toggle=h)):(u=function(e){if(!e)throw"SyntaxError";if(l.test(e))throw"InvalidCharacterError";return e},a=function(e){var t=e.className.replace(f,"");t.length&&d.push.apply(this,t.split(l)),this._=e},a.prototype={length:0,add:function(){for(var t=0,n;t<arguments.length;t++)n=arguments[t],this.contains(n)||d.push.call(this,o);this._.className=""+this},contains:function(e){return function(n){return (m=e.call(this,o=u(n)), -1<m)}}([].indexOf||function(e){m=this.length;while(m--&&this[m]!==e);return m}),item:function(t){return this[t]||null},remove:function(){for(var t=0,n;t<arguments.length;t++)n=arguments[t],this.contains(n)&&d.splice.call(this,m,1);this._.className=""+this},toggle:h,toString:function y(){return d.join.call(this,c)}},r(p,"classList",{get:function(){return new a(this)},set:function(){}})),"head"in document||r(document,"head",{get:function(){return s||(s=document.getElementsByTagName("head")[0])}});try{new e.CustomEvent("?")}catch(g){e.CustomEvent=function(e,t){function n(n,i){var s=document.createEvent(e);if(typeof n!="string")throw new Error("An event name must be provided");return (e == "Event" && (s.initCustomEvent = r), i == null && (i = t), s.initCustomEvent(n, i.bubbles, i.cancelable, i.detail), s)}function r(e,t,n,r){this.initEvent(e,t,n),this.detail=r}return n}(e.CustomEvent?"CustomEvent":"Event",{bubbles:!1,cancelable:!1,detail:null})}})(window);
});
require.register("webreflection/[email protected]", function (exports, module) {
module.exports = require("webreflection/[email protected]/build/dom4")
});
require.register("yuzujs/[email protected]/setImmediate", function (exports, module) {
(function (global, undefined) {
"use strict";
if (global.setImmediate) {
return;
}
var nextHandle = 1; // Spec says greater than zero
var tasksByHandle = {};
var currentlyRunningATask = false;
var doc = global.document;
var setImmediate;
function addFromSetImmediateArguments(args) {
tasksByHandle[nextHandle] = partiallyApplied.apply(undefined, args);
return nextHandle++;
}
// This function accepts the same arguments as setImmediate, but
// returns a function that requires no arguments.
function partiallyApplied(handler) {
var args = [].slice.call(arguments, 1);
return function() {
if (typeof handler === "function") {
handler.apply(undefined, args);
} else {
(new Function("" + handler))();
}
};
}
function runIfPresent(handle) {
// From the spec: "Wait until any invocations of this algorithm started before this one have completed."
// So if we're currently running a task, we'll need to delay this invocation.
if (currentlyRunningATask) {
// Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
// "too much recursion" error.
setTimeout(partiallyApplied(runIfPresent, handle), 0);
} else {
var task = tasksByHandle[handle];
if (task) {
currentlyRunningATask = true;
try {
task();
} finally {
clearImmediate(handle);
currentlyRunningATask = false;
}
}
}
}
function clearImmediate(handle) {
delete tasksByHandle[handle];
}
function installNextTickImplementation() {
setImmediate = function() {
var handle = addFromSetImmediateArguments(arguments);
process.nextTick(partiallyApplied(runIfPresent, handle));
return handle;
};
}
function canUsePostMessage() {
// The test against `importScripts` prevents this implementation from being installed inside a web worker,
// where `global.postMessage` means something completely different and can't be used for this purpose.
if (global.postMessage && !global.importScripts) {
var postMessageIsAsynchronous = true;
var oldOnMessage = global.onmessage;
global.onmessage = function() {
postMessageIsAsynchronous = false;
};
global.postMessage("", "*");
global.onmessage = oldOnMessage;
return postMessageIsAsynchronous;
}
}
function installPostMessageImplementation() {
// Installs an event handler on `global` for the `message` event: see
// * https://developer.mozilla.org/en/DOM/window.postMessage
// * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
var messagePrefix = "setImmediate$" + Math.random() + "$";
var onGlobalMessage = function(event) {
if (event.source === global &&
typeof event.data === "string" &&
event.data.indexOf(messagePrefix) === 0) {
runIfPresent(+event.data.slice(messagePrefix.length));
}
};
if (global.addEventListener) {
global.addEventListener("message", onGlobalMessage, false);
} else {
global.attachEvent("onmessage", onGlobalMessage);
}
setImmediate = function() {
var handle = addFromSetImmediateArguments(arguments);
global.postMessage(messagePrefix + handle, "*");
return handle;
};
}
function installMessageChannelImplementation() {
var channel = new MessageChannel();
channel.port1.onmessage = function(event) {
var handle = event.data;
runIfPresent(handle);
};
setImmediate = function() {
var handle = addFromSetImmediateArguments(arguments);
channel.port2.postMessage(handle);
return handle;
};
}
function installReadyStateChangeImplementation() {
var html = doc.documentElement;
setImmediate = function() {
var handle = addFromSetImmediateArguments(arguments);
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
var script = doc.createElement("script");
script.onreadystatechange = function () {
runIfPresent(handle);
script.onreadystatechange = null;
html.removeChild(script);
script = null;
};
html.appendChild(script);
return handle;
};
}
function installSetTimeoutImplementation() {
setImmediate = function() {
var handle = addFromSetImmediateArguments(arguments);
setTimeout(partiallyApplied(runIfPresent, handle), 0);
return handle;
};
}
// If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
// Don't get fooled by e.g. browserify environments.
if ({}.toString.call(global.process) === "[object process]") {
// For Node.js before 0.9
installNextTickImplementation();
} else if (canUsePostMessage()) {
// For non-IE10 modern browsers
installPostMessageImplementation();
} else if (global.MessageChannel) {
// For web workers, where supported
installMessageChannelImplementation();
} else if (doc && "onreadystatechange" in doc.createElement("script")) {
// For IE 6–8
installReadyStateChangeImplementation();
} else {
// For older browsers
installSetTimeoutImplementation();
}
attachTo.setImmediate = setImmediate;
attachTo.clearImmediate = clearImmediate;
}(new Function("return this")()));
});
require.register("yuzujs/[email protected]", function (exports, module) {
module.exports = require("yuzujs/[email protected]/setImmediate")
});
require.register("./client/permalinks", function (exports, module) {
document.queryAll('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]').forEach(function (h) {
var a = document.createElement('a')
a.href = '#' + h.id
a.textContent = '#'
a.className = 'header-permalink'
h.appendChild(a)
})
});
require.register("component/[email protected]", function (exports, module) {
/**
* Expose `requestAnimationFrame()`.
*/
exports = module.exports = window.requestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.oRequestAnimationFrame
|| window.msRequestAnimationFrame
|| fallback;
/**
* Fallback implementation.
*/
var prev = new Date().getTime();
function fallback(fn) {
var curr = new Date().getTime();
var ms = Math.max(0, 16 - (curr - prev));
var req = setTimeout(fn, ms);
prev = curr;
return req;
}
/**
* Cancel.
*/
var cancel = window.cancelAnimationFrame
|| window.webkitCancelAnimationFrame
|| window.mozCancelAnimationFrame
|| window.oCancelAnimationFrame
|| window.msCancelAnimationFrame
|| window.clearTimeout;
exports.cancel = function(id){
cancel.call(window, id);
};
});
require.register("component/[email protected]", function (exports, module) {
var raf = require("component/[email protected]")
module.exports = function (fn, immediate) {
var queued = false
// immediate by default
if (immediate !== false)
call()
return queue
function queue() {
if (queued)
return
queued = true
raf(call)
}
function call() {
fn()
queued = false
}
}
// normalize:common:info: rewriting dependency "raf" to "https://nlz.io/github/component/raf/*/index.js"
});
require.register("component/[email protected]", function (exports, module) {
function one(selector, el) {
return el.querySelector(selector);
}
exports = module.exports = function(selector, el){
el = el || document;
return one(selector, el);
};
exports.all = function(selector, el){
el = el || document;
return el.querySelectorAll(selector);
};
exports.engine = function(obj){
if (!obj.one) throw new Error('.one callback required');
if (!obj.all) throw new Error('.all callback required');
one = obj.one;
exports.all = obj.all;
return exports;
};
});
require.register("component/[email protected]", function (exports, module) {
/**
* Module dependencies.
*/
var query = require("component/[email protected]");
/**
* Element prototype.
*/
var proto = Element.prototype;
/**
* Vendor function.
*/
var vendor = proto.matches
|| proto.webkitMatchesSelector
|| proto.mozMatchesSelector
|| proto.msMatchesSelector
|| proto.oMatchesSelector;
/**
* Expose `match()`.
*/
module.exports = match;
/**
* Match `el` to `selector`.
*
* @param {Element} el
* @param {String} selector
* @return {Boolean}
* @api public
*/
function match(el, selector) {
if (!el || el.nodeType !== 1) return false;
if (vendor) return vendor.call(el, selector);
var nodes = query.all(selector, el.parentNode);
for (var i = 0; i < nodes.length; ++i) {
if (nodes[i] == el) return true;
}
return false;
}
// normalize:common:info: rewriting dependency "query" to "https://nlz.io/github/component/query/*/index.js"
});
require.register("component/[email protected]", function (exports, module) {
module.exports = function (selector, childSelector, sep) {
childSelector || (childSelector = '*')
sep || (sep = ' ')
return selector.split(',').map(function (x) {
return x + sep + childSelector
}).join(',')
}
});
require.register("discore/[email protected]", function (exports, module) {
var matches = require("component/[email protected]")
module.exports = function (element, selector, checkYoSelf, root) {
element = checkYoSelf ? {parentNode: element} : element
root = root || document
// Make sure `element !== document` and `element != null`
// otherwise we get an illegal invocation
while ((element = element.parentNode) && element !== document) {
if (matches(element, selector))
return element
// After `matches` on the edge case that
// the selector matches the root
// (when the root is not the document)
if (element === root)
return
}
}
// normalize:common:info: rewriting dependency "matches-selector" to "https://nlz.io/github/component/matches-selector/*/index.js"
});
require.register("component/[email protected]", function (exports, module) {
var cancelEvents = [
'touchmove',
'touchcancel',
'touchstart',
]
var endEvents = [
'touchend',
]
module.exports = Tap
function Tap(callback) {
// to keep track of the original listener
listener.handler = callback
return listener
// el.addEventListener('touchstart', listener)
function listener(e1) {
// tap should only happen with a single finger
if (!e1.touches || e1.touches.length > 1)
return
var el = this
cancelEvents.forEach(function (event) {
document.addEventListener(event, cleanup)
})
endEvents.forEach(function (event) {
document.addEventListener(event, done)
})
function done(e2) {
// since touchstart is added on the same tick
// and because of bubbling,
// it'll execute this on the same touchstart.
// this filters out the same touchstart event.
if (e1 === e2)
return
cleanup()
// already handled
if (e2.defaultPrevented)
return
var preventDefault = e1.preventDefault
var stopPropagation = e1.stopPropagation
e2.stopPropagation = function () {
stopPropagation.call(e1)
stopPropagation.call(e2)
}
e2.preventDefault = function () {
preventDefault.call(e1)
preventDefault.call(e2)
}
// calls the handler with the `end` event,
// but i don't think it matters.
callback.call(el, e2)
}
function cleanup(e2) {
if (e1 === e2)
return
cancelEvents.forEach(function (event) {
document.removeEventListener(event, cleanup)
})
endEvents.forEach(function (event) {
document.removeEventListener(event, done)
})
}
}
}
});
require.register("jonathanong/[email protected]", function (exports, module) {
var matches = require("component/[email protected]")
var context = require("component/[email protected]")
var closest = require("discore/[email protected]")
var query = require("component/[email protected]")
var tap = require("component/[email protected]")
module.exports = Eevee
/**
* We expose them, but they're private.
* Only reason I can think to expose them
* is to cleanup bad instances.
* Don't really want to add cleanup to this repo.
*/
// [id] = [element, eevee instance]
var instances = Eevee.instances = []
// [id][event][selector] = handlers[]
var Events = Eevee.events = []
// [id][event] = EventListeners()
var Listeners = Eevee.listeners = []
// Map handlers to their `tap`d form, if any
var Taphandlers = Eevee.taphandlers = []
// el {HTMLElement|String}
function Eevee(el) {
if (typeof el === 'string')
el = query(el)
if (!el)
throw new Error('No element supplied.')
if (!(this instanceof Eevee))
return new Eevee(el)
// find any
var instance
for (var i = 0, l = instances.length; i < l; i++)
if ((instance = instances[i])[0] === el)
return instance[1]
this.element = el
instances.push([el, this])
Events.push(this.events = {})
Listeners.push(this.listeners = {})
}
Eevee.prototype.on = function (events, selector, handler, capture) {
events = getEvents(events)
this[typeof selector === 'function' ? '_on' : '_onDelegate']
(events, selector, handler, capture)
return this
}
Eevee.prototype._on = function (events, handler, capture) {
events.forEach(function (event) {
if (event === 'tap') {
event = 'touchstart'
handler = getTapHandler(handler)
}
this.element.addEventListener(event, handler, useCapture(capture))
}, this)
}
Eevee.prototype._onDelegate = function (events, selector, handler) {
selector = getSelector(selector)
getEvents(events).forEach(function (event) {
if (event === 'tap') {
event = 'touchstart'
handler = getTapHandler(handler)
}
var selectorspace = this._addEventListener(event)
;(selectorspace[selector] || (selectorspace[selector] = []))
.push(handler)
}, this)
}
Eevee.prototype.off = function (events, selector, handler, capture) {
this[typeof selector === 'function' ? '_off' : '_offDelegate']
(events, selector, handler, capture)
return this
}
Eevee.prototype._off = function (events, handler, capture) {
capture = useCapture(capture)
getEvents(events).forEach(function (event) {
if (event === 'tap') {
event = 'touchstart'
handler = getTapHandler(handler)
}
this.element.removeEventListener(event, handler, capture)
}, this)
}
Eevee.prototype._offDelegate = function (events, selector, handler) {
// remove all delegated events
if (!events || !selector)
return this._removeEventListeners(events)
events = getEvents(events)
selector = getSelector(selector)
var eventspace = this.events
if (!handler) {
// Remove all the listeners on the given selector
events.forEach(function (event) {
if (event === 'tap')
event = 'touchstart'
var selectorspace = eventspace[event]
if (!selectorspace)
return
delete selectorspace[selector]
if (!Object.keys(selectorspace).length)
this._removeEventListeners(event)
}, this)
}
events.forEach(function (event) {
if (event === 'tap')
event = 'touchstart'
var selectorspace = eventspace[event]
if (!selectorspace)
return
var handlers = selectorspace[selector]
if (!handlers)
return
// Remove listeners, including possible duplicates
// We do not use `[].splice` since it would mess up `once`
handlers = handlers.filter(function (fn) {
if (fn === handler)
return false
if (!fn.fn)
return true
if (fn.fn === handler)
return false
if (fn.fn.fn === handler)
return false
return true
})
// Delete the entire selector if there are no listeners
if (!handlers.length)
delete selectorspace[selector]
// Replace the listeners otherwise
else
selectorspace[selector] = handlers
})
}
Eevee.prototype.once = function (events, selector, handler, capture) {
events = getEvents(events)
this[typeof selector === 'function' ? '_once' : '_onceDelegate']
(events, selector, handler, capture)
return this
}
Eevee.prototype._once = function (events, handler, capture) {
tempListener.fn = handler
capture = useCapture(capture)
var that = this.on(events, tempListener, capture)
return this
function tempListener(e) {
handler.call(this, e)
that.off(events, tempListener, capture)
}
}
Eevee.prototype._onceDelegate = function (events, selector, handler) {
tempListener.fn = handler
var that = this.on(events, selector, tempListener)
return this
function tempListener(e) {
handler.call(this, e)
that.off(events, selector, tempListener)
}
}
Eevee.prototype._addEventListener = function (event) {
var listeners = this.listeners