-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathm.html
1916 lines (1915 loc) · 90.1 KB
/
m.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>m².js - modular micro framework</title>
<meta http-equiv="x-ua-compatible" content="ie=edge"/>
<meta viewport="width=device-width"/>
<style>
html, body, * { font: 13px sans-serif; }
h1 { font-size: 250%; font-weight: 400; }
h2 { font-size: 125%; font-weight: 700; }
h3 { font-size: 120%; }
h4 { font-size: 110%; }
h5 { font-size: 100%; }
pre { padding: 20px; }
pre, pre * { font: 12px monospace; white-space: pre-wrap; tab-size: 4; }
/* syntax highlighting */
/* regexp */
.f-1, .f-1 * {color:#092;}
/* string */
.f1,.f1 * {color:#d14;}
/* comment */
.f2,.f2 * {color:#999;font-style:italic;}
/* keyword */
.f3,.f3 * {color:#000;font-weight: 700;}
/* predefined object */
.f4,.f4 * {color:#08B;}
/* number */
.f5,.f5 * {color:#099;}
/* bracket, operator */
.f6 {color:#000;}
</style>
<script type="text/javascript">
// m² 0.0.4 - modular JS micro framework (c) 2013-2014 by Alex Kloss
!function (doc, proto/**query-full**/, getElementsByTagName/**jsonp**/, script/**/, length, array/**cookie**/, cookie, escape/**query-full**/, regex/**/, undef) {
/*
Initialisation:
- instantiation with "new" if necessary
- DOM queries vs. other functions (handled via "i"nit method)
m([DOM query, Array, DOM node, onready callback function], [opt: DOM query base])
*/
m = function (query, base) { return this instanceof m ? '' + query === query ? /**query-html**//^<\w+.*>$/.test(query) ? (base = (base ? base.ownerDocument : doc).createElement('a'), base.innerHTML = query, m(base.childNodes)) : /**query-performance**/(!base && (base = /^#(\S+)$|^\[name=([^\]]+)\]$|^([a-zA-Z]+)$/.exec(query))) ? this.i(document['getElement' + (base[1] ? 'ById' : base[2] ? 'sByName' : 'sByTagName')](base[1] || base[2] || base[3])) :/**/m(base || doc).find(query) : /^f/.test(typeof query) ? m().ready(query/**elementready**/, base/**/) : this.i(query) : new m(query, base) }
m[proto] = {
// basic length
length: 0,
// initialisation for everything but functions or DOM queries
i: function (query, idx) {
query = !query ? [] : query.nodeName || query.window === query ? [query] : query
for (idx = 0; idx < query[length];) this[this[length]++] = query[idx++];
},
// DOMready
ready: function (func/**elementready**/, base/**/) { (function t(){ /**elementready**/(base ? m(base)[length] : /**//c/.test(doc.readyState)/**elementready**/)/**/ ? func() : setTimeout(t, 99) })() },
// Iterator
each: function (func) { return m.each(this, func) },
// Filtering m(...).filter([function returning either true to keep the node or something like an Array to replace it]), otherwise works as unique()
filter: function (filter, result) {
result = []
this.each(function (node, idx, check, ctr) {
check = !node || !filter || filter.call(node, node, idx);
check = check === true ? [node] : check && check[0] ? check : [];
for (ctr = 0; node = check[ctr++]; ~idx || result.push(node))
for (idx = result[length]; idx-- && node !== result[idx];);
})
return m(result)
},
// DOM (sub)query
find: function (query/**query-full**/, selected, nodes, base, dom, err/**/) { /**query-full**/
try {
/**/return this.filter(function (node){ return node.querySelectorAll(query) }) /**query-full**/
} catch (e) {
selected = m([]), base = this, dom = base.filter(m.s[' ']()), nodes = m(dom), regex.lastIndex = 0;
/*
CSS3 Selector RegExp (matches a-f)
a=[>~* +,] (traversal),
b=[[#.:[]""] (marker: id, class, attr, pseudo, tag if empty),
c=name,
d="(" for pseudo, comparison for attr,
e=attribute value
f=pseudo value
*/
(query+',').replace(regex, function (_, a, b, c, d, e, f) {
_ && (a == ',' ? (selected.i(nodes), nodes = m(dom)) : (a = m.s[b == ':' ? c : b || a || '']) ?
(a = a.call(nodes, f || c, d, e, base)) ? (nodes = nodes.filter(a)) : (err = 'filter call failed: ') : (err = 'no matching filter found: '))
if (err) throw err + _
})
return selected.filter()
}
/**/}/**events**/,
// DOM event binding
on: function (type, callback/**events-once**/, once/**events**/) {/**events-once**/
once && (callback.once = true);/**events-multi**/
if (/\s+/.test(type)) { type.replace(/\S+/, function(name){ this.on(name, callback, once) }); return this }/**events**/
return this.each(function (node, addEvent, trigger) {
node[trigger = '_trigger'] = node[trigger] || function() { m[proto].trigger.apply(node, arguments) }
type.replace(/\w+/g, function (name) { node['_' + name] ? node['_' + name].push(callback) : (node['_' + name] = [callback],
node[addEvent = 'addEventListener'] ? node[addEvent](name, node[trigger]) : node.attachEvent('on' + name, node[trigger])) });
})
},
// DOM event unbinding
off: function (type, callback) {/**events-multi**/
if (/\s+/.test(type)) { type.replace(/\S+/, function(name){ this.off(name, callback, once) }); return this }/**events**/
return this.each(function (node, removeEvent) {
type.replace(/\w+/g, function (name) { m.each(node['_' + name], function (func, idx, handler) { func == callback && handler.splice(idx,1) })
if (!(node['_' + name] || 0)[length]) node[removeEvent = 'removeEventListener'] ? node[removeEvent](name, node._trigger) : node.detachEvent('on' + name, node._trigger) })
})
},
// Event chain trigger
trigger: function (event, result) {
event = event || window.event;
event = event.type ? event : { type: event };
event.target || (event.target = event.srcElement);
return this instanceof m ? this.each(function(node){ m[proto].trigger.call(node, event) }) :
(m.each((node = this)['_'+event.type], function(callback){
result = callback.call(node, event) === false && result;/**events-once**/
callback.once && $(this).off(event.type, callback);/**events**/
}), !result)
}/**ins**/,
ins: function(reference, after, idx) {
reference = m(reference)[0];
if (after) {
for (idx = reference; (idx = idx.nextSibling) && idx.nodeType != 1;);
idx && (after = !(reference = idx))
}
if (after) return this.each(function() { reference.parentNode.appendChild(this) });
for (idx = this.length; idx--; reference.parentNode.insertBefore(this[idx], reference));
return this;
}/**ins-convenience**/,
before: function(reference) { return this.ins(reference) },
after: function(reference) { return this.ins(reference, true) }/**html**/,
// read/write HTML
html : function(html){ return html === undef ? this[0].innerHTML : this.each(function (node) { node.innerHTML = html }) }/**attr**/,
// get/set Attributes
attr: function(key, value){
if (value === undef && '' + key !== (key || '')) {
for (value in key) this.attr(value, key[value])
return this
}
return key && value !== undef ? this.each(function (node) { node.setAttribute(key, value), node[key] = value }) : this[0] ?
this[0][key] || (this[0].getAttribute && this[0].getAttribute(key)) || '' : ''
}/**css**/,
// get/set CSS attributes
css: function(key, value){
if (!value && '' + key !== (key || '')) {
for (value in key) this.css(value, key[value])
return this
}
return key && value ? this.each(function () { this.style[key] = value }) : this[0] ? this[0][value = 'currentStyle'] ? this[0][value][key] :
window.getComputedStyle(this[0])[key] || this[0].style[key] : ''
}/**class**/,
// has/add/remove/toggle class names (convenience functions below)
cls: function (action, name, has, search) {
action = action == 'has' ? 0 : action
search = eval('/\\b' + name + '\\b/g')
this.each(function (node, className, without, within) {
search.lastIndex = 0
without = node[className = 'className'].replace(search, '')
within = without != node[className]
has = has || within
action && (node[className] = (without + ({ add: 1, toggle: !within }[action] ? ' ' + name : '')).replace(/ +/g, ' '))
})
return action ? this : has
}/**value**/,
// get/set value
val: function (value) { return '' + value === value ? this.each(function (node) { node.value = value }) : this[0].value }/**selection**/,
/*
inspect/manipulate/create Selection
m(s).sel() - inspect Selection -> { start, end, length, text }
m(s).sel({ start: 0-n, end: 0-n, text: 'xy' }) -> create/manipulate selection
*/
sel: function (obj, node, createdRange, end, value) {
node = this[0]
value = 'value'
value in node || (value = 'innerText')
return node ? obj ? ((obj.text && (node[value] = node[value].substr(0, obj.start||0) + obj.text + node[value].substr((obj.start||0) +
(obj.end||node[value][length])))),
(obj.start && obj.end && (((createdRange = doc[createdRange='createRange'] ? doc[createdRange]() : doc.createTextRange())), createdRange.setStart ?
(createdRange.setStart(node, obj.start), createdRange.setEnd(node, obj.end)) : (createdRange.moveToElementText(node), createdRange.moveStart(obj.start),
createdRange.moveEnd(obj.end), createdRange.select())), this)) :
(obj = 'selection', createdRange = 1 + node[obj + 'End'] ? { start: node[obj + 'Start'], end: node[obj + 'End'] } :
(n.focus(), obj = doc[obj].createRange(), createdRange = node.createTextRange(), end = createdRange.duplicate(), end.moveToBookmark(obj.getBookmark()),
end.setEndPoint('EndToStart', createdRange), createdRange = { start: end.textcreatedRange[length], end: end.text[length] + obj.text[length] }),
createdRange.text = node[value].substr(createdRange.start, (createdRange[length] = createdRange.end - createdRange.start)), createdRange): {}
}/**position**/,
pos: function (offset) {
offset = function (node, x, y, html) { return node && node[html = 'getBoundingClientRect'] && (node = node[html](), html = document.documentElement) ?
{ left: (this.pageXOffset || html.scrollLeft) + node.left, top: (this.pageYOffset || html.scrollTop) + node.top } :
node ? offset(node.offsetParent, ~~x + ~~node.offsetLeft, ~~y + ~~node.offsetTop) : { left: x, top: y } }
return offset(this[0])
}/**ajax-full**/,
// convenient AJAX loading
load: function (url, nodes, callback) {
nodes = this,
callback = function (html) {
html = this.responseText
nodes.each(function (node) { node.innerHTML = html })
}
m.ajax(url.url ? (url.callback = callback, url) : { url: url, callback: callback })
}/**/,
// this makes most development consoles interpret the output as Array
splice: array.splice
}/**class-full**/
// class name convenience functions
'has add remove toggle'.replace(/\w+/g, function(action) {
if (action) m[proto][action + 'Class'] = function (name) { return this.cls(action, name) }
})/**query-full**/
// Selector functions: each returns a function that will be used to filter the output (re-use where possible and reasonable)
m.s = {
// CSS 1 selectors
'#': function (id) { return function (node) { return node.id == id } },
'.': function (classname) { return function (node) { return (' ' + node.className + ' ').indexOf(' ' + classname + ' ') > -1 } },
'': function (tagname) { return function (node) { return node.nodeName.toLowerCase() == tagname.toLowerCase() } },
'*': function () { return function (node) { return node[getElementsByTagName] && node[getElementsByTagName]('*') } }/**query-css2**/,
// CSS 2 selectors
'[': function (key, comparison, value, flags) {
value = comparison ? eval('/' + ({'|=': '\\b', '~=': '\\b', '=': '^', '!=': '^'}[comparison] || '') +
((value || '').replace(/[.+*()]/g, '\\$1') || '.+') +
({'|=': '(-|$)', '~=': '\\b', '=': '$', '!=': '$'}[comparison] || '') + '/' + (flags || '')) : /.+/;
return function(node){ return !!(value.test(node[key] || (typeof node.getAttribute == 'function' && node.getAttribute(key)) || '') ^ (comparison == '!=')) };
},
'>': function () { return function (nodes, result, idx) {
for (result = [], nodes = nodes.childNodes, idx = 0; nodes[idx]; idx++) nodes[idx].nodeType == 1 && result.push(nodes[idx]);
return result }
},
'+': function () { return function (node) { for (;node = node.nextSibling;) if ((node||0).nodeType == 1) return [node] } }/**query-css3**/,
// CSS 3 selectors
'~': function () { return function (node, result) {
for (result = []; node = node.nextSibling; node && node.nodeType == 1 && result.push(node));
return result }
},
'nth-of-type': function (count, sibling, idx, tagname, direction) {
count = ({ odd: '2n+1', even: '2n+0' }[count] || count).split(/n/),
idx = +count[0],
sibling = count[1],
direction = direction ? 'nextSibling' : 'previousSibling';
return function (node, count) {
for (node = this, count = 1; node = node[direction]; node.nodeType == 1 && (tagname == '*' || node.nodeName == this.nodeName) && count++);
return !(sibling ? (count - sibling) % idx : count - idx);
}
},
'nth-last-of-type': function (count) { return m.s['nth-of-type'](count, 0, 0, 0, 1) },
'nth-child': function (count) { return m.s['nth-of-type'](count, 0, 0, '*') },
'nth-last-child': function (count) { return m.s['nth-of-type'](count, 0, 0, '*', 1) },
'first-of-type': function (tagname) { return function(node){ return node.parentNode[getElementsByTagName](tagname == '*' ? tagname : node.nodeName)[0] == node } },
'last-of-type': function (tagname) { return function(node){
for (;(node = node.nextSibling||0);) if (node.nodeType == 1 && (tagname == '*' || (node.nodeName == this.nodeName))) return false;
return true;
} },
'only-of-type': function (tagname) { return function(node){ return node.parentNode[getElementsByTagName](tagname == '*' ? tagname : node.nodeName)[length] == 1 } },
'first-child': function () { return m.s['first-of-type']('*') },
'last-child': function () { return m.s['last-of-type']('*') },
'only-child': function () { return m.s['only-of-type']('*') },
empty: function () { return function (node) { return !node.childNodes[length] } },
target: function () { return this['[']('id', '=', /^#(.+)$/.test(location.hash) ? RegExp.$1 : '#') },
lang: function (lang) { return this['[']('lang', '|=', lang, 'i') },
enabled: function () { return function (node) { return node.disabled === false } },
disabled: function () { return function (node) { return !!node.disabled } },
checked: function () { return function (node) { return !!node.checked } },
not: function (negated, x, y, z, base) { return negated = m(negated, base), function (idx) { for (idx = 0; negated[idx];) if (negated[idx++] == this) return false; return true } },
root: function() { return function(node){ return node == doc.documentElement } },
has: function(query) { return function(node){ return m(node).find(query)[length] > 0 } },
contains: function (content, text, texts) {
text = function(node, texts){ return node ? (node.nodeType == 3 && texts.push(node.data), text(node.firstChild, texts), text(node.nextSibling, texts)) : texts }
return function(node) { return text(node.firstChild, texts = []).join('').indexOf(content) > -1 }
},
hidden: function (hidden) {return function (node, style) { return !!(!hidden ^ (!(node.offsetWidth * node.offsetHeight) ||
!((style = node.currentStyle || {}).visibility != 'hidden' || style.display != 'none'))) } },
visible: function () { return m.s.hidden() },
odd: function(odd) { return function(){ return (odd = !odd) } },
even: function(odd) { return function(){ return !(odd = !odd) } }/**query-extra**/,
// non-standard selectors
eq: function(idx) { idx |= 0; return function(){ return !idx-- } },
seq: function(seq) { seq = seq.split(','); return function(node, idx){ return idx >= seq[0] && (isNaN(seq[1]) || idx < seq[1]) } },
first: function() { return m.s.eq(0) },
last: function() { return m.s.eq(this[length]-1) },
gt: function(idx) { return m.s.seq(''+idx) },
lt: function(idx) { return m.s.seq('0,'+idx) }/**query-full**/
}
/**query-extra**/
// extra selectors
m.s[' '] = m.s['*']
'checkbox file image password radio reset submit text'.replace(/\w+/g, function (type) {
if (type) m.s[type] = function(){ return function(node) { return (node.type || '').toLowerCase() == type }}
});/**/
// Iterator: m.each([object/array], [callback])
m.each = function (obj, func, item) {
for (item in obj) (obj[length] + 1 ? isNaN(item) : !obj.hasOwnProperty(item)) || func.call(obj[item], obj[item], !isNaN(item) ? +item : item, obj);
return obj
}/**ajax**/
/* Ajax:
m.ajax({
url: '[required: url string]',
method: '[optional: get*|post|head]',
callback: [optional: function],
init: [optional, requires init: function],
header: [optional, requires header: function],
user: [optional: username string],
password: [optional: password string],
data: [optional: data string]
})
returns RequestObject for synchronous or asynchronous use (latter only if callback is specified)
*/
m.ajax = function (conf, xhr) {
xhr = /**ajax-ie6**/!window.XMLHttpRequest && window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : /**ajax**/new XMLHttpRequest()
xhr.open(conf.method || 'get', conf.url, !!(conf.callback && (xhr.onreadystatechange = /**ajax-ie6**/function(){/**ajax**/conf.callback/**ajax-ie6**/.call(xhr)}/**ajax**/)), conf.user, conf.password)/**ajax-init**/
conf.init && conf.init(xhr)/**ajax-header**/
m.each(conf.header||[], function(value, key) { xhr.setRequestHeader(key, value) })/**ajax**/
xhr.send(conf.data)
return xhr
}/**jsonp**/
/* JSONp:
m.jsonp({
url: '[required: url string]',
callback: [optional: callback function],
"_": '[optional: callback name - do not use unless you know what you are doing]'
})
*/
m.jsonp = function (conf, head, scripttag) {
head = doc.getElementsByTagName('head')[0],
scripttag = doc.createElement(script),
conf.callback && (window[conf._ = conf._ || script + (+new Date()+Math.floor((Math.random() * 10000) + 1))] = function(){
head.removeChild(scripttag);
conf.callback.apply(this, arguments);
window[conf._] = undef
}),
scripttag.src = conf.url.replace(/\??$/, conf._),
head.appendChild(scripttag)
return scripttag
}/**cookie**/
/* Cookie
m.cookie([required:cookie name string]) // returns cookie if set or ''
m.cookie({
name: '[required: cookie name string]',
value: '[required: cookie value string]',
date: [optional: Date() object or time in milliseconds until expiry],
domain: '[optional: domain string]',
path: '[optional: path string]',
extra: '[optional: extra string, e.g. "secure"]'
}) // sets cookie based on object
*/
m[cookie] = function (obj) {
if ('' + obj === obj)
return (eval('/(^|[ ;])'+escape(obj)+'=([^;]+)/')).test(doc[cookie]) && unescape(RegExp.$2);
obj && obj.name && obj.value && (doc[cookie] = escape(obj.name) + '=' + escape(obj.value) +
(obj.date ? ('; expires=' + (new Date(+obj.date === obj.date ? +new Date() + obj.date : obj.date)).toGMTString()) : '') +
(obj.domain ? ('; domain=' + obj.domain) : '') +
(obj.path ? '; path=' + obj.path : '') +
(obj.extra || '') + ';')
}/**url**/
/*
m.url('url-string') // -> URL-object (similar to location, but o.search[key] yields value, though o.search+'' yields the full string
*/
m.url = function (url, obj) {
url = (url || location.href).match(/^([^:\/\?#\.]*:?)(\/\/([^\/\?#:]*))?:?(\d*)(\.*\/[^?#]*)(\\?[^#]*)?(#.*)?$/)
obj = { toString: function () { return '' + obj.protocol + (obj.host != '' ? '\/\/' : '') + obj.host + obj.pathname + (obj.search ? '?' + obj.search : '') + obj.hash; },
search: { toString: function(result, tostring) {
result = [],
tostring = 'toString',
m.each(this, function(value, key){ (key || tostring) != tostring && result.push(key + '=' + value) })
return result.join('&')
} } }
'href protocol base hostname port pathname search hash'.replace(/\w+/g, function(key, value, r) {
value = url.shift() || ''
key != 'search' ? (obj[key] = value) : value.replace(/([^\?&=]+)=?([^&]*)?/g, function(_, item, data) { if (key) obj[key][unescape(item)] = unescape(data || '') })
})
obj.host = obj.hostname + (obj.port != '' ? ':' + obj.port : '');
if (obj.host.match(/^\.\.?$/)) obj.path = obj.host + obj.path, obj.host = '';
return obj;
}
m.each(m.url(), function(value, key){ m.url[key] = value })/**useragent**/
// useragent detection
m.ua = function (obj, browser, ie, version) {
obj = { ua: navigator.userAgent.toLowerCase(), info: {} },
browser = 'browser',
version = 'version',
obj.ua.replace(/[\(\)]/g, ';').replace(/\s*(\w*?\ ?\w+[\:\s]?[^\d\s;]*?)[\/\ ;](\d[.\w]*|)/g, function(_, key, value) { obj.info[key] = obj.info[key] || value || true; });
'msie1opr1firefox1seamonkey1aurora1iron1chrome1safari1opera1windows0windows nt0windows phone0windows rt0mac os0android0iphone0ipad0ipod0blackberry0rim0linux0'.replace(/(\D+)(\d)/g, function(node, name, digit) {
node = +digit ? browser : 'os'
obj.info[name] && (obj[node] = obj[node] || { name: name == 'opr' ? 'opera' : name == 'chrome' && +obj.info[version] == 1 ? 'native' : name, version: (+digit ? obj.info[version] : 0) || obj.info[name] },
obj[node][obj[node].name] = parseFloat(obj[node][version]) || obj[node][version])
});
(ie = +obj.info.trident + 4) && (obj[browser] = { name: 'msie', msie: ie, renderMode: obj.info.msie, version: ie });
;
return obj
}()/**/
}(
document,
'prototype'/**query-full**/,
'getElementsByTagName'/**jsonp**/,
'script'/**/,
'length',
[]/**cookie**/,
'cookie',
escape/**query-full**/,
/\s*([,>~* +])\s*|([#.:[]?)([0-9A-Za-z-_]+)(?:([*\|\~\^\$!]?=)([^\]]+)\]|\(([^)]*)\)|)/g/**/
);
</script>
<script>
window.startTime = +new Date();
window.readyTime = false;
window.loadTime = false;
m(function(){readyTime = +new Date()});
m(window).on('load', function(){loadTime=+new Date()});
</script>
</head>
<body>
<h1>m².js - modular micro framework</h1>
<p>Modular microframework © 2013-2014 Alex Kloss.</p>
<ul>
<li>2kb - 19.04kb commented/uncompressed</li>
<li>801b - 10.43kb bytes compressed using Google Closure Compiler*</li>
<li>492b - 4.33kb bytes compressed/gzipped using Google Closure Compiler*</li>
</ul>
<p>* WARNING: Google's Closure Compiler breaks stuff in advanced mode; also the resulting gzipped code is actually bigger in most cases.</p>
<h2>Features</h2>
<ul style="list-style: none">
<li><input type="checkbox" id="basic" value="on" disabled="disabled" style="display:none" checked/>Basic Framework: Main Object, <a href="#domevents">DOMready</a>, <a href="#iterator">Iterator</a>
<ul>
<li>Easily extendable</li>
<li>Minimal size</li>
<li>Simple usage through chaining, jQuery-like syntax</li>
<li>Variable Compatibility (depending on size/features)</li>
<li>Speaking variable names allow for easy understanding and adaption</li>
<li>Tests for most of the functionality</li>
<li>Licensed under GPLv2</li>
</ul>
</li>
<li><a href="#selectors" style="display:inline-block; float: left; height: 2.5em;">DOM Selection:</a> <label for="query-simple"><input type="radio" name="query" id="query-simple" value="simple" checked/> Simple (IE8+/querySelectorAll only)</label> <label for="query-performance"><input type="checkbox" name="query-performance" id="query-performance" value="on"> More performant (cross-browser-compatible) queries for id, name or tagname (does not require full query engine)</label><br/> <label for="query-full"><input type="radio" name="query" id="query-full" value="full"/> Full (all browsers, CSS1)</label> <label for="query-css2"><input type="checkbox" name="query-css2" id="query-css2" value="css2"/> CSS2</label> <label for="query-css3"><input type="checkbox" name="query-css3" id="query-css3" value="css2"/> CSS3</label> <label for="query-extra"><input type="checkbox" name="query-extra" id="query-extra" value="extra"/> non-standard CSS selectors</label></li>
<li><label for="query-html"><input type="checkbox" id="query-html" name="query-html" value="html"/> HTML queries (DOM generator)</label> <a href="#query-html">[doc]</a></li>
<li><a href="#domevents">DOM Events</a> <label for="no-events"><input type="radio" name="events" id="no-events" value="none"/> None</label> <label for="events-simple"><input type="radio" name="events" id="events-simple" value="simple"> DOM Events (simple)</label> <label for="events-multiple"><input type="checkbox" name="events-multiple" id="events-multiple" value="multiple"> multiple DOM Events</label> <label for="events-once"><input type="checkbox" name="events-once" id="events-once" value="once"> singular Events (run only once)</label></li>
<li><label for="elementready"><input type="checkbox" name="elementready" id="elementready" value="on"> ElementReady</label> <a href="#domevents">[doc]</a></li>
<li><a href="#insertion"> DOM insertion</a> <label for="no-ins"><input type="radio" name="ins" id="no-ins" value="none" checked/> None</label> <label for="ins"><input type="radio" name="ins" id="ins" value="simple"/> Simple</label> <label for="ins-convenience"><input type="radio" name="ins" id="ins-convenience" value="convenience"/> with convenience methods</label></li>
<li><label for="html"><input type="checkbox" name="html" id="html" value="on"> HTML inspection/manipulation</label> <a href="#manipulation">[doc]</a></li>
<li><label for="attr"><input type="checkbox" name="attr" id="attr" value="on"> DOM Attribute inspection/manipulation</label> <a href="#manipulation">[doc]</a></li>
<li><label for="css"><input type="checkbox" name="css" id="css" value="on"> CSS Attribute inspection/manipulation</label> <a href="#manipulation">[doc]</a></li>
<li> <a href="#manipulation">ClassName inspection/manipulation:</a> <label for="no-class"><input type="radio" name="class" id="no-class" value="none" checked/> None</label> <label for="class-simple"><input type="radio" name="class" id="class-simple" value="simple"/> Single Method m.cls('has|set|get|toggle', name, value)</label> <label for="class-full"><input type="radio" name="class" id="class-full" value="full"/> With convenience methods</label></li>
<li><label for="value"><input type="checkbox" name="value" id="value" value="on"> Form Value inspection/manipulation</label> <a href="#manipulation">[doc]</a></li>
<li><label for="selection"><input type="checkbox" name="selection" id="selection" value="on"> Selection inspection/manipulation</label> <a href="#manipulation">[doc]</a></li>
<li><label for="position"><input type="checkbox" name="position" id="position" value="on"> Position</label> <a href="#manipulation">[doc]</a></li>
<li><a href="#networking">AJAX:</a> <label for="no-ajax"><input type="radio" name="ajax" id="no-ajax" value="none" checked/> None</label> <label for="ajax-simple"><input type="radio" name="ajax" id="ajax-simple" value="simple"/> Simple</label> <label for="ajax-full"><input type="radio" name="ajax" id="ajax-full" value="full"/> With convenience loader</label> <label for="ajax-ie6"><input type="checkbox" name="ajax-ie6" id="ajax-ie6" value="on"/> MSIE6 Compatibility</label> <label for="ajax-init"><input type="checkbox" name="ajax-init" id="ajax-init" value="on"/> Init Callback</label> <label for="ajax-header"><input type="checkbox" name="ajax-header" id="ajax-header" value="on"/> Header Manipulation</label></li>
<li><label for="jsonp"><input type="checkbox" name="jsonp" id="jsonp" value="on"> JSONp</label> <a href="#networking">[doc]</a></li>
<li><label for="cookie"><input type="checkbox" name="cookie" id="cookie" value="on"> Cookies</label> <a href="#networking">[doc]</a></li>
<li><label for="url"><input type="checkbox" name="url" id="url" value="on"> URL</label> <a href="#networking">[doc]</a></li>
<li><label for="useragent"><input type="checkbox" name="useragent" id="useragent" value="on"> UserAgent</label> <a href="#client">[doc]</a></li>
</ul>
<button id="build">Build</button> <button id="full">Full</button> <button id="minimal">Minimal</button> <span id="length"></span>
<h2>Development Code</h2>
<pre id="devcode">[Code appears here]</pre>
<h2>Compiled Code</h2>
<pre id="livecode">[Code appears here]</pre>
<script type="text/javascript">
/* for debugging purposes on ie */
m.prototype.toString = function(r){
r = [];
this.each(function(n, i, t){
t = '<' + n.nodeName.toLowerCase();
'id class type name'.replace(/\w+/g, function(k) { t += m(n).attr(k) ? ' ' + k + '="' + m(n).attr(k) + '"' : '' });
r.push((i && (i % 10 == 0) ? '\n' : '') + t + '>');
})
return 'm('+this.length+')[' + r.join(', ') + ']';
}/**/
m(function(){
document.createElement('t');
var jsre = /(\B\/(?:\\.|[^\n/*])(?:\\.|[^\n/])*\/[gim]*)|("(?:\\.|\\\r*\n|[^\n"])*"|'(?:\\.|\\\r*\n|[^\n'])*')|(\/\/[^\n]*\n|\/\*[\x00-\xff\u00\uffff]*?\*\/)|\b(abstract|boolean|break|byte|case|catch|char|class|const|continue|debugger|default|delete|do|double|else|enum|export|extends|false|final|finally|float|for|function|goto|if|implements|import|in|instanceof|int|interface|long|native|new|null|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|var|void|volatile|while|with)\b|\b(Array|Boolean|Date|Function|Math|Number|Object|RegExp|String|document|window|arguments)\b|(\d[\d\.eE]*)|([\x28-\x2b\x2d\x3a-\x3f\x5b\x5d\x5e\x7b-\x7e]+|\x2f|\.(?=\D))/g,
jshighlight = function(c,r){return c.replace(r,function(f,i){for(i=7;~i*!arguments[i--];);return i?'<t class=f'+i+'>'+f.replace('<','<')+'</t>':''})},
jspreparemsie = function(d){return jshighlight(d.replace(/(['"])(.*?)\1/g,function(f,q,s){return q+s.replace(/&/g,'&')+q}),jsre).replace(/\n/g, '<br>').replace(/\t/g, ' ')},
jsprepare = function(d){return jshighlight(d.replace(/(['"])(.*?)\1/g,function(f,q,s){return q+s.replace(/&/g,'&')+q}),jsre)},
toKB = function(b){ return (b/1024).toFixed(2).replace(/0+$/, '') },
build = function(s, r){
s = '';
r = m('script').html().replace(/([^\0]*?)\/\*\*([\w-]*?)\**\//g, function(f, c, n) {
f = (!s || (s.replace(/\s+/g, '')) && m('[id^='+s+']:checked').length) ? c : '';
s = n;
return f
});
s = r.length+' bytes commented/uncompressed' + (r.length > 1024 ? ' (' + toKB(r.length) + 'kb)' : '')
m('#devcode').html((m.ua.browser.renderMode || m.ua.browser.msie) < 8 ? jspreparemsie(r) : jsprepare(r))
if (m.ua.browser.msie) {
r = { compiledCode: '/* CORS Request to Google\'s Closure Compiler REST service not supported by MSIE */' };
} else {
r = JSON.parse(m.ajax({url: 'http://closure-compiler.appspot.com/compile', method: 'post', header: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" }, data: 'js_code='+encodeURIComponent(r)+'&compilation_level=SIMPLE_OPTIMIZATIONS&output_format=json&output_info=compiled_code&output_info=statistics'}).responseText)
s += ', '+r.statistics.compressedSize+' bytes compressed'+(r.statistics.compressedSize > 1024 ? ' (' + toKB(r.statistics.compressedSize) + 'kb)' : '')+', ' + r.statistics.compressedGzipSize+' bytes compressed/gzipped'+(r.statistics.compressedGzipSize > 1024 ? ' (' + toKB(r.statistics.compressedGzipSize) + 'kb)' : '')
}
m('#length').html(s)
m('#livecode').html((m.ua.browser.renderMode || m.ua.browser.msie) < 8 ? jspreparemsie(r.compiledCode) : jsprepare(r.compiledCode))
};
m('#build').on('click', build);
m('#full').on('click', function(){ m('input').attr('checked', true) });
m('#minimal').on('click', function(c){
m('input:checkbox').attr('checked', false);
m('label:first-of-type :radio').attr('checked', true);
});
m('#ajax-init, #ajax-header').on('change', function(){
if (m('#ajax-init:checked, #ajax-header:checked').length > 0 &&
m('#ajax-simple:checked, #ajax-full:checked').length == 0) {
m('#ajax-simple').attr('checked', true);
}
});
m('#no-ajax').on('change', function(){
if (this.checked) { m('#ajax-init, #ajax-header').attr('checked', false) }
})
m('#query-css2, #query-css3, #query-extra').on('change', function(){
if (m('#query-css2:checked, #query-css3:checked, #query-extra:checked').length &&
m('#query-full:checked').length == 0) {
m('#query-full').attr('checked', true)
}
})
m('#query-simple').on('change', function(){
if (this.checked) { m('#query-css2, #query-css3, #query-extra').attr('checked', false) }
})
});
//m(function(){console.log('iterator ready')}, '#iterator');
</script>
<h2>TODO</h2>
<ul>
<li>More/Improved Documentation</li>
<li>Test Suite for pos, sel?</li>
<li>Additional functionality (as modules)
<ul>
<li>serialize (as optional part of (.val)?)</li>
<li>.live() Events</li>
<li>.post() requests</li>
<li>.route</li>
<li>.render (Templates)</li>
<li>?</li>
</ul>
</li>
<li>Improved (more beautiful) code
<ul>
<li>m().sel - IE Fallback (modularity?)</li>
</ul>
</li>
<li>Cheat Sheet</li>
</ul>
<h2>Functionality</h2>
<style>
#functionality { margin: 0; padding: 0; }
#functionality li { font-size: 13px; }
#functionality label { background: #FFFFFF; border: 1px solid #DDDDDD; cursor: pointer; }
#selectors, #domevents, #manipulation, #insertion, #iterator, #networking, #client { display: block; margin: 0; padding: 0 1em 1em; overflow: hidden; border-bottom: 4px solid #FFFFFF; }
#selectors { background: #FFBBBB; }
#selectors > ul > li { float: left; }
#pseudoattributes { width: 40em; }
#pseudoattributes li { float: left; width: 12em; }
#domevents { background: #FFDDBB; }
#insertion { background: #FFFFBB;}
#manipulation { background: #DDFFBB; }
#manipulation > ul > li { float: left; margin-right: 3em; }
#iterator { background: #BBDDDD; }
#networking { background: #BBDDFF; }
#networking > ul > li { float: left; margin-right: 3em; }
#client { background: #DDDDFF; }
</style>
<ul id="functionality">
<li id="selectors">
<h3>m(s), m(s, b), m(n).find(s) - Selectors</h3>
<h4><label for="selector-simple">Simple DOM Selection</label></h4>
<p>Simple DOM Selection is solely based on <a href="http://www.w3.org/TR/selectors-api/#queryselectorall" target="_blank">querySelectorAll()</a>, which is <a href="http://caniuse.com/queryselector" target="_blank">not supported on some obsolete browsers</a> and may not provide all possible selectors.
<h4><label for="selector-full">Full DOM Selection</label></h4>
<ul>
<li>
<h5>Basic/Traversing</h5>
<ul>
<li>body - tag name</li>
<li>#id - id</li>
<li>.class - class name</li>
<li>* - Everything</li>
<li>> - Direct Childs</li>
<li>~ - Siblings</li>
<li>+ - Next</li>
<li>, - Multiple Selections</li>
</ul>
</li>
<li>
<h5>Attributes</h5>
<ul>
<li>[attr] - attribute presence</li>
<li>[attr=value] - attribute value</li>
<li>[attr!=value] - attribute negation</li>
<li>[attr^=value] - attribute start</li>
<li>[attr$=value] - attribute end</li>
<li>[attr*=value] - attribute part</li>
<li>[attr~=value] - Separate attribute part</li>
<li>[attr|=value] - attribute subpart before -</li>
</ul>
</li>
<li id="pseudoattributes">
<h5>Pseudo Attributes</h5>
<ul>
<li>:first-child, :first</li>
<li>:nth-child(2n+1)</li>
<li>:nth-of-type(odd)</li>
<li>:odd</li>
<li>:even</li>
<li>:eq(7)</li>
<li>:last-child, :last</li>
<li>:nth-last-child(even)</li>
<li>:nth-last-of-type(3)</li>
<li>:only-child</li>
<li>:only-of-type</li>
<li>:seq(2,5)</li>
<li>:gt(2)</li>
<li>:lt(5)</li>
<li>:empty</li>
<li>:target</li>
<li>:lang(en)</li>
<li>:enabled</li>
<li>:disabled</li>
<li>:checked</li>
<li>:not([simple selector])</li>
<li>:root</li>
<li>:has([simple selector])</li>
<li>:contains(text)</li>
<li>:hidden</li>
<li>:visible</li>
<li>:checkbox</li>
<li>:file</li>
<li>:image</li>
<li>:password</li>
<li>:radio</li>
<li>:reset</li>
<li>:submit</li>
<li>:text</li>
</ul>
</li>
</ul>
</li>
<li id="domevents">
<h3>m(f), m(s).on(t, f), m(s).off(t, f) - Events</h3>
<ul>
<li>m(f) - DOMready (basic)</li>
<li>m(f, s) - <label for="elementready">ElementReady</label></li>
<li>m(s).on(t, f) - Bind DOM Event*</li>
<li>m(s).off(t, f) - Unbind DOM Event*</li>
<li>m(s).trigger(t) - Trigger Event Chain</li>
</ul>
<p>* requires <label for="events">DOM Events</label></p>
</li>
<li id="insertion">
<h3>m(s).ins, m(s).before, m(s).after - Insertion*</h3>
<ul>
<li>m(s).ins(referenceNode, after) - insert Node Collection before/after referenceNode</li>
<li>m(s).before(referenceNode) - convenience call</li>
<li>m(s).after(referenceNode) - convenience call</li>
</ul>
<p>* requires <label for="ins">DOM Insertion</label> or <label for="ins-convenience">Convenience Calls for DOM Insertion</label></p>
</li>
<li id="manipulation">
<h3>m(s).attr|css|html|cls|val - Manipulation/Inspection</h3>
<ul>
<li>
<h4><label for="attr">m(s).attr - DOM Attributes</label></h4>
<ul>
<li>m(s).attr('name')</li>
<li>m(s).attr('name', value)</li>
<li>m(s).attr({name: 'value'})</li>
</ul>
</li>
<li>
<h4><label for="css">m(s).css - CSS Attributes</label></h4>
<ul>
<li>m(s).css('name')</li>
<li>m(s).css('name', value)</li>
<li>m(s).css({name: 'value'})</li>
</ul>
</li>
<li>
<h4><label for="html">m(s).html - HTML Content</label></h4>
<ul>
<li>m(s).html()</li>
<li>m(s).html('<html code>')</li>
</ul>
</li>
<li>
<h4><label for="class-simple">m(s).cls - ClassName</label></h4>
<ul>
<li>m(s).cls('has|set|remove|toggle', 'name', 'opt:value')</li>
<li>m(s).hasClass('name')**</li>
<li>m(s).addClass('name')**</li>
<li>m(s).removeClass('name')**</li>
<li>m(s).toggleClass('name')**</li>
</ul>
<p>** Convenience Methods provided by <label for="class-full">additional module</label></p>
</li>
<li>
<h4><label for="value">m(s).val(), m(s).val(v) - Value</label></h4>
<ul>
<li>m(s).val() - gets value of the first selected node</li>
<li>m(s).val(v) - sets value of every field</li>
</ul>
</li>
<li>
<h4><label for="selection">m(s).sel(), m(s).sel(o) - Selection</label></h4>
<ul>
<li>m(s).sel() - gets selection object</li>
<li>m(s).sel(o) - create/manipulate selection depending on object (length ignored)</li>
</ul>
<h5>Selection Object</h5>
<ul>
<li>start - start of selection (beginning at 0)</li>
<li>end - end of selection</li>
<li>length - length of selection</li>
<li>text - selected text (or replacement)</li>
</ul>
<input type="text" id="selectiontest" />
<span id="selectionview"></span>
<script type="text/javascript">
(function(s){
m('#selectiontest').on('mousedown', function(e) { s = 1 }).on('mouseup', function () { s = 0 }).on('mousemove', function(e) {
if (!s) return;
e = m('#selectiontest').sel()
m('#selectionview').html(e.start + '-' + e.end + ': "' + e.text + '"')
}).on('keyup', function(e){
e = m('#selectiontest').sel()
m('#selectionview').html(e.start + '-' + e.end + ': "' + e.text + '"')
})
})()
</script>
</li>
<li><h4><label for="position">m(s).pos() - Position</label></h4>
<p>m(s).pos() // returns position object</p>
<h5>Position Object</h5>
<ul>
<li>.left - horizontal position in pixels</li>
<li>.top - vertical position in pixels</li>
</ul>
<p>Position coordinates may be floating point numbers</p>
</li>
</ul>
</li>
<li id="iterator">
<h3>m.each(o, f), m(s).each(f), m(s).filter(f) - Iterator</h3>
<ul>
<li>m.each({key, value}, function(value, key){ /* this == value */ })</li>
<li>m.each([1, 2, 3], function(value, key){ /* this == value */ })</li>
<li>m(s).each(function(node, idx){ /* this == node */ })</li>
<li>m(s).filter(function(node, idx){ return true || NodeCollection })</li>
</ul>
</li>
<li id="networking">
<h3>m.ajax(o), m.jsonp(o), m.cookie(o), m.url(o) - Networking/Server</h3>
<ul>
<li>
<h4><label for="ajax-simple">m.ajax(o)</label></h4>
m.ajax({configuration object}) - yields AJAX Request object
<h5>Configuration Object</h5>
<ul>
<li>url (required): Request URL</li>
<li>method (optional): [get]|head|post</li>
<li>callback (optional): called on readyStateChange, makes request async</li>
<li>user (optional): username for HTTP/Auth</li>
<li>password (optional): password for HTTP/Auth</li>
<li>data (optional): data for POST request</li>
<li>init (optional, requires <label for="ajax-init">AJAX init</label>): init callback</li>
<li>header (optional, requires <label for="ajax-header">AJAX header</label>): header object</li>
</ul>
<br/>m(s).load(url), m(s).load(obj) - <label for="ajax-full">Convenience loader</label>; callback not supported.
</li>
<li>
<h4><label for="jsonp">m.jsonp(o)</label></h4>
m.jsonp({configuration object}) - yields script tag for JSONp-Request
<h5>Configuration Object</h5>
<ul>
<li>url (required): Request URL, "?" at the end will be replaced with callback name</li>
<li>callback (optional): will be called from JSONp-Request</li>
<li>_ (optional): callback name, if it needs to be pre-defined</li>
</ul>
</li>
<li>
<h4><label for="cookies">m.cookie(o)</label></h4>
m.cookie(name) - returns cookie value<br/>
m.cookie({cookie object})
<h5>Cookie Object</h5>
<ul>
<li>name (required): Cookie name</li>
<li>value (required): Cookie value</li>
<li>date (optional): Date() object or time in milliseconds until expiry</li>
<li>domain (optional): domain string</li>
<li>path (optional): path string</li>
<li>extra (optional): extra string, e.g. "secure"</li>
</ul>
</li>
<li>
<h4><label for="url">m.url(u)</label></h4>
m.url("URL string") - returns URL object<br/>
m.url.hostname - m.url serves as the page's URL object, too
<h5>URL Object</h5>
The URL Object is rather similar to window.location, the main differences is the url.search (which will perform as an key-value storage for everything in its search, but yield an URI-Encoded string if coerced)
</li>
</ul>
</li>
<li id="client">
<h3><label for="useragent">m.ua - Browser/OS</label></h3>
m.ua.
<ul>
<li>
browser.
<ul>
<li>name: <script type="text/javascript">document.write(m.ua.browser.name);</script></li>
<li>version: <script type="text/javascript">document.write(m.ua.browser.version);</script></li>
<li><script type="text/javascript">document.write(m.ua.browser.name);</script>: <script type="text/javascript">document.write(m.ua.browser[m.ua.browser.name]);</script></li>
<script type="text/javascript">if (m.ua.browser.renderMode) document.write('<li>renderMode: '+m.ua.browser.renderMode+'</li>');</script>
</ul>
</li>
<li>
os.
<ul>
<li>name: <script type="text/javascript">document.write(m.ua.os.name);</script></li>
<li>version: <script type="text/javascript">document.write(m.ua.os.version);</script></li>
<li><script type="text/javascript">document.write(m.ua.os.name);</script>: <script type="text/javascript">document.write(m.ua.os[m.ua.os.name]);</script></li>
</ul>
</li>
<li>info: Hash aller weiteren UA-Eigenschaften (key=value oder key=true)</li>
<li>ua: navigator.userAgent.toLowerCase() // <script type="text/javascript">document.write(m.ua.ua);</script></li>
</ul>
</li>
</ul>
<h2>Compatibility (if restricted)</h2>
<ul>
<li>Selectors:
<ul>
<li>Basic: IE8+, FF3.5+, Chrome, Safari, Opera10+, iOS, Android</li>
<li>Full: IE6+, FF2+, Chrome, Safari, Opera9+, iOS, Android</li>
</ul>
</li>
<li>AJAX: IE6+ (with compatibility module), otherwise IE7+, FF, Chrome, Safari, Opera, iOS, Android</li>
<li>Everything else: IE6+, FF, Chrome, Safari, Opera, iOS, Android</li>
</ul>
<h2>Tests</h2>
<style>
#testresults p { margin: 0; padding: 0; }
</style>
<div id="testresults"></div>
<button id="run">Run</button>
<script type="text/javascript">
(function(){
var now = window.startTime, ready = window.readyTime, load,
testfilter = function(filter, obj, args) {
if (typeof obj == 'string') {
var div = document.createElement('div');
div.innerHTML = obj;
if (args) args[4] = div, filter = filter.apply(m.s, args);
obj = m(div.getElementsByTagName('*'))
} else {
if (args) args[4] = obj, filter = filter.apply(m.s, args);
}
return m.prototype.filter.call(obj, filter);
},
tests = [
{
description: '<h3>Iterator/Filter tests</h3>'
},
{
description: 'array iterator',
run: function(r, c){
c = [1,2,3],
r = '';
m.each(c, function(n, i){
if (!n) r += ' ERROR: empty/false element';
if (n != this) r += ' ERROR: this/arg[0] differ';
if (!(i in c)) r += ' ERROR: wrong index';
if (+n !== n || n < 0 || n > 3) r += ' ERROR: element outside array';
if (i + 1 != n) r += ' ERROR: element/index mismatch: '+i+'→'+n;
}) == c || (r += ' ERROR: wrong/missing return value');
return r || true;
}
},
{
description: 'object iterator',
run: function(r, c){
c = { a: 1, b: 2, c: 3 },
r = '';
m.each(c, function(n, i){
if (!n) r += ' ERROR: empty/false element';
if (n != this) r += ' ERROR: this/arg[0] differ';
if (!(i in c) || !/[abc]/.test(i)) r += ' ERROR: wrong index';
if (+n !== n || n < 0 || n > 3) r += ' ERROR: element outside object';
if (parseInt(i, 36) - 9 != n) r += ' ERROR: element/index mismatch';
}) == c || (r += ' ERROR: wrong/missing return value');
return r || true;
}
},
{
description: 'selection iterator',
run: function(r, c){
c = document.createElement('div'),
r = '';
c.innerHTML = '<span><\/span><i><\/i><img/><div><\/div>';
c = m('*', c);
c.each(function(n, i){
if (!n) r += ' ERROR: empty/false element';
if (n != this) r += ' ERROR: this/arg[0] differ';
if (+i !== i || i < 0 || i > 3) r += ' ERROR: element outside object';
if (i == 0 && n.nodeName.toLowerCase() != 'span') r += ' ERROR: element/index mismatch';
if (i == 1 && n.nodeName.toLowerCase() != 'i') r += ' ERROR: element/index mismatch';
if (i == 2 && n.nodeName.toLowerCase() != 'img') r += ' ERROR: element/index mismatch';
if (i == 3 && n.nodeName.toLowerCase() != 'div') r += ' ERROR: element/index mismatch';
}) == c || (r += ' ERROR: wrong/missing return value');
return r || true;
}
},
{
description: 'selection filter',
run: function(r, c){
c = document.createElement('div'),
r = '';
c.innerHTML = '<span><\/span><i><\/i><img/><div><\/div>';
c = m('*', c);
c.filter(function(n, i){
if (!n) r += ' ERROR: empty/false element';
if (n != this) r += ' ERROR: this/arg[0] differ';
if (+i !== i || i < 0 || i > 3) r += ' ERROR: element outside object';
if (i == 0 && n.nodeName.toLowerCase() != 'span') r += ' ERROR: element/index mismatch';
if (i == 1 && n.nodeName.toLowerCase() != 'i') r += ' ERROR: element/index mismatch';
if (i == 2 && n.nodeName.toLowerCase() != 'img') r += ' ERROR: element/index mismatch';
if (i == 3 && n.nodeName.toLowerCase() != 'div') r += ' ERROR: element/index mismatch';
return i == 2;
}).length == 1 || (r += ' ERROR: wrong/missing return value');
return r || true;
}
},
{
description: '<h3>Selector filter tests</h3>'
},
{
description: 'tagname filter',
run: function(r, n){
r = '';
n = testfilter(m.s['']('li'), '<span><\/span><div><\/div><ul><li><\/li><\/ul><a><\/a><img/>');
if (!n) r += ' ERROR: empty result';
if (n.length != 1) r += ' ERROR: wrong number of matched elements: '+n.length;
if (((n[0] || 0).nodeName || '').toLowerCase() != 'li') r += ' ERROR: wrong element matched'
return r || true
}
},
{
description: 'id filter',
run: function(r, n){
r = '';
n = testfilter(m.s['#']('test'), '<span><\/span><div id="test"><\/div><ul><li><\/li><\/ul><a><\/a><img/>');
if (!n) r += ' ERROR: empty result';
if (n.length != 1) r += ' ERROR: wrong number of matched elements '+n.length;
if (((n[0] || 0).nodeName || '').toLowerCase() != 'div') r += ' ERROR: wrong element matched'
return r || true
}
},
{
description: 'class name filter',
run: function(r, n){
r = '';
n = testfilter(m.s['.']('test'), '<span><\/span><div class="test"><\/div><ul><li class="test"><\/li><\/ul><a><\/a><img/>');
if (!n) r += ' ERROR: empty result';
if (n.length != 2) r += ' ERROR: wrong number of matched elements';
if (((n[0] || 0).nodeName || '').toLowerCase() != 'div') r += ' ERROR: wrong element matched'
if (((n[1] || 0).nodeName || '').toLowerCase() != 'li') r += ' ERROR: wrong element matched'
return r || true
}
},
{
description: 'recursive child filter',
run: function(r, n){
r = '';
n = testfilter(m.s['*'](), '<div><span><\/span><div class="test"><\/div><ul><li class="test"><\/li><\/ul><a><\/a><img/></div>');
if (!n) r += ' ERROR: empty result';
if (n.length != 6) r += ' ERROR: wrong number of matched elements';
if (((n[0] || 0).nodeName || '').toLowerCase() != 'span') r += ' ERROR: wrong element matched'
if (((n[1] || 0).nodeName || '').toLowerCase() != 'div') r += ' ERROR: wrong element matched'
if (((n[2] || 0).nodeName || '').toLowerCase() != 'ul') r += ' ERROR: wrong element matched'
if (((n[3] || 0).nodeName || '').toLowerCase() != 'li') r += ' ERROR: wrong element matched'
if (((n[4] || 0).nodeName || '').toLowerCase() != 'a') r += ' ERROR: wrong element matched'
if (((n[5] || 0).nodeName || '').toLowerCase() != 'img') r += ' ERROR: wrong element matched'
return r || true
}
},
{
description: 'direct child filter',
run: function(r, n){
r = '';
n = testfilter(m.s['>'](), '<span><\/span><div class="test"><\/div><ul><li class="test"><\/li><\/ul><a><\/a><img/>');
if (!n) r += ' ERROR: empty result';
if (n.length != 1) r += ' ERROR: wrong number of matched elements';
if (((n[0] || 0).nodeName || '').toLowerCase() != 'li') r += ' ERROR: wrong element matched'
return r || true
}
},
{
description: 'sibling filter',
run: function(res, n){
res = '';
n = testfilter(m.s['~'](), '<span><\/span><div class="test"><\/div><ul><li class="test"><\/li><\/ul><a><\/a><img/>');
if (!n) res += ' ERROR: empty result';
if (n.length != 4) res += ' ERROR: wrong number of matched elements';
if (((n[0] || 0).nodeName || '').toLowerCase() != 'div') res += ' ERROR: wrong element matched'
if (((n[1] || 0).nodeName || '').toLowerCase() != 'ul') res += ' ERROR: wrong element matched'
if (((n[2] || 0).nodeName || '').toLowerCase() != 'a') res += ' ERROR: wrong element matched'
if (((n[3] || 0).nodeName || '').toLowerCase() != 'img') res += ' ERROR: wrong element matched'
return res || true
}
},
{