author | Mahlon E. Smith <mahlon@martini.nu> |
Mon, 09 Feb 2015 09:20:01 -0800 | |
changeset 0 | 52d30e6014a0 |
permissions | -rw-r--r-- |
0
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1 |
/*! |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2 |
* CanJS - 2.1.1 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3 |
* http://canjs.us/ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4 |
* Copyright (c) 2014 Bitovi |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5 |
* Fri, 23 May 2014 15:47:45 GMT |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6 |
* Licensed MIT |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7 |
* Includes: can/construct/construct.js,can/map/map.js,can/list/list.js,can/compute/compute.js,can/model/model.js,can/view/view.js,can/control/control.js,can/route/route.js,can/control/route/route.js,can/view/ejs/ejs.js,can/map/backup/backup.js,can/util/object/object.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
8 |
* Download from: http://bitbuilder.herokuapp.com/can.custom.js?configuration=jquery&plugins=can%2Fconstruct%2Fconstruct.js&plugins=can%2Fmap%2Fmap.js&plugins=can%2Flist%2Flist.js&plugins=can%2Fcompute%2Fcompute.js&plugins=can%2Fmodel%2Fmodel.js&plugins=can%2Fview%2Fview.js&plugins=can%2Fcontrol%2Fcontrol.js&plugins=can%2Froute%2Froute.js&plugins=can%2Fcontrol%2Froute%2Froute.js&plugins=can%2Fview%2Fejs%2Fejs.js&plugins=can%2Fmap%2Fbackup%2Fbackup.js&plugins=can%2Futil%2Fobject%2Fobject.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
9 |
*/ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
10 |
(function(undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
11 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
12 |
// ## can/util/can.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
13 |
var __m5 = (function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
14 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
15 |
var can = window.can || {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
16 |
if (typeof GLOBALCAN === 'undefined' || GLOBALCAN !== false) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
17 |
window.can = can; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
18 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
19 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
20 |
// An empty function useful for where you need a dummy callback. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
21 |
can.k = function() {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
22 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
23 |
can.isDeferred = function(obj) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
24 |
var isFunction = this.isFunction; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
25 |
// Returns `true` if something looks like a deferred. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
26 |
return obj && isFunction(obj.then) && isFunction(obj.pipe); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
27 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
28 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
29 |
var cid = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
30 |
can.cid = function(object, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
31 |
if (!object._cid) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
32 |
cid++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
33 |
object._cid = (name || '') + cid; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
34 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
35 |
return object._cid; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
36 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
37 |
can.VERSION = '@EDGE'; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
38 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
39 |
can.simpleExtend = function(d, s) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
40 |
for (var prop in s) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
41 |
d[prop] = s[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
42 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
43 |
return d; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
44 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
45 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
46 |
can.frag = function(item) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
47 |
var frag; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
48 |
if (!item || typeof item === "string") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
49 |
frag = can.buildFragment(item == null ? "" : "" + item, document.body); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
50 |
// If we have an empty frag... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
51 |
if (!frag.childNodes.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
52 |
frag.appendChild(document.createTextNode('')); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
53 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
54 |
return frag; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
55 |
} else if (item.nodeType === 11) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
56 |
return item; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
57 |
} else if (typeof item.nodeType === "number") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
58 |
frag = document.createDocumentFragment(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
59 |
frag.appendChild(item); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
60 |
return frag; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
61 |
} else if (typeof item.length === "number") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
62 |
frag = document.createDocumentFragment(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
63 |
can.each(item, function(item) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
64 |
frag.appendChild(can.frag(item)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
65 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
66 |
return frag; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
67 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
68 |
frag = can.buildFragment("" + item, document.body); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
69 |
// If we have an empty frag... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
70 |
if (!frag.childNodes.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
71 |
frag.appendChild(document.createTextNode('')); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
72 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
73 |
return frag; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
74 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
75 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
76 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
77 |
// this is here in case can.compute hasn't loaded |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
78 |
can.__reading = function() {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
79 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
80 |
return can; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
81 |
})(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
82 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
83 |
// ## can/util/attr/attr.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
84 |
var __m6 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
85 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
86 |
// Acts as a polyfill for setImmediate which only works in IE 10+. Needed to make |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
87 |
// the triggering of `attributes` event async. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
88 |
var setImmediate = window.setImmediate || function(cb) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
89 |
return setTimeout(cb, 0); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
90 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
91 |
attr = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
92 |
// This property lets us know if the browser supports mutation observers. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
93 |
// If they are supported then that will be setup in can/util/jquery and those native events will be used to inform observers of attribute changes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
94 |
// Otherwise this module handles triggering an `attributes` event on the element. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
95 |
MutationObserver: window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
96 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
97 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
98 |
map: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
99 |
"class": "className", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
100 |
"value": "value", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
101 |
"innerText": "innerText", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
102 |
"textContent": "textContent", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
103 |
"checked": true, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
104 |
"disabled": true, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
105 |
"readonly": true, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
106 |
"required": true, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
107 |
// For the `src` attribute we are using a setter function to prevent values such as an empty string or null from being set. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
108 |
// An `img` tag attempts to fetch the `src` when it is set, so we need to prevent that from happening by removing the attribute instead. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
109 |
src: function(el, val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
110 |
if (val == null || val === "") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
111 |
el.removeAttribute("src"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
112 |
return null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
113 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
114 |
el.setAttribute("src", val); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
115 |
return val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
116 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
117 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
118 |
style: function(el, val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
119 |
return el.style.cssText = val || ""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
120 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
121 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
122 |
// These are elements whos default value we should set. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
123 |
defaultValue: ["input", "textarea"], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
124 |
// ## attr.set |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
125 |
// Set the value an attribute on an element. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
126 |
set: function(el, attrName, val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
127 |
var oldValue; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
128 |
// In order to later trigger an event we need to compare the new value to the old value, so here we go ahead and retrieve the old value for browsers that don't have native MutationObservers. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
129 |
if (!attr.MutationObserver) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
130 |
oldValue = attr.get(el, attrName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
131 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
132 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
133 |
var tagName = el.nodeName.toString() |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
134 |
.toLowerCase(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
135 |
prop = attr.map[attrName], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
136 |
newValue; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
137 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
138 |
// Using the property of `attr.map`, go through and check if the property is a function, and if so call it. Then check if the property is `true`, and if so set the value to `true`, also making sure to set `defaultChecked` to `true` for elements of `attr.defaultValue`. We always set the value to true because for these boolean properties, setting them to false would be the same as removing the attribute. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
139 |
// For all other attributes use `setAttribute` to set the new value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
140 |
if (typeof prop === "function") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
141 |
newValue = prop(el, val); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
142 |
} else if (prop === true) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
143 |
newValue = el[attrName] = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
144 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
145 |
if (attrName === "checked" && el.type === "radio") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
146 |
if (can.inArray(tagName, attr.defaultValue) >= 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
147 |
el.defaultChecked = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
148 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
149 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
150 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
151 |
} else if (prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
152 |
newValue = el[prop] = val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
153 |
if (prop === "value" && can.inArray(tagName, attr.defaultValue) >= 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
154 |
el.defaultValue = val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
155 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
156 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
157 |
el.setAttribute(attrName, val); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
158 |
newValue = val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
159 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
160 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
161 |
// Now that the value has been set, for browsers without MutationObservers, check to see that value has changed and if so trigger the "attributes" event on the element. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
162 |
if (!attr.MutationObserver && newValue !== oldValue) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
163 |
attr.trigger(el, attrName, oldValue); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
164 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
165 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
166 |
// ## attr.trigger |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
167 |
// Used to trigger an "attributes" event on an element. Checks to make sure that someone is listening for the event and then queues a function to be called asynchronously using `setImmediate. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
168 |
trigger: function(el, attrName, oldValue) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
169 |
if (can.data(can.$(el), "canHasAttributesBindings")) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
170 |
return setImmediate(function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
171 |
can.trigger(el, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
172 |
type: "attributes", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
173 |
attributeName: attrName, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
174 |
target: el, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
175 |
oldValue: oldValue, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
176 |
bubbles: false |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
177 |
}, []); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
178 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
179 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
180 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
181 |
// ## attr.get |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
182 |
// Gets the value of an attribute. First checks to see if the property is a string on `attr.map` and if so returns the value from the element's property. Otherwise uses `getAttribute` to retrieve the value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
183 |
get: function(el, attrName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
184 |
var prop = attr.map[attrName]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
185 |
if (typeof prop === "string" && el[prop]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
186 |
return el[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
187 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
188 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
189 |
return el.getAttribute(attrName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
190 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
191 |
// ## attr.remove |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
192 |
// Removes an attribute from an element. Works by using the `attr.map` to see if the attribute is a special type of property. If the property is a function then the fuction is called with `undefined` as the value. If the property is `true` then the attribute is set to false. If the property is a string then the attribute is set to an empty string. Otherwise `removeAttribute` is used. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
193 |
// If the attribute previously had a value and the browser doesn't support MutationObservers we then trigger an "attributes" event. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
194 |
remove: function(el, attrName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
195 |
var oldValue; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
196 |
if (!attr.MutationObserver) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
197 |
oldValue = attr.get(el, attrName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
198 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
199 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
200 |
var setter = attr.map[attrName]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
201 |
if (typeof setter === "function") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
202 |
setter(el, undefined); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
203 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
204 |
if (setter === true) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
205 |
el[attrName] = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
206 |
} else if (typeof setter === "string") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
207 |
el[setter] = ""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
208 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
209 |
el.removeAttribute(attrName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
210 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
211 |
if (!attr.MutationObserver && oldValue != null) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
212 |
attr.trigger(el, attrName, oldValue); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
213 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
214 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
215 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
216 |
// ## attr.has |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
217 |
// Checks if an element contains an attribute. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
218 |
// For browsers that support `hasAttribute`, creates a function that calls hasAttribute, otherwise creates a function that uses `getAttribute` to check that the attribute is not null. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
219 |
has: (function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
220 |
var el = document.createElement('div'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
221 |
if (el.hasAttribute) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
222 |
return function(el, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
223 |
return el.hasAttribute(name); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
224 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
225 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
226 |
return function(el, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
227 |
return el.getAttribute(name) !== null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
228 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
229 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
230 |
})() |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
231 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
232 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
233 |
return attr; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
234 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
235 |
})(__m5); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
236 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
237 |
// ## can/event/event.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
238 |
var __m7 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
239 |
// ## can.event.addEvent |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
240 |
// Adds a basic event listener to an object. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
241 |
// This consists of storing a cache of event listeners on each object, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
242 |
// that are iterated through later when events are dispatched. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
243 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
244 |
can.addEvent = function(event, handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
245 |
// Initialize event cache. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
246 |
var allEvents = this.__bindEvents || (this.__bindEvents = {}), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
247 |
eventList = allEvents[event] || (allEvents[event] = []); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
248 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
249 |
// Add the event |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
250 |
eventList.push({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
251 |
handler: handler, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
252 |
name: event |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
253 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
254 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
255 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
256 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
257 |
// ## can.event.listenTo |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
258 |
// Listens to an event without know how bind is implemented. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
259 |
// The primary use for this is to listen to another's objects event while |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
260 |
// tracking events on the local object (similar to namespacing). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
261 |
// The API was heavily influenced by BackboneJS: http://backbonejs.org/ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
262 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
263 |
can.listenTo = function(other, event, handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
264 |
// Initialize event cache |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
265 |
var idedEvents = this.__listenToEvents; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
266 |
if (!idedEvents) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
267 |
idedEvents = this.__listenToEvents = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
268 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
269 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
270 |
// Identify the other object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
271 |
var otherId = can.cid(other); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
272 |
var othersEvents = idedEvents[otherId]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
273 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
274 |
// Create a local event cache |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
275 |
if (!othersEvents) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
276 |
othersEvents = idedEvents[otherId] = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
277 |
obj: other, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
278 |
events: {} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
279 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
280 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
281 |
var eventsEvents = othersEvents.events[event]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
282 |
if (!eventsEvents) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
283 |
eventsEvents = othersEvents.events[event] = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
284 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
285 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
286 |
// Add the event, both locally and to the other object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
287 |
eventsEvents.push(handler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
288 |
can.bind.call(other, event, handler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
289 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
290 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
291 |
// ## can.event.stopListening |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
292 |
// Stops listening for events on other objects |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
293 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
294 |
can.stopListening = function(other, event, handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
295 |
var idedEvents = this.__listenToEvents, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
296 |
iterIdedEvents = idedEvents, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
297 |
i = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
298 |
if (!idedEvents) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
299 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
300 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
301 |
if (other) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
302 |
var othercid = can.cid(other); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
303 |
(iterIdedEvents = {})[othercid] = idedEvents[othercid]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
304 |
// you might be trying to listen to something that is not there |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
305 |
if (!idedEvents[othercid]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
306 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
307 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
308 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
309 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
310 |
// Clean up events on the other object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
311 |
for (var cid in iterIdedEvents) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
312 |
var othersEvents = iterIdedEvents[cid], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
313 |
eventsEvents; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
314 |
other = idedEvents[cid].obj; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
315 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
316 |
// Find the cache of events |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
317 |
if (!event) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
318 |
eventsEvents = othersEvents.events; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
319 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
320 |
(eventsEvents = {})[event] = othersEvents.events[event]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
321 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
322 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
323 |
// Unbind event handlers, both locally and on the other object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
324 |
for (var eventName in eventsEvents) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
325 |
var handlers = eventsEvents[eventName] || []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
326 |
i = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
327 |
while (i < handlers.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
328 |
if (handler && handler === handlers[i] || !handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
329 |
can.unbind.call(other, eventName, handlers[i]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
330 |
handlers.splice(i, 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
331 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
332 |
i++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
333 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
334 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
335 |
// no more handlers? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
336 |
if (!handlers.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
337 |
delete othersEvents.events[eventName]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
338 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
339 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
340 |
if (can.isEmptyObject(othersEvents.events)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
341 |
delete idedEvents[cid]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
342 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
343 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
344 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
345 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
346 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
347 |
// ## can.event.removeEvent |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
348 |
// Removes a basic event listener from an object. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
349 |
// This removes event handlers from the cache of listened events. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
350 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
351 |
can.removeEvent = function(event, fn, __validate) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
352 |
if (!this.__bindEvents) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
353 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
354 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
355 |
var events = this.__bindEvents[event] || [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
356 |
i = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
357 |
ev, isFunction = typeof fn === 'function'; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
358 |
while (i < events.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
359 |
ev = events[i]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
360 |
// Determine whether this event handler is "equivalent" to the one requested |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
361 |
// Generally this requires the same event/function, but a validation function |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
362 |
// can be included for extra conditions. This is used in some plugins like `can/event/namespace`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
363 |
if (__validate ? __validate(ev, event, fn) : isFunction && ev.handler === fn || !isFunction && (ev.cid === fn || !fn)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
364 |
events.splice(i, 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
365 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
366 |
i++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
367 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
368 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
369 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
370 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
371 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
372 |
// ## can.event.dispatch |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
373 |
// Dispatches/triggers a basic event on an object. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
374 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
375 |
can.dispatch = function(event, args) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
376 |
var events = this.__bindEvents; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
377 |
if (!events) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
378 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
379 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
380 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
381 |
// Initialize the event object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
382 |
if (typeof event === 'string') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
383 |
event = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
384 |
type: event |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
385 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
386 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
387 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
388 |
// Grab event listeners |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
389 |
var eventName = event.type, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
390 |
handlers = (events[eventName] || []).slice(0); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
391 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
392 |
// Execute handlers listening for this event. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
393 |
args = [event].concat(args || []); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
394 |
for (var i = 0, len = handlers.length; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
395 |
handlers[i].handler.apply(this, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
396 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
397 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
398 |
return event; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
399 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
400 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
401 |
// ## can.event.one |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
402 |
// Adds a basic event listener that listens to an event once and only once. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
403 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
404 |
can.one = function(event, handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
405 |
// Unbind the listener after it has been executed |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
406 |
var one = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
407 |
can.unbind.call(this, event, one); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
408 |
return handler.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
409 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
410 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
411 |
// Bind the altered listener |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
412 |
can.bind.call(this, event, one); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
413 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
414 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
415 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
416 |
// ## can.event |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
417 |
// Create and export the `can.event` mixin |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
418 |
can.event = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
419 |
// Event method aliases |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
420 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
421 |
on: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
422 |
if (arguments.length === 0 && can.Control && this instanceof can.Control) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
423 |
return can.Control.prototype.on.call(this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
424 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
425 |
return can.addEvent.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
426 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
427 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
428 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
429 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
430 |
off: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
431 |
if (arguments.length === 0 && can.Control && this instanceof can.Control) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
432 |
return can.Control.prototype.off.call(this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
433 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
434 |
return can.removeEvent.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
435 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
436 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
437 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
438 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
439 |
bind: can.addEvent, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
440 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
441 |
unbind: can.removeEvent, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
442 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
443 |
delegate: function(selector, event, handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
444 |
return can.addEvent.call(event, handler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
445 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
446 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
447 |
undelegate: function(selector, event, handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
448 |
return can.removeEvent.call(event, handler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
449 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
450 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
451 |
trigger: can.dispatch, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
452 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
453 |
// Normal can/event methods |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
454 |
one: can.one, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
455 |
addEvent: can.addEvent, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
456 |
removeEvent: can.removeEvent, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
457 |
listenTo: can.listenTo, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
458 |
stopListening: can.stopListening, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
459 |
dispatch: can.dispatch |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
460 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
461 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
462 |
return can.event; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
463 |
})(__m5); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
464 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
465 |
// ## can/util/array/each.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
466 |
var __m8 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
467 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
468 |
// The following is from jQuery |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
469 |
var isArrayLike = function(obj) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
470 |
var length = obj.length; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
471 |
return typeof arr !== "function" && |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
472 |
(length === 0 || typeof length === "number" && length > 0 && (length - 1) in obj); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
473 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
474 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
475 |
can.each = function(elements, callback, context) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
476 |
var i = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
477 |
key, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
478 |
len, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
479 |
item; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
480 |
if (elements) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
481 |
if (isArrayLike(elements)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
482 |
if (can.List && elements instanceof can.List) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
483 |
for (len = elements.attr("length"); i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
484 |
item = elements.attr(i); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
485 |
if (callback.call(context || item, item, i, elements) === false) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
486 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
487 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
488 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
489 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
490 |
for (len = elements.length; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
491 |
item = elements[i]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
492 |
if (callback.call(context || item, item, i, elements) === false) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
493 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
494 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
495 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
496 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
497 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
498 |
} else if (typeof elements === "object") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
499 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
500 |
if (can.Map && elements instanceof can.Map || elements === can.route) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
501 |
var keys = can.Map.keys(elements); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
502 |
for (i = 0, len = keys.length; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
503 |
key = keys[i]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
504 |
item = elements.attr(key); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
505 |
if (callback.call(context || item, item, key, elements) === false) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
506 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
507 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
508 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
509 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
510 |
for (key in elements) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
511 |
if (elements.hasOwnProperty(key) && callback.call(context || elements[key], elements[key], key, elements) === false) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
512 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
513 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
514 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
515 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
516 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
517 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
518 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
519 |
return elements; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
520 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
521 |
return can; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
522 |
})(__m5); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
523 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
524 |
// ## can/util/inserted/inserted.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
525 |
var __m9 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
526 |
can.inserted = function(elems) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
527 |
// Turn the `elems` property into an array to prevent mutations from changing the looping. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
528 |
elems = can.makeArray(elems); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
529 |
var inDocument = false, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
530 |
// Gets the `doc` to use as a reference for finding out whether the element is in the document. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
531 |
doc = can.$(document.contains ? document : document.body), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
532 |
children; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
533 |
// Go through `elems` and trigger the `inserted` event. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
534 |
// If the first element is not in the document (a Document Fragment) it will exit the function. If it is in the document it sets the `inDocument` flag to true. This means that we only check for the first element and either exit the function or start triggering "inserted" for child elements. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
535 |
for (var i = 0, elem; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
536 |
(elem = elems[i]) !== undefined; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
537 |
if (!inDocument) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
538 |
if (elem.getElementsByTagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
539 |
if (can.has(doc, elem) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
540 |
.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
541 |
inDocument = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
542 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
543 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
544 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
545 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
546 |
continue; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
547 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
548 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
549 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
550 |
// If we've found an element in the document then we can now trigger **"inserted"** for `elem` and all of its children. We are using `getElementsByTagName("*")` so that we grab all of the descendant nodes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
551 |
if (inDocument && elem.getElementsByTagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
552 |
children = can.makeArray(elem.getElementsByTagName("*")); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
553 |
can.trigger(elem, "inserted", [], false); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
554 |
for (var j = 0, child; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
555 |
(child = children[j]) !== undefined; j++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
556 |
can.trigger(child, "inserted", [], false); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
557 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
558 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
559 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
560 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
561 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
562 |
// ## can.appendChild |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
563 |
// Used to append a node to an element and trigger the "inserted" event on all of the newly inserted children. Since `can.inserted` takes an array we convert the child to an array, or in the case of a DocumentFragment we first convert the childNodes to an array and call inserted on those. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
564 |
can.appendChild = function(el, child) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
565 |
var children; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
566 |
if (child.nodeType === 11) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
567 |
children = can.makeArray(child.childNodes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
568 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
569 |
children = [child]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
570 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
571 |
el.appendChild(child); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
572 |
can.inserted(children); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
573 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
574 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
575 |
// ## can.insertBefore |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
576 |
// Like can.appendChild, used to insert a node to an element before a reference node and then trigger the "inserted" event. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
577 |
can.insertBefore = function(el, child, ref) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
578 |
var children; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
579 |
if (child.nodeType === 11) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
580 |
children = can.makeArray(child.childNodes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
581 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
582 |
children = [child]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
583 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
584 |
el.insertBefore(child, ref); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
585 |
can.inserted(children); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
586 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
587 |
})(__m5); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
588 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
589 |
// ## can/util/jquery/jquery.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
590 |
var __m3 = (function($, can, attr, event) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
591 |
var isBindableElement = function(node) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
592 |
// In IE8 window.window !== window.window, so we allow == here. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
593 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
594 |
return (node.nodeName && (node.nodeType === 1 || node.nodeType === 9)) || node == window; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
595 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
596 |
// _jQuery node list._ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
597 |
$.extend(can, $, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
598 |
trigger: function(obj, event, args, bubbles) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
599 |
if (isBindableElement(obj)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
600 |
$.event.trigger(event, args, obj, !bubbles); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
601 |
} else if (obj.trigger) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
602 |
obj.trigger(event, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
603 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
604 |
if (typeof event === 'string') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
605 |
event = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
606 |
type: event |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
607 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
608 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
609 |
event.target = event.target || obj; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
610 |
can.dispatch.call(obj, event, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
611 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
612 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
613 |
event: can.event, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
614 |
addEvent: can.addEvent, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
615 |
removeEvent: can.removeEvent, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
616 |
buildFragment: function(elems, context) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
617 |
// Check if this has any html nodes on our own. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
618 |
var ret; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
619 |
elems = [elems]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
620 |
// Set context per 1.8 logic |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
621 |
context = context || document; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
622 |
context = !context.nodeType && context[0] || context; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
623 |
context = context.ownerDocument || context; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
624 |
ret = $.buildFragment(elems, context); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
625 |
return ret.cacheable ? $.clone(ret.fragment) : ret.fragment || ret; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
626 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
627 |
$: $, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
628 |
each: can.each, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
629 |
bind: function(ev, cb) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
630 |
// If we can bind to it... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
631 |
if (this.bind && this.bind !== can.bind) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
632 |
this.bind(ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
633 |
} else if (isBindableElement(this)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
634 |
$.event.add(this, ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
635 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
636 |
// Make it bind-able... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
637 |
can.addEvent.call(this, ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
638 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
639 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
640 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
641 |
unbind: function(ev, cb) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
642 |
// If we can bind to it... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
643 |
if (this.unbind && this.unbind !== can.unbind) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
644 |
this.unbind(ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
645 |
} else if (isBindableElement(this)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
646 |
$.event.remove(this, ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
647 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
648 |
// Make it bind-able... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
649 |
can.removeEvent.call(this, ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
650 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
651 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
652 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
653 |
delegate: function(selector, ev, cb) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
654 |
if (this.delegate) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
655 |
this.delegate(selector, ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
656 |
} else if (isBindableElement(this)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
657 |
$(this) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
658 |
.delegate(selector, ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
659 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
660 |
// make it bind-able ... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
661 |
can.bind.call(this, ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
662 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
663 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
664 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
665 |
undelegate: function(selector, ev, cb) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
666 |
if (this.undelegate) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
667 |
this.undelegate(selector, ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
668 |
} else if (isBindableElement(this)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
669 |
$(this) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
670 |
.undelegate(selector, ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
671 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
672 |
can.unbind.call(this, ev, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
673 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
674 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
675 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
676 |
proxy: function(fn, context) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
677 |
return function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
678 |
return fn.apply(context, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
679 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
680 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
681 |
attr: attr |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
682 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
683 |
// Wrap binding functions. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
684 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
685 |
// Aliases |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
686 |
can.on = can.bind; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
687 |
can.off = can.unbind; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
688 |
// Wrap modifier functions. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
689 |
$.each([ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
690 |
'append', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
691 |
'filter', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
692 |
'addClass', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
693 |
'remove', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
694 |
'data', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
695 |
'get', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
696 |
'has' |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
697 |
], function(i, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
698 |
can[name] = function(wrapped) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
699 |
return wrapped[name].apply(wrapped, can.makeArray(arguments) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
700 |
.slice(1)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
701 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
702 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
703 |
// Memory safe destruction. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
704 |
var oldClean = $.cleanData; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
705 |
$.cleanData = function(elems) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
706 |
$.each(elems, function(i, elem) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
707 |
if (elem) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
708 |
can.trigger(elem, 'removed', [], false); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
709 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
710 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
711 |
oldClean(elems); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
712 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
713 |
var oldDomManip = $.fn.domManip, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
714 |
cbIndex; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
715 |
// feature detect which domManip we are using |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
716 |
$.fn.domManip = function(args, cb1, cb2) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
717 |
for (var i = 1; i < arguments.length; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
718 |
if (typeof arguments[i] === 'function') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
719 |
cbIndex = i; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
720 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
721 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
722 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
723 |
return oldDomManip.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
724 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
725 |
$(document.createElement("div")) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
726 |
.append(document.createElement("div")); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
727 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
728 |
$.fn.domManip = (cbIndex === 2 ? function(args, table, callback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
729 |
return oldDomManip.call(this, args, table, function(elem) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
730 |
var elems; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
731 |
if (elem.nodeType === 11) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
732 |
elems = can.makeArray(elem.childNodes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
733 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
734 |
var ret = callback.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
735 |
can.inserted(elems ? elems : [elem]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
736 |
return ret; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
737 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
738 |
} : function(args, callback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
739 |
return oldDomManip.call(this, args, function(elem) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
740 |
var elems; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
741 |
if (elem.nodeType === 11) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
742 |
elems = can.makeArray(elem.childNodes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
743 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
744 |
var ret = callback.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
745 |
can.inserted(elems ? elems : [elem]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
746 |
return ret; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
747 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
748 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
749 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
750 |
if (!can.attr.MutationObserver) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
751 |
// handle via calls to attr |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
752 |
var oldAttr = $.attr; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
753 |
$.attr = function(el, attrName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
754 |
var oldValue, newValue; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
755 |
if (arguments.length >= 3) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
756 |
oldValue = oldAttr.call(this, el, attrName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
757 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
758 |
var res = oldAttr.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
759 |
if (arguments.length >= 3) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
760 |
newValue = oldAttr.call(this, el, attrName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
761 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
762 |
if (newValue !== oldValue) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
763 |
can.attr.trigger(el, attrName, oldValue); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
764 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
765 |
return res; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
766 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
767 |
var oldRemove = $.removeAttr; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
768 |
$.removeAttr = function(el, attrName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
769 |
var oldValue = oldAttr.call(this, el, attrName), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
770 |
res = oldRemove.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
771 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
772 |
if (oldValue != null) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
773 |
can.attr.trigger(el, attrName, oldValue); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
774 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
775 |
return res; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
776 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
777 |
$.event.special.attributes = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
778 |
setup: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
779 |
can.data(can.$(this), "canHasAttributesBindings", true); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
780 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
781 |
teardown: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
782 |
$.removeData(this, "canHasAttributesBindings"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
783 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
784 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
785 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
786 |
// setup a special events |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
787 |
$.event.special.attributes = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
788 |
setup: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
789 |
var self = this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
790 |
var observer = new can.attr.MutationObserver(function(mutations) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
791 |
mutations.forEach(function(mutation) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
792 |
var copy = can.simpleExtend({}, mutation); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
793 |
can.trigger(self, copy, []); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
794 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
795 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
796 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
797 |
observer.observe(this, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
798 |
attributes: true, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
799 |
attributeOldValue: true |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
800 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
801 |
can.data(can.$(this), "canAttributesObserver", observer); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
802 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
803 |
teardown: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
804 |
can.data(can.$(this), "canAttributesObserver") |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
805 |
.disconnect(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
806 |
$.removeData(this, "canAttributesObserver"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
807 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
808 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
809 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
810 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
811 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
812 |
// ## Fix build fragment. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
813 |
// In IE8, we can pass jQuery a fragment and it removes newlines. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
814 |
// This checks for that and replaces can.buildFragment with something |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
815 |
// that if only a single text node is returned, returns a fragment with |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
816 |
// a text node that is set to the content. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
817 |
(function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
818 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
819 |
var text = "<-\n>", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
820 |
frag = can.buildFragment(text, document); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
821 |
if (text !== frag.childNodes[0].nodeValue) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
822 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
823 |
var oldBuildFragment = can.buildFragment; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
824 |
can.buildFragment = function(content, context) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
825 |
var res = oldBuildFragment(content, context); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
826 |
if (res.childNodes.length === 1 && res.childNodes[0].nodeType === 3) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
827 |
res.childNodes[0].nodeValue = content; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
828 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
829 |
return res; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
830 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
831 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
832 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
833 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
834 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
835 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
836 |
})(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
837 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
838 |
$.event.special.inserted = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
839 |
$.event.special.removed = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
840 |
return can; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
841 |
})(jQuery, __m5, __m6, __m7, __m8, __m9); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
842 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
843 |
// ## can/util/string/string.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
844 |
var __m2 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
845 |
// ##string.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
846 |
// _Miscellaneous string utility functions._ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
847 |
// Several of the methods in this plugin use code adapated from Prototype |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
848 |
// Prototype JavaScript framework, version 1.6.0.1. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
849 |
// © 2005-2007 Sam Stephenson |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
850 |
var strUndHash = /_|-/, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
851 |
strColons = /\=\=/, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
852 |
strWords = /([A-Z]+)([A-Z][a-z])/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
853 |
strLowUp = /([a-z\d])([A-Z])/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
854 |
strDash = /([a-z\d])([A-Z])/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
855 |
strReplacer = /\{([^\}]+)\}/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
856 |
strQuote = /"/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
857 |
strSingleQuote = /'/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
858 |
strHyphenMatch = /-+(.)?/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
859 |
strCamelMatch = /[a-z][A-Z]/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
860 |
// Returns the `prop` property from `obj`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
861 |
// If `add` is true and `prop` doesn't exist in `obj`, create it as an |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
862 |
// empty object. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
863 |
getNext = function(obj, prop, add) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
864 |
var result = obj[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
865 |
if (result === undefined && add === true) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
866 |
result = obj[prop] = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
867 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
868 |
return result; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
869 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
870 |
// Returns `true` if the object can have properties (no `null`s). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
871 |
isContainer = function(current) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
872 |
return /^f|^o/.test(typeof current); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
873 |
}, convertBadValues = function(content) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
874 |
// Convert bad values into empty strings |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
875 |
var isInvalid = content === null || content === undefined || isNaN(content) && '' + content === 'NaN'; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
876 |
return '' + (isInvalid ? '' : content); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
877 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
878 |
can.extend(can, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
879 |
esc: function(content) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
880 |
return convertBadValues(content) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
881 |
.replace(/&/g, '&') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
882 |
.replace(/</g, '<') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
883 |
.replace(/>/g, '>') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
884 |
.replace(strQuote, '"') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
885 |
.replace(strSingleQuote, '''); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
886 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
887 |
getObject: function(name, roots, add) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
888 |
// The parts of the name we are looking up |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
889 |
// `['App','Models','Recipe']` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
890 |
var parts = name ? name.split('.') : [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
891 |
length = parts.length, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
892 |
current, r = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
893 |
i, container, rootsLength; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
894 |
// Make sure roots is an `array`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
895 |
roots = can.isArray(roots) ? roots : [roots || window]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
896 |
rootsLength = roots.length; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
897 |
if (!length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
898 |
return roots[0]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
899 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
900 |
// For each root, mark it as current. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
901 |
for (r; r < rootsLength; r++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
902 |
current = roots[r]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
903 |
container = undefined; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
904 |
// Walk current to the 2nd to last object or until there |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
905 |
// is not a container. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
906 |
for (i = 0; i < length && isContainer(current); i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
907 |
container = current; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
908 |
current = getNext(container, parts[i]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
909 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
910 |
// If we found property break cycle |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
911 |
if (container !== undefined && current !== undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
912 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
913 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
914 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
915 |
// Remove property from found container |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
916 |
if (add === false && current !== undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
917 |
delete container[parts[i - 1]]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
918 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
919 |
// When adding property add it to the first root |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
920 |
if (add === true && current === undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
921 |
current = roots[0]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
922 |
for (i = 0; i < length && isContainer(current); i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
923 |
current = getNext(current, parts[i], true); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
924 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
925 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
926 |
return current; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
927 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
928 |
capitalize: function(s, cache) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
929 |
// Used to make newId. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
930 |
return s.charAt(0) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
931 |
.toUpperCase() + s.slice(1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
932 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
933 |
camelize: function(str) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
934 |
return convertBadValues(str) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
935 |
.replace(strHyphenMatch, function(match, chr) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
936 |
return chr ? chr.toUpperCase() : ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
937 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
938 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
939 |
hyphenate: function(str) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
940 |
return convertBadValues(str) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
941 |
.replace(strCamelMatch, function(str, offset) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
942 |
return str.charAt(0) + '-' + str.charAt(1) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
943 |
.toLowerCase(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
944 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
945 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
946 |
underscore: function(s) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
947 |
return s.replace(strColons, '/') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
948 |
.replace(strWords, '$1_$2') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
949 |
.replace(strLowUp, '$1_$2') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
950 |
.replace(strDash, '_') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
951 |
.toLowerCase(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
952 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
953 |
sub: function(str, data, remove) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
954 |
var obs = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
955 |
str = str || ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
956 |
obs.push(str.replace(strReplacer, function(whole, inside) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
957 |
// Convert inside to type. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
958 |
var ob = can.getObject(inside, data, remove === true ? false : undefined); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
959 |
if (ob === undefined || ob === null) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
960 |
obs = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
961 |
return ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
962 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
963 |
// If a container, push into objs (which will return objects found). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
964 |
if (isContainer(ob) && obs) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
965 |
obs.push(ob); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
966 |
return ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
967 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
968 |
return '' + ob; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
969 |
})); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
970 |
return obs === null ? obs : obs.length <= 1 ? obs[0] : obs; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
971 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
972 |
replacer: strReplacer, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
973 |
undHash: strUndHash |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
974 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
975 |
return can; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
976 |
})(__m3); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
977 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
978 |
// ## can/construct/construct.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
979 |
var __m1 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
980 |
// ## construct.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
981 |
// `can.Construct` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
982 |
// _This is a modified version of |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
983 |
// [John Resig's class](http://ejohn.org/blog/simple-javascript-inheritance/). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
984 |
// It provides class level inheritance and callbacks._ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
985 |
// A private flag used to initialize a new class instance without |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
986 |
// initializing it's bindings. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
987 |
var initializing = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
988 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
989 |
can.Construct = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
990 |
if (arguments.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
991 |
return can.Construct.extend.apply(can.Construct, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
992 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
993 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
994 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
995 |
can.extend(can.Construct, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
996 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
997 |
constructorExtends: true, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
998 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
999 |
newInstance: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1000 |
// Get a raw instance object (`init` is not called). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1001 |
var inst = this.instance(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1002 |
args; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1003 |
// Call `setup` if there is a `setup` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1004 |
if (inst.setup) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1005 |
args = inst.setup.apply(inst, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1006 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1007 |
// Call `init` if there is an `init` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1008 |
// If `setup` returned `args`, use those as the arguments |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1009 |
if (inst.init) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1010 |
inst.init.apply(inst, args || arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1011 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1012 |
return inst; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1013 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1014 |
// Overwrites an object with methods. Used in the `super` plugin. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1015 |
// `newProps` - New properties to add. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1016 |
// `oldProps` - Where the old properties might be (used with `super`). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1017 |
// `addTo` - What we are adding to. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1018 |
_inherit: function(newProps, oldProps, addTo) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1019 |
can.extend(addTo || newProps, newProps || {}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1020 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1021 |
// used for overwriting a single property. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1022 |
// this should be used for patching other objects |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1023 |
// the super plugin overwrites this |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1024 |
_overwrite: function(what, oldProps, propName, val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1025 |
what[propName] = val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1026 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1027 |
// Set `defaults` as the merger of the parent `defaults` and this |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1028 |
// object's `defaults`. If you overwrite this method, make sure to |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1029 |
// include option merging logic. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1030 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1031 |
setup: function(base, fullName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1032 |
this.defaults = can.extend(true, {}, base.defaults, this.defaults); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1033 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1034 |
// Create's a new `class` instance without initializing by setting the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1035 |
// `initializing` flag. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1036 |
instance: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1037 |
// Prevents running `init`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1038 |
initializing = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1039 |
var inst = new this(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1040 |
// Allow running `init`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1041 |
initializing = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1042 |
return inst; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1043 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1044 |
// Extends classes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1045 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1046 |
extend: function(fullName, klass, proto) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1047 |
// Figure out what was passed and normalize it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1048 |
if (typeof fullName !== 'string') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1049 |
proto = klass; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1050 |
klass = fullName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1051 |
fullName = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1052 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1053 |
if (!proto) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1054 |
proto = klass; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1055 |
klass = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1056 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1057 |
proto = proto || {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1058 |
var _super_class = this, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1059 |
_super = this.prototype, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1060 |
parts, current, _fullName, _shortName, name, shortName, namespace, prototype; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1061 |
// Instantiate a base class (but only create the instance, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1062 |
// don't run the init constructor). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1063 |
prototype = this.instance(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1064 |
// Copy the properties over onto the new prototype. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1065 |
can.Construct._inherit(proto, _super, prototype); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1066 |
// The dummy class constructor. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1067 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1068 |
function Constructor() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1069 |
// All construction is actually done in the init method. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1070 |
if (!initializing) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1071 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1072 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1073 |
return this.constructor !== Constructor && |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1074 |
// We are being called without `new` or we are extending. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1075 |
arguments.length && Constructor.constructorExtends ? Constructor.extend.apply(Constructor, arguments) : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1076 |
// We are being called with `new`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1077 |
Constructor.newInstance.apply(Constructor, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1078 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1079 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1080 |
// Copy old stuff onto class (can probably be merged w/ inherit) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1081 |
for (name in _super_class) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1082 |
if (_super_class.hasOwnProperty(name)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1083 |
Constructor[name] = _super_class[name]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1084 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1085 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1086 |
// Copy new static properties on class. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1087 |
can.Construct._inherit(klass, _super_class, Constructor); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1088 |
// Setup namespaces. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1089 |
if (fullName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1090 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1091 |
parts = fullName.split('.'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1092 |
shortName = parts.pop(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1093 |
current = can.getObject(parts.join('.'), window, true); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1094 |
namespace = current; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1095 |
_fullName = can.underscore(fullName.replace(/\./g, "_")); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1096 |
_shortName = can.underscore(shortName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1097 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1098 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1099 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1100 |
current[shortName] = Constructor; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1101 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1102 |
// Set things that shouldn't be overwritten. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1103 |
can.extend(Constructor, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1104 |
constructor: Constructor, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1105 |
prototype: prototype, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1106 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1107 |
namespace: namespace, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1108 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1109 |
_shortName: _shortName, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1110 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1111 |
fullName: fullName, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1112 |
_fullName: _fullName |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1113 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1114 |
// Dojo and YUI extend undefined |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1115 |
if (shortName !== undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1116 |
Constructor.shortName = shortName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1117 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1118 |
// Make sure our prototype looks nice. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1119 |
Constructor.prototype.constructor = Constructor; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1120 |
// Call the class `setup` and `init` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1121 |
var t = [_super_class].concat(can.makeArray(arguments)), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1122 |
args = Constructor.setup.apply(Constructor, t); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1123 |
if (Constructor.init) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1124 |
Constructor.init.apply(Constructor, args || t); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1125 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1126 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1127 |
return Constructor; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1128 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1129 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1130 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1131 |
can.Construct.prototype.setup = function() {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1132 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1133 |
can.Construct.prototype.init = function() {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1134 |
return can.Construct; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1135 |
})(__m2); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1136 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1137 |
// ## can/util/bind/bind.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1138 |
var __m11 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1139 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1140 |
// ## Bind helpers |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1141 |
can.bindAndSetup = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1142 |
// Add the event to this object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1143 |
can.addEvent.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1144 |
// If not initializing, and the first binding |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1145 |
// call bindsetup if the function exists. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1146 |
if (!this._init) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1147 |
if (!this._bindings) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1148 |
this._bindings = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1149 |
// setup live-binding |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1150 |
if (this._bindsetup) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1151 |
this._bindsetup(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1152 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1153 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1154 |
this._bindings++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1155 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1156 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1157 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1158 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1159 |
can.unbindAndTeardown = function(ev, handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1160 |
// Remove the event handler |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1161 |
can.removeEvent.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1162 |
if (this._bindings === null) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1163 |
this._bindings = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1164 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1165 |
this._bindings--; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1166 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1167 |
// If there are no longer any bindings and |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1168 |
// there is a bindteardown method, call it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1169 |
if (!this._bindings && this._bindteardown) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1170 |
this._bindteardown(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1171 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1172 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1173 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1174 |
return can; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1175 |
})(__m3); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1176 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1177 |
// ## can/map/bubble.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1178 |
var __m12 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1179 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1180 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1181 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1182 |
var bubble = can.bubble = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1183 |
// Given a binding, returns a string event name used to set up bubbline. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1184 |
// If no binding should be done, undefined or null should be returned |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1185 |
event: function(map, eventName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1186 |
return map.constructor._bubbleRule(eventName, map); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1187 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1188 |
childrenOf: function(parentMap, eventName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1189 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1190 |
parentMap._each(function(child, prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1191 |
if (child && child.bind) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1192 |
bubble.toParent(child, parentMap, prop, eventName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1193 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1194 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1195 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1196 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1197 |
teardownChildrenFrom: function(parentMap, eventName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1198 |
parentMap._each(function(child) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1199 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1200 |
bubble.teardownFromParent(parentMap, child, eventName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1201 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1202 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1203 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1204 |
toParent: function(child, parent, prop, eventName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1205 |
can.listenTo.call(parent, child, eventName, function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1206 |
// `batchTrigger` the type on this... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1207 |
var args = can.makeArray(arguments), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1208 |
ev = args.shift(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1209 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1210 |
args[0] = |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1211 |
(can.List && parent instanceof can.List ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1212 |
parent.indexOf(child) : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1213 |
prop) + (args[0] ? "." + args[0] : ""); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1214 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1215 |
// track objects dispatched on this map |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1216 |
ev.triggeredNS = ev.triggeredNS || {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1217 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1218 |
// if it has already been dispatched exit |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1219 |
if (ev.triggeredNS[parent._cid]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1220 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1221 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1222 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1223 |
ev.triggeredNS[parent._cid] = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1224 |
// send change event with modified attr to parent |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1225 |
can.trigger(parent, ev, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1226 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1227 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1228 |
teardownFromParent: function(parent, child, eventName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1229 |
if (child && child.unbind) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1230 |
can.stopListening.call(parent, child, eventName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1231 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1232 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1233 |
bind: function(parent, eventName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1234 |
if (!parent._init) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1235 |
var bubbleEvent = bubble.event(parent, eventName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1236 |
if (bubbleEvent) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1237 |
if (!parent._bubbleBindings) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1238 |
parent._bubbleBindings = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1239 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1240 |
if (!parent._bubbleBindings[bubbleEvent]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1241 |
parent._bubbleBindings[bubbleEvent] = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1242 |
// setup live-binding |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1243 |
bubble.childrenOf(parent, bubbleEvent); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1244 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1245 |
parent._bubbleBindings[bubbleEvent]++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1246 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1247 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1248 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1249 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1250 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1251 |
unbind: function(parent, eventName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1252 |
var bubbleEvent = bubble.event(parent, eventName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1253 |
if (bubbleEvent) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1254 |
if (parent._bubbleBindings) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1255 |
parent._bubbleBindings[bubbleEvent]--; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1256 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1257 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1258 |
if (!parent._bubbleBindings[bubbleEvent]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1259 |
delete parent._bubbleBindings[bubbleEvent]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1260 |
bubble.teardownChildrenFrom(parent, bubbleEvent); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1261 |
if (can.isEmptyObject(parent._bubbleBindings)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1262 |
delete parent._bubbleBindings; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1263 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1264 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1265 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1266 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1267 |
add: function(parent, child, prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1268 |
if (child instanceof can.Map && parent._bubbleBindings) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1269 |
for (var eventName in parent._bubbleBindings) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1270 |
if (parent._bubbleBindings[eventName]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1271 |
bubble.teardownFromParent(parent, child, eventName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1272 |
bubble.toParent(child, parent, prop, eventName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1273 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1274 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1275 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1276 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1277 |
removeMany: function(parent, children) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1278 |
for (var i = 0, len = children.length; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1279 |
bubble.remove(parent, children[i]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1280 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1281 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1282 |
remove: function(parent, child) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1283 |
if (child instanceof can.Map && parent._bubbleBindings) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1284 |
for (var eventName in parent._bubbleBindings) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1285 |
if (parent._bubbleBindings[eventName]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1286 |
bubble.teardownFromParent(parent, child, eventName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1287 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1288 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1289 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1290 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1291 |
set: function(parent, prop, value, current) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1292 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1293 |
//var res = parent.__type(value, prop); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1294 |
if (can.Map.helpers.isObservable(value)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1295 |
bubble.add(parent, value, prop); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1296 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1297 |
// bubble.add will remove, so only remove if we are replacing another object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1298 |
if (can.Map.helpers.isObservable(current)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1299 |
bubble.remove(parent, current); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1300 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1301 |
return value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1302 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1303 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1304 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1305 |
return bubble; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1306 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1307 |
})(__m3); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1308 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1309 |
// ## can/util/batch/batch.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1310 |
var __m13 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1311 |
// Which batch of events this is for -- might not want to send multiple |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1312 |
// messages on the same batch. This is mostly for event delegation. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1313 |
var batchNum = 1, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1314 |
// how many times has start been called without a stop |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1315 |
transactions = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1316 |
// an array of events within a transaction |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1317 |
batchEvents = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1318 |
stopCallbacks = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1319 |
can.batch = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1320 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1321 |
start: function(batchStopHandler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1322 |
transactions++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1323 |
if (batchStopHandler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1324 |
stopCallbacks.push(batchStopHandler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1325 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1326 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1327 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1328 |
stop: function(force, callStart) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1329 |
if (force) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1330 |
transactions = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1331 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1332 |
transactions--; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1333 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1334 |
if (transactions === 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1335 |
var items = batchEvents.slice(0), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1336 |
callbacks = stopCallbacks.slice(0), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1337 |
i, len; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1338 |
batchEvents = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1339 |
stopCallbacks = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1340 |
batchNum++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1341 |
if (callStart) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1342 |
can.batch.start(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1343 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1344 |
for (i = 0, len = items.length; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1345 |
can.trigger.apply(can, items[i]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1346 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1347 |
for (i = 0, len = callbacks.length; i < callbacks.length; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1348 |
callbacks[i](); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1349 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1350 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1351 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1352 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1353 |
trigger: function(item, event, args) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1354 |
// Don't send events if initalizing. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1355 |
if (!item._init) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1356 |
if (transactions === 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1357 |
return can.trigger(item, event, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1358 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1359 |
event = typeof event === 'string' ? { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1360 |
type: event |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1361 |
} : event; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1362 |
event.batchNum = batchNum; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1363 |
batchEvents.push([ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1364 |
item, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1365 |
event, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1366 |
args |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1367 |
]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1368 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1369 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1370 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1371 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1372 |
})(__m5); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1373 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1374 |
// ## can/map/map.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1375 |
var __m10 = (function(can, bind, bubble) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1376 |
// ## Helpers |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1377 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1378 |
// A temporary map of Maps that have been made from plain JS objects. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1379 |
var madeMap = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1380 |
// Clears out map of converted objects. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1381 |
var teardownMap = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1382 |
for (var cid in madeMap) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1383 |
if (madeMap[cid].added) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1384 |
delete madeMap[cid].obj._cid; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1385 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1386 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1387 |
madeMap = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1388 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1389 |
// Retrieves a Map instance from an Object. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1390 |
var getMapFromObject = function(obj) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1391 |
return madeMap && madeMap[obj._cid] && madeMap[obj._cid].instance; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1392 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1393 |
// A temporary map of Maps |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1394 |
var serializeMap = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1395 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1396 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1397 |
var Map = can.Map = can.Construct.extend({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1398 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1399 |
setup: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1400 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1401 |
can.Construct.setup.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1402 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1403 |
// Do not run if we are defining can.Map. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1404 |
if (can.Map) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1405 |
if (!this.defaults) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1406 |
this.defaults = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1407 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1408 |
// Builds a list of compute and non-compute properties in this Object's prototype. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1409 |
this._computes = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1410 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1411 |
for (var prop in this.prototype) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1412 |
// Non-functions are regular defaults. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1413 |
if (prop !== "define" && typeof this.prototype[prop] !== "function") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1414 |
this.defaults[prop] = this.prototype[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1415 |
// Functions with an `isComputed` property are computes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1416 |
} else if (this.prototype[prop].isComputed) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1417 |
this._computes.push(prop); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1418 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1419 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1420 |
this.helpers.define(this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1421 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1422 |
// If we inherit from can.Map, but not can.List, make sure any lists are the correct type. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1423 |
if (can.List && !(this.prototype instanceof can.List)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1424 |
this.List = Map.List.extend({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1425 |
Map: this |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1426 |
}, {}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1427 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1428 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1429 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1430 |
// Reference to bubbling helpers. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1431 |
_bubble: bubble, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1432 |
// Given an eventName, determine if bubbling should be setup. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1433 |
_bubbleRule: function(eventName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1434 |
return (eventName === "change" || eventName.indexOf(".") >= 0) && "change"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1435 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1436 |
// List of computes on the Map's prototype. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1437 |
_computes: [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1438 |
// Adds an event to this Map. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1439 |
bind: can.bindAndSetup, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1440 |
on: can.bindAndSetup, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1441 |
// Removes an event from this Map. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1442 |
unbind: can.unbindAndTeardown, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1443 |
off: can.unbindAndTeardown, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1444 |
// Name of the id field. Used in can.Model. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1445 |
id: "id", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1446 |
// ## Internal helpers |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1447 |
helpers: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1448 |
// ### can.Map.helpers.define |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1449 |
// Stub function for the define plugin. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1450 |
define: function() {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1451 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1452 |
// ### can.Map.helpers.attrParts |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1453 |
// Parses attribute name into its parts. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1454 |
attrParts: function(attr, keepKey) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1455 |
//Keep key intact |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1456 |
if (keepKey) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1457 |
return [attr]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1458 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1459 |
// Split key on '.' |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1460 |
return can.isArray(attr) ? attr : ("" + attr) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1461 |
.split("."); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1462 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1463 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1464 |
// ### can.Map.helpers.addToMap |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1465 |
// Tracks Map instances created from JS Objects |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1466 |
addToMap: function(obj, instance) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1467 |
var teardown; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1468 |
// Setup a fresh mapping if `madeMap` is missing. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1469 |
if (!madeMap) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1470 |
teardown = teardownMap; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1471 |
madeMap = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1472 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1473 |
// Record if Object has a `_cid` before adding one. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1474 |
var hasCid = obj._cid; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1475 |
var cid = can.cid(obj); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1476 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1477 |
// Only update if there already isn't one already. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1478 |
if (!madeMap[cid]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1479 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1480 |
madeMap[cid] = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1481 |
obj: obj, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1482 |
instance: instance, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1483 |
added: !hasCid |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1484 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1485 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1486 |
return teardown; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1487 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1488 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1489 |
// ### can.Map.helpers.isObservable |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1490 |
// Determines if `obj` is observable. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1491 |
isObservable: function(obj) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1492 |
return obj instanceof can.Map || (obj && obj === can.route); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1493 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1494 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1495 |
// ### can.Map.helpers.canMakeObserve |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1496 |
// Determines if an object can be made into an observable. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1497 |
canMakeObserve: function(obj) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1498 |
return obj && !can.isDeferred(obj) && (can.isArray(obj) || can.isPlainObject(obj)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1499 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1500 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1501 |
// ### can.Map.helpers.serialize |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1502 |
// Serializes a Map or Map.List |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1503 |
serialize: function(map, how, where) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1504 |
var cid = can.cid(map), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1505 |
firstSerialize = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1506 |
if (!serializeMap) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1507 |
firstSerialize = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1508 |
// Serialize might call .attr() so we need to keep different map |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1509 |
serializeMap = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1510 |
attr: {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1511 |
serialize: {} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1512 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1513 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1514 |
serializeMap[how][cid] = where; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1515 |
// Go through each property. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1516 |
map.each(function(val, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1517 |
// If the value is an `object`, and has an `attrs` or `serialize` function. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1518 |
var result, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1519 |
isObservable = Map.helpers.isObservable(val), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1520 |
serialized = isObservable && serializeMap[how][can.cid(val)]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1521 |
if (serialized) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1522 |
result = serialized; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1523 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1524 |
if (how === "serialize") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1525 |
result = Map.helpers._serialize(map, name, val); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1526 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1527 |
result = Map.helpers._getValue(map, name, val, how); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1528 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1529 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1530 |
// this is probably removable |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1531 |
if (result !== undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1532 |
where[name] = result; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1533 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1534 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1535 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1536 |
can.__reading(map, '__keys'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1537 |
if (firstSerialize) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1538 |
serializeMap = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1539 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1540 |
return where; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1541 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1542 |
_serialize: function(map, name, val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1543 |
return Map.helpers._getValue(map, name, val, "serialize"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1544 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1545 |
_getValue: function(map, name, val, how) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1546 |
if (Map.helpers.isObservable(val)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1547 |
return val[how](); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1548 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1549 |
return val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1550 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1551 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1552 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1553 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1554 |
keys: function(map) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1555 |
var keys = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1556 |
can.__reading(map, '__keys'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1557 |
for (var keyName in map._data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1558 |
keys.push(keyName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1559 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1560 |
return keys; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1561 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1562 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1563 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1564 |
{ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1565 |
setup: function(obj) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1566 |
// `_data` is where we keep the properties. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1567 |
this._data = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1568 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1569 |
// The namespace this `object` uses to listen to events. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1570 |
can.cid(this, ".map"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1571 |
// Sets all `attrs`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1572 |
this._init = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1573 |
// It's handy if we pass this to comptues, because computes can have a default value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1574 |
var defaultValues = this._setupDefaults(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1575 |
this._setupComputes(defaultValues); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1576 |
var teardownMapping = obj && can.Map.helpers.addToMap(obj, this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1577 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1578 |
var data = can.extend(can.extend(true, {}, defaultValues), obj); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1579 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1580 |
this.attr(data); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1581 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1582 |
if (teardownMapping) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1583 |
teardownMapping(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1584 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1585 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1586 |
// `batchTrigger` change events. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1587 |
this.bind('change', can.proxy(this._changes, this)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1588 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1589 |
delete this._init; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1590 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1591 |
// Sets up computed properties on a Map. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1592 |
_setupComputes: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1593 |
var computes = this.constructor._computes; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1594 |
this._computedBindings = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1595 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1596 |
for (var i = 0, len = computes.length, prop; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1597 |
prop = computes[i]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1598 |
// Make the context of the compute the current Map |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1599 |
this[prop] = this[prop].clone(this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1600 |
// Keep track of computed properties |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1601 |
this._computedBindings[prop] = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1602 |
count: 0 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1603 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1604 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1605 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1606 |
_setupDefaults: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1607 |
return this.constructor.defaults || {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1608 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1609 |
// Setup child bindings. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1610 |
_bindsetup: function() {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1611 |
// Teardown child bindings. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1612 |
_bindteardown: function() {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1613 |
// `change`event handler. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1614 |
_changes: function(ev, attr, how, newVal, oldVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1615 |
// when a change happens, create the named event. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1616 |
can.batch.trigger(this, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1617 |
type: attr, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1618 |
batchNum: ev.batchNum |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1619 |
}, [newVal, oldVal]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1620 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1621 |
if (how === "remove" || how === "add") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1622 |
can.batch.trigger(this, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1623 |
type: "__keys", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1624 |
batchNum: ev.batchNum |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1625 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1626 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1627 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1628 |
// Trigger a change event. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1629 |
_triggerChange: function(attr, how, newVal, oldVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1630 |
can.batch.trigger(this, "change", can.makeArray(arguments)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1631 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1632 |
// Iterator that does not trigger live binding. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1633 |
_each: function(callback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1634 |
var data = this.__get(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1635 |
for (var prop in data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1636 |
if (data.hasOwnProperty(prop)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1637 |
callback(data[prop], prop); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1638 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1639 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1640 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1641 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1642 |
attr: function(attr, val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1643 |
// This is super obfuscated for space -- basically, we're checking |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1644 |
// if the type of the attribute is not a `number` or a `string`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1645 |
var type = typeof attr; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1646 |
if (type !== "string" && type !== "number") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1647 |
return this._attrs(attr, val); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1648 |
// If we are getting a value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1649 |
} else if (arguments.length === 1) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1650 |
// Let people know we are reading. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1651 |
can.__reading(this, attr); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1652 |
return this._get(attr); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1653 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1654 |
// Otherwise we are setting. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1655 |
this._set(attr, val); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1656 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1657 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1658 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1659 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1660 |
each: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1661 |
return can.each.apply(undefined, [this].concat(can.makeArray(arguments))); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1662 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1663 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1664 |
removeAttr: function(attr) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1665 |
// If this is List. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1666 |
var isList = can.List && this instanceof can.List, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1667 |
// Convert the `attr` into parts (if nested). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1668 |
parts = can.Map.helpers.attrParts(attr), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1669 |
// The actual property to remove. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1670 |
prop = parts.shift(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1671 |
// The current value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1672 |
current = isList ? this[prop] : this._data[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1673 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1674 |
// If we have more parts, call `removeAttr` on that part. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1675 |
if (parts.length && current) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1676 |
return current.removeAttr(parts); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1677 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1678 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1679 |
// If attr does not have a `.` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1680 |
if (typeof attr === 'string' && !! ~attr.indexOf('.')) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1681 |
prop = attr; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1682 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1683 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1684 |
this._remove(prop, current); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1685 |
return current; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1686 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1687 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1688 |
// Remove a property. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1689 |
_remove: function(prop, current) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1690 |
if (prop in this._data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1691 |
// Delete the property from `_data` and the Map |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1692 |
// as long as it isn't part of the Map's prototype. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1693 |
delete this._data[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1694 |
if (!(prop in this.constructor.prototype)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1695 |
delete this[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1696 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1697 |
// Let others now this property has been removed. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1698 |
this._triggerChange(prop, "remove", undefined, current); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1699 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1700 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1701 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1702 |
// Reads a property from the `object`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1703 |
_get: function(attr) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1704 |
var value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1705 |
// Handles the case of a key having a `.` in its name |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1706 |
if (typeof attr === 'string' && !! ~attr.indexOf('.')) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1707 |
// Attempt to get the value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1708 |
value = this.__get(attr); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1709 |
// For keys with a `.` in them, value will be defined |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1710 |
if (value !== undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1711 |
return value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1712 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1713 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1714 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1715 |
// Otherwise we have to dig deeper into the Map to get the value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1716 |
// First, break up the attr (`"foo.bar"`) into parts like `["foo","bar"]`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1717 |
var parts = can.Map.helpers.attrParts(attr), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1718 |
// Then get the value of the first attr name (`"foo"`). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1719 |
current = this.__get(parts.shift()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1720 |
// If there are other attributes to read... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1721 |
return parts.length ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1722 |
// and current has a value... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1723 |
current ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1724 |
// then lookup the remaining attrs on current |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1725 |
current._get(parts) : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1726 |
// or if there's no current, return undefined. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1727 |
undefined : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1728 |
// If there are no more parts, return current. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1729 |
current; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1730 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1731 |
// Reads a property directly if an `attr` is provided, otherwise |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1732 |
// returns the "real" data object itself. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1733 |
__get: function(attr) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1734 |
if (attr) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1735 |
// If property is a compute return the result, otherwise get the value directly |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1736 |
if (this._computedBindings[attr]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1737 |
return this[attr](); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1738 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1739 |
return this._data[attr]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1740 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1741 |
// If not property is provided, return entire `_data` object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1742 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1743 |
return this._data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1744 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1745 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1746 |
// converts the value into an observable if needed |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1747 |
__type: function(value, prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1748 |
// If we are getting an object. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1749 |
if (!(value instanceof can.Map) && can.Map.helpers.canMakeObserve(value)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1750 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1751 |
var cached = getMapFromObject(value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1752 |
if (cached) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1753 |
return cached; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1754 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1755 |
if (can.isArray(value)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1756 |
var List = can.List; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1757 |
return new List(value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1758 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1759 |
var Map = this.constructor.Map || can.Map; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1760 |
return new Map(value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1761 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1762 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1763 |
return value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1764 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1765 |
// Sets `attr` prop as value on this object where. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1766 |
// `attr` - Is a string of properties or an array of property values. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1767 |
// `value` - The raw value to set. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1768 |
_set: function(attr, value, keepKey) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1769 |
// Convert `attr` to attr parts (if it isn't already). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1770 |
var parts = can.Map.helpers.attrParts(attr, keepKey), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1771 |
// The immediate prop we are setting. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1772 |
prop = parts.shift(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1773 |
// We only need to get the current value if we are not in init. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1774 |
current = this._init ? undefined : this.__get(prop); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1775 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1776 |
if (parts.length && Map.helpers.isObservable(current)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1777 |
// If we have an `object` and remaining parts that `object` should set it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1778 |
current._set(parts, value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1779 |
} else if (!parts.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1780 |
// We're in "real" set territory. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1781 |
if (this.__convert) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1782 |
//Convert if there is a converter |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1783 |
value = this.__convert(prop, value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1784 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1785 |
this.__set(prop, this.__type(value, prop), current); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1786 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1787 |
throw "can.Map: Object does not exist"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1788 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1789 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1790 |
__set: function(prop, value, current) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1791 |
// TODO: Check if value is object and transform. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1792 |
// Don't do anything if the value isn't changing. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1793 |
if (value !== current) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1794 |
// Check if we are adding this for the first time -- |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1795 |
// if we are, we need to create an `add` event. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1796 |
var changeType = this.__get() |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1797 |
.hasOwnProperty(prop) ? "set" : "add"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1798 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1799 |
// Set the value on `_data` and hook it up to send event. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1800 |
this.___set(prop, this.constructor._bubble.set(this, prop, value, current)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1801 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1802 |
// `batchTrigger` the change event. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1803 |
this._triggerChange(prop, changeType, value, current); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1804 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1805 |
// If we can stop listening to our old value, do it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1806 |
if (current) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1807 |
this.constructor._bubble.teardownFromParent(this, current); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1808 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1809 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1810 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1811 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1812 |
// Directly sets a property on this `object`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1813 |
___set: function(prop, val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1814 |
if (this._computedBindings[prop]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1815 |
this[prop](val); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1816 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1817 |
this._data[prop] = val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1818 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1819 |
// Add property directly for easy writing. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1820 |
// Check if its on the `prototype` so we don't overwrite methods like `attrs`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1821 |
if (!can.isFunction(this.constructor.prototype[prop]) && !this._computedBindings[prop]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1822 |
this[prop] = val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1823 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1824 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1825 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1826 |
bind: function(eventName, handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1827 |
var computedBinding = this._computedBindings && this._computedBindings[eventName]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1828 |
if (computedBinding) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1829 |
// The first time we bind to this computed property we |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1830 |
// initialize `count` and `batchTrigger` the change event. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1831 |
if (!computedBinding.count) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1832 |
computedBinding.count = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1833 |
var self = this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1834 |
computedBinding.handler = function(ev, newVal, oldVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1835 |
can.batch.trigger(self, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1836 |
type: eventName, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1837 |
batchNum: ev.batchNum |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1838 |
}, [newVal, oldVal]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1839 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1840 |
this[eventName].bind("change", computedBinding.handler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1841 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1842 |
// Increment number of things listening to this computed property. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1843 |
computedBinding.count++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1844 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1845 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1846 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1847 |
// The first time we bind to this Map, `_bindsetup` will |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1848 |
// be called to setup child event bubbling. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1849 |
this.constructor._bubble.bind(this, eventName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1850 |
return can.bindAndSetup.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1851 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1852 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1853 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1854 |
unbind: function(eventName, handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1855 |
var computedBinding = this._computedBindings && this._computedBindings[eventName]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1856 |
if (computedBinding) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1857 |
// If there is only one listener, we unbind the change event handler |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1858 |
// and clean it up since no one is listening to this property any more. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1859 |
if (computedBinding.count === 1) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1860 |
computedBinding.count = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1861 |
this[eventName].unbind("change", computedBinding.handler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1862 |
delete computedBinding.handler; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1863 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1864 |
// Decrement number of things listening to this computed property |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1865 |
computedBinding.count--; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1866 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1867 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1868 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1869 |
this.constructor._bubble.unbind(this, eventName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1870 |
return can.unbindAndTeardown.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1871 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1872 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1873 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1874 |
serialize: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1875 |
return can.Map.helpers.serialize(this, 'serialize', {}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1876 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1877 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1878 |
_attrs: function(props, remove) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1879 |
if (props === undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1880 |
return Map.helpers.serialize(this, 'attr', {}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1881 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1882 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1883 |
props = can.simpleExtend({}, props); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1884 |
var prop, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1885 |
self = this, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1886 |
newVal; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1887 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1888 |
// Batch all of the change events until we are done. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1889 |
can.batch.start(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1890 |
// Merge current properties with the new ones. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1891 |
this.each(function(curVal, prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1892 |
// You can not have a _cid property; abort. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1893 |
if (prop === "_cid") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1894 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1895 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1896 |
newVal = props[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1897 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1898 |
// If we are merging, remove the property if it has no value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1899 |
if (newVal === undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1900 |
if (remove) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1901 |
self.removeAttr(prop); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1902 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1903 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1904 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1905 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1906 |
// Run converter if there is one |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1907 |
if (self.__convert) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1908 |
newVal = self.__convert(prop, newVal); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1909 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1910 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1911 |
// If we're dealing with models, we want to call _set to let converters run. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1912 |
if (Map.helpers.isObservable(newVal)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1913 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1914 |
self.__set(prop, self.__type(newVal, prop), curVal); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1915 |
// If its an object, let attr merge. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1916 |
} else if (Map.helpers.isObservable(curVal) && Map.helpers.canMakeObserve(newVal)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1917 |
curVal.attr(newVal, remove); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1918 |
// Otherwise just set. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1919 |
} else if (curVal !== newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1920 |
self.__set(prop, self.__type(newVal, prop), curVal); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1921 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1922 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1923 |
delete props[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1924 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1925 |
// Add remaining props. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1926 |
for (prop in props) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1927 |
// Ignore _cid. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1928 |
if (prop !== "_cid") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1929 |
newVal = props[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1930 |
this._set(prop, newVal, true); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1931 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1932 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1933 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1934 |
can.batch.stop(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1935 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1936 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1937 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1938 |
compute: function(prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1939 |
// If the property is a function, use it as the getter/setter |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1940 |
// otherwise, create a new compute that returns the value of a property on `this` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1941 |
if (can.isFunction(this.constructor.prototype[prop])) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1942 |
return can.compute(this[prop], this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1943 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1944 |
var reads = prop.split("."), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1945 |
last = reads.length - 1, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1946 |
options = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1947 |
args: [] |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1948 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1949 |
return can.compute(function(newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1950 |
if (arguments.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1951 |
can.compute.read(this, reads.slice(0, last)) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1952 |
.value.attr(reads[last], newVal); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1953 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1954 |
return can.compute.read(this, reads, options) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1955 |
.value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1956 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1957 |
}, this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1958 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1959 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1960 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1961 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1962 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1963 |
// Setup on/off aliases |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1964 |
Map.prototype.on = Map.prototype.bind; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1965 |
Map.prototype.off = Map.prototype.unbind; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1966 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1967 |
return Map; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1968 |
})(__m3, __m11, __m12, __m1, __m13); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1969 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1970 |
// ## can/list/list.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1971 |
var __m14 = (function(can, Map, bubble) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1972 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1973 |
// Helpers for `observable` lists. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1974 |
var splice = [].splice, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1975 |
// test if splice works correctly |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1976 |
spliceRemovesProps = (function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1977 |
// IE's splice doesn't remove properties |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1978 |
var obj = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1979 |
0: "a", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1980 |
length: 1 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1981 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1982 |
splice.call(obj, 0, 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1983 |
return !obj[0]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1984 |
})(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1985 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1986 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1987 |
var list = Map.extend( |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1988 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1989 |
{ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1990 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1991 |
Map: Map |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1992 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1993 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1994 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1995 |
{ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1996 |
setup: function(instances, options) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1997 |
this.length = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1998 |
can.cid(this, ".map"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1999 |
this._init = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2000 |
this._setupComputes(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2001 |
instances = instances || []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2002 |
var teardownMapping; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2003 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2004 |
if (can.isDeferred(instances)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2005 |
this.replace(instances); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2006 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2007 |
teardownMapping = instances.length && can.Map.helpers.addToMap(instances, this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2008 |
this.push.apply(this, can.makeArray(instances || [])); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2009 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2010 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2011 |
if (teardownMapping) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2012 |
teardownMapping(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2013 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2014 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2015 |
// this change needs to be ignored |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2016 |
this.bind('change', can.proxy(this._changes, this)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2017 |
can.simpleExtend(this, options); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2018 |
delete this._init; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2019 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2020 |
_triggerChange: function(attr, how, newVal, oldVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2021 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2022 |
Map.prototype._triggerChange.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2023 |
// `batchTrigger` direct add and remove events... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2024 |
var index = +attr; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2025 |
// Make sure this is not nested and not an expando |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2026 |
if (!~attr.indexOf('.') && !isNaN(index)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2027 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2028 |
if (how === 'add') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2029 |
can.batch.trigger(this, how, [newVal, index]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2030 |
can.batch.trigger(this, 'length', [this.length]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2031 |
} else if (how === 'remove') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2032 |
can.batch.trigger(this, how, [oldVal, index]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2033 |
can.batch.trigger(this, 'length', [this.length]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2034 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2035 |
can.batch.trigger(this, how, [newVal, index]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2036 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2037 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2038 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2039 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2040 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2041 |
__get: function(attr) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2042 |
if (attr) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2043 |
if (this[attr] && this[attr].isComputed && can.isFunction(this.constructor.prototype[attr])) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2044 |
return this[attr](); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2045 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2046 |
return this[attr]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2047 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2048 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2049 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2050 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2051 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2052 |
___set: function(attr, val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2053 |
this[attr] = val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2054 |
if (+attr >= this.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2055 |
this.length = (+attr + 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2056 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2057 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2058 |
_remove: function(prop, current) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2059 |
// if removing an expando property |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2060 |
if (isNaN(+prop)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2061 |
delete this[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2062 |
this._triggerChange(prop, "remove", undefined, current); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2063 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2064 |
this.splice(prop, 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2065 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2066 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2067 |
_each: function(callback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2068 |
var data = this.__get(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2069 |
for (var i = 0; i < data.length; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2070 |
callback(data[i], i); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2071 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2072 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2073 |
// Returns the serialized form of this list. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2074 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2075 |
serialize: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2076 |
return Map.helpers.serialize(this, 'serialize', []); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2077 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2078 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2079 |
splice: function(index, howMany) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2080 |
var args = can.makeArray(arguments), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2081 |
i; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2082 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2083 |
for (i = 2; i < args.length; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2084 |
args[i] = bubble.set(this, i, this.__type(args[i], i)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2085 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2086 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2087 |
if (howMany === undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2088 |
howMany = args[1] = this.length - index; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2089 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2090 |
var removed = splice.apply(this, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2091 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2092 |
if (!spliceRemovesProps) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2093 |
for (i = this.length; i < removed.length + this.length; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2094 |
delete this[i]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2095 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2096 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2097 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2098 |
can.batch.start(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2099 |
if (howMany > 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2100 |
this._triggerChange("" + index, "remove", undefined, removed); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2101 |
bubble.removeMany(this, removed); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2102 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2103 |
if (args.length > 2) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2104 |
this._triggerChange("" + index, "add", args.slice(2), removed); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2105 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2106 |
can.batch.stop(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2107 |
return removed; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2108 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2109 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2110 |
_attrs: function(items, remove) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2111 |
if (items === undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2112 |
return Map.helpers.serialize(this, 'attr', []); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2113 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2114 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2115 |
// Create a copy. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2116 |
items = can.makeArray(items); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2117 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2118 |
can.batch.start(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2119 |
this._updateAttrs(items, remove); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2120 |
can.batch.stop(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2121 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2122 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2123 |
_updateAttrs: function(items, remove) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2124 |
var len = Math.min(items.length, this.length); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2125 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2126 |
for (var prop = 0; prop < len; prop++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2127 |
var curVal = this[prop], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2128 |
newVal = items[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2129 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2130 |
if (Map.helpers.isObservable(curVal) && Map.helpers.canMakeObserve(newVal)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2131 |
curVal.attr(newVal, remove); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2132 |
//changed from a coercion to an explicit |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2133 |
} else if (curVal !== newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2134 |
this._set(prop, newVal); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2135 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2136 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2137 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2138 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2139 |
if (items.length > this.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2140 |
// Add in the remaining props. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2141 |
this.push.apply(this, items.slice(this.length)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2142 |
} else if (items.length < this.length && remove) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2143 |
this.splice(items.length); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2144 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2145 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2146 |
}), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2147 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2148 |
// Converts to an `array` of arguments. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2149 |
getArgs = function(args) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2150 |
return args[0] && can.isArray(args[0]) ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2151 |
args[0] : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2152 |
can.makeArray(args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2153 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2154 |
// Create `push`, `pop`, `shift`, and `unshift` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2155 |
can.each({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2156 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2157 |
push: "length", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2158 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2159 |
unshift: 0 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2160 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2161 |
// Adds a method |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2162 |
// `name` - The method name. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2163 |
// `where` - Where items in the `array` should be added. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2164 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2165 |
function(where, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2166 |
var orig = [][name]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2167 |
list.prototype[name] = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2168 |
// Get the items being added. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2169 |
var args = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2170 |
// Where we are going to add items. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2171 |
len = where ? this.length : 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2172 |
i = arguments.length, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2173 |
res, val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2174 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2175 |
// Go through and convert anything to an `map` that needs to be converted. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2176 |
while (i--) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2177 |
val = arguments[i]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2178 |
args[i] = bubble.set(this, i, this.__type(val, i)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2179 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2180 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2181 |
// Call the original method. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2182 |
res = orig.apply(this, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2183 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2184 |
if (!this.comparator || args.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2185 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2186 |
this._triggerChange("" + len, "add", args, undefined); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2187 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2188 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2189 |
return res; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2190 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2191 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2192 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2193 |
can.each({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2194 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2195 |
pop: "length", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2196 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2197 |
shift: 0 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2198 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2199 |
// Creates a `remove` type method |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2200 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2201 |
function(where, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2202 |
list.prototype[name] = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2203 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2204 |
var args = getArgs(arguments), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2205 |
len = where && this.length ? this.length - 1 : 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2206 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2207 |
var res = [][name].apply(this, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2208 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2209 |
// Create a change where the args are |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2210 |
// `len` - Where these items were removed. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2211 |
// `remove` - Items removed. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2212 |
// `undefined` - The new values (there are none). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2213 |
// `res` - The old, removed values (should these be unbound). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2214 |
this._triggerChange("" + len, "remove", undefined, [res]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2215 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2216 |
if (res && res.unbind) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2217 |
bubble.remove(this, res); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2218 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2219 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2220 |
return res; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2221 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2222 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2223 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2224 |
can.extend(list.prototype, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2225 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2226 |
indexOf: function(item, fromIndex) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2227 |
this.attr('length'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2228 |
return can.inArray(item, this, fromIndex); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2229 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2230 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2231 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2232 |
join: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2233 |
return [].join.apply(this.attr(), arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2234 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2235 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2236 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2237 |
reverse: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2238 |
var list = can.makeArray([].reverse.call(this)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2239 |
this.replace(list); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2240 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2241 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2242 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2243 |
slice: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2244 |
var temp = Array.prototype.slice.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2245 |
return new this.constructor(temp); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2246 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2247 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2248 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2249 |
concat: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2250 |
var args = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2251 |
can.each(can.makeArray(arguments), function(arg, i) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2252 |
args[i] = arg instanceof can.List ? arg.serialize() : arg; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2253 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2254 |
return new this.constructor(Array.prototype.concat.apply(this.serialize(), args)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2255 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2256 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2257 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2258 |
forEach: function(cb, thisarg) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2259 |
return can.each(this, cb, thisarg || this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2260 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2261 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2262 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2263 |
replace: function(newList) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2264 |
if (can.isDeferred(newList)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2265 |
newList.then(can.proxy(this.replace, this)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2266 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2267 |
this.splice.apply(this, [0, this.length].concat(can.makeArray(newList || []))); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2268 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2269 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2270 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2271 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2272 |
filter: function(callback, thisArg) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2273 |
var filteredList = new can.List(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2274 |
self = this, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2275 |
filtered; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2276 |
this.each(function(item, index, list) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2277 |
filtered = callback.call(thisArg | self, item, index, self); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2278 |
if (filtered) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2279 |
filteredList.push(item); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2280 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2281 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2282 |
return filteredList; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2283 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2284 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2285 |
can.List = Map.List = list; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2286 |
return can.List; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2287 |
})(__m3, __m10, __m12); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2288 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2289 |
// ## can/compute/compute.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2290 |
var __m15 = (function(can, bind) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2291 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2292 |
// ## Reading Helpers |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2293 |
// The following methods are used to call a function that relies on |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2294 |
// observable data and to track the observable events which should |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2295 |
// be listened to when changes occur. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2296 |
// To do this, [`can.__reading(observable, event)`](#can-__reading) is called to |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2297 |
// "broadcast" the corresponding event on each read. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2298 |
// ### Observed |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2299 |
// An "Observed" is an object of observable objects and events that |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2300 |
// a function relies on. These objects and events must be listened to |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2301 |
// in order to determine when to check a function for updates. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2302 |
// This looks like the following: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2303 |
// { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2304 |
// "map1|first": {obj: map, event: "first"}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2305 |
// "map1|last" : {obj: map, event: "last"} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2306 |
// } |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2307 |
// Each object-event pair is mapped so no duplicates will be listed. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2308 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2309 |
// ### State |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2310 |
// `can.__read` may call a function that calls `can.__read` again. For |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2311 |
// example, a compute can read another compute. To track each compute's |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2312 |
// `Observed` object (containing observable objects and events), we maintain |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2313 |
// a stack of Observed values for each call to `__read`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2314 |
var stack = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2315 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2316 |
// ### can.__read |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2317 |
// With a given function and context, calls the function |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2318 |
// and returns the resulting value of the function as well |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2319 |
// as the observable properties and events that were read. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2320 |
can.__read = function(func, self) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2321 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2322 |
// Add an object that `can.__read` will write to. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2323 |
stack.push({}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2324 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2325 |
var value = func.call(self); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2326 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2327 |
// Example return value: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2328 |
// `{value: 100, observed: Observed}` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2329 |
return { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2330 |
value: value, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2331 |
observed: stack.pop() |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2332 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2333 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2334 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2335 |
// ### can.__reading |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2336 |
// When an observable value is read, it must call `can.__reading` to |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2337 |
// broadcast which object and event should be listened to. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2338 |
can.__reading = function(obj, event) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2339 |
// Add the observable object and the event |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2340 |
// that was read to the `Observed` object on |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2341 |
// the stack. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2342 |
if (stack.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2343 |
stack[stack.length - 1][obj._cid + '|' + event] = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2344 |
obj: obj, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2345 |
event: event + "" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2346 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2347 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2348 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2349 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2350 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2351 |
// ### can.__clearReading |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2352 |
// Clears and returns the current observables. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2353 |
// This can be used to access a value without |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2354 |
// it being handled as a regular `read`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2355 |
can.__clearReading = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2356 |
if (stack.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2357 |
var ret = stack[stack.length - 1]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2358 |
stack[stack.length - 1] = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2359 |
return ret; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2360 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2361 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2362 |
// Specifies current observables. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2363 |
can.__setReading = function(o) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2364 |
if (stack.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2365 |
stack[stack.length - 1] = o; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2366 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2367 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2368 |
can.__addReading = function(o) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2369 |
if (stack.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2370 |
can.simpleExtend(stack[stack.length - 1], o); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2371 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2372 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2373 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2374 |
// ## Section Name |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2375 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2376 |
// ### getValueAndBind |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2377 |
// Calls a function and sets up bindings to call `onchanged` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2378 |
// when events from its "Observed" object are triggered. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2379 |
// Removes bindings from `oldObserved` that are no longer needed. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2380 |
// - func - the function to call. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2381 |
// - context - the `this` of the function. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2382 |
// - oldObserved - an object that contains what has already been bound to |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2383 |
// - onchanged - the function to call when any change occurs |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2384 |
var getValueAndBind = function(func, context, oldObserved, onchanged) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2385 |
// Call the function, get the value as well as the observed objects and events |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2386 |
var info = can.__read(func, context), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2387 |
// The objects-event pairs that must be bound to |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2388 |
newObserveSet = info.observed, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2389 |
// A flag that is used to determine if an event is already being observed. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2390 |
obEv, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2391 |
name; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2392 |
// Go through what needs to be observed. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2393 |
for (name in newObserveSet) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2394 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2395 |
if (oldObserved[name]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2396 |
// After binding is set up, values |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2397 |
// in `oldObserved` will be unbound. So if a name |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2398 |
// has already be observed, remove from `oldObserved` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2399 |
// to prevent this. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2400 |
delete oldObserved[name]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2401 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2402 |
// If current name has not been observed, listen to it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2403 |
obEv = newObserveSet[name]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2404 |
obEv.obj.bind(obEv.event, onchanged); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2405 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2406 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2407 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2408 |
// Iterate through oldObserved, looking for observe/attributes |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2409 |
// that are no longer being bound and unbind them. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2410 |
for (name in oldObserved) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2411 |
obEv = oldObserved[name]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2412 |
obEv.obj.unbind(obEv.event, onchanged); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2413 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2414 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2415 |
return info; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2416 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2417 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2418 |
// ### updateOnChange |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2419 |
// Fires a change event when a compute's value changes |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2420 |
var updateOnChange = function(compute, newValue, oldValue, batchNum) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2421 |
// Only trigger event when value has changed |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2422 |
if (newValue !== oldValue) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2423 |
can.batch.trigger(compute, batchNum ? { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2424 |
type: "change", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2425 |
batchNum: batchNum |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2426 |
} : 'change', [ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2427 |
newValue, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2428 |
oldValue |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2429 |
]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2430 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2431 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2432 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2433 |
// ###setupComputeHandlers |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2434 |
// Sets up handlers for a compute. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2435 |
// - compute - the compute to set up handlers for |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2436 |
// - func - the getter/setter function for the compute |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2437 |
// - context - the `this` for the compute |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2438 |
// - setCachedValue - function for setting cached value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2439 |
// Returns an object with `on` and `off` functions. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2440 |
var setupComputeHandlers = function(compute, func, context, setCachedValue) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2441 |
var readInfo, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2442 |
onchanged, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2443 |
batchNum; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2444 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2445 |
return { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2446 |
// Set up handler for when the compute changes |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2447 |
on: function(updater) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2448 |
if (!onchanged) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2449 |
onchanged = function(ev) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2450 |
if (compute.bound && (ev.batchNum === undefined || ev.batchNum !== batchNum)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2451 |
// Keep the old value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2452 |
var oldValue = readInfo.value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2453 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2454 |
// Get the new value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2455 |
readInfo = getValueAndBind(func, context, readInfo.observed, onchanged); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2456 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2457 |
// Call the updater with old and new values |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2458 |
updater(readInfo.value, oldValue, ev.batchNum); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2459 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2460 |
batchNum = batchNum = ev.batchNum; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2461 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2462 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2463 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2464 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2465 |
readInfo = getValueAndBind(func, context, {}, onchanged); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2466 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2467 |
setCachedValue(readInfo.value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2468 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2469 |
compute.hasDependencies = !can.isEmptyObject(readInfo.observed); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2470 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2471 |
// Remove handler for the compute |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2472 |
off: function(updater) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2473 |
for (var name in readInfo.observed) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2474 |
var ob = readInfo.observed[name]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2475 |
ob.obj.unbind(ob.event, onchanged); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2476 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2477 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2478 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2479 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2480 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2481 |
// ###isObserve |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2482 |
// Checks if an object is observable |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2483 |
var isObserve = function(obj) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2484 |
return obj instanceof can.Map || obj && obj.__get; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2485 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2486 |
// Instead of calculating whether anything is listening every time, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2487 |
// use a function to do nothing (which may be overwritten) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2488 |
k = function() {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2489 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2490 |
// ## Creating a can.compute |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2491 |
// A `can.compute` can be created by |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2492 |
// - [Specifying the getterSeter function](#specifying-gettersetter-function) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2493 |
// - [Observing a property of an object](#observing-a-property-of-an-object) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2494 |
// - [Specifying an initial value and a setter function](#specifying-an-initial-value-and-a-setter) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2495 |
// - [Specifying an initial value and how to read, update, and listen to changes](#specifying-an-initial-value-and-a-settings-object) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2496 |
// - [Simply specifying an initial value](#specifying-only-a-value) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2497 |
can.compute = function(getterSetter, context, eventName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2498 |
// ### Setting up |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2499 |
// Do nothing if getterSetter is already a compute |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2500 |
if (getterSetter && getterSetter.isComputed) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2501 |
return getterSetter; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2502 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2503 |
// The computed object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2504 |
var computed, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2505 |
// The following functions are overwritten depending on how compute() is called |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2506 |
// A method to set up listening |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2507 |
on = k, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2508 |
// A method to teardown listening |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2509 |
off = k, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2510 |
// Current cached value (valid only when bound is true) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2511 |
value, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2512 |
// How the value is read by default |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2513 |
get = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2514 |
return value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2515 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2516 |
// How the value is set by default |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2517 |
set = function(newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2518 |
value = newVal; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2519 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2520 |
setCached = set, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2521 |
// Save arguments for cloning |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2522 |
args = can.makeArray(arguments), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2523 |
// updater for when value is changed |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2524 |
updater = function(newValue, oldValue, batchNum) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2525 |
setCached(newValue); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2526 |
updateOnChange(computed, newValue, oldValue, batchNum); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2527 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2528 |
// the form of the arguments |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2529 |
form; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2530 |
computed = function(newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2531 |
// If the computed function is called with arguments, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2532 |
// a value should be set |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2533 |
if (arguments.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2534 |
// Save a reference to the old value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2535 |
var old = value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2536 |
// Setter may return the value if setter |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2537 |
// is for a value maintained exclusively by this compute. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2538 |
var setVal = set.call(context, newVal, old); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2539 |
// If the computed function has dependencies, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2540 |
// return the current value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2541 |
if (computed.hasDependencies) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2542 |
return get.call(context); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2543 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2544 |
// Setting may not fire a change event, in which case |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2545 |
// the value must be read |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2546 |
if (setVal === undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2547 |
value = get.call(context); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2548 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2549 |
value = setVal; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2550 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2551 |
// Fire the change |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2552 |
updateOnChange(computed, value, old); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2553 |
return value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2554 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2555 |
// Another compute may bind to this `computed` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2556 |
if (stack.length && computed.canReadForChangeEvent !== false) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2557 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2558 |
// Tell the compute to listen to change on this computed |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2559 |
// Use `can.__reading` to allow other compute to listen |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2560 |
// for a change on this `computed` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2561 |
can.__reading(computed, 'change'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2562 |
// We are going to bind on this compute. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2563 |
// If we are not bound, we should bind so that |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2564 |
// we don't have to re-read to get the value of this compute. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2565 |
if (!computed.bound) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2566 |
can.compute.temporarilyBind(computed); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2567 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2568 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2569 |
// If computed is bound, use the cached value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2570 |
if (computed.bound) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2571 |
return value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2572 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2573 |
return get.call(context); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2574 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2575 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2576 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2577 |
// ###Specifying getterSetter function |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2578 |
// If `can.compute` is [called with a getterSetter function](http://canjs.com/docs/can.compute.html#sig_can_compute_getterSetter__context__), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2579 |
// override set and get |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2580 |
if (typeof getterSetter === 'function') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2581 |
// `can.compute(getterSetter, [context])` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2582 |
set = getterSetter; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2583 |
get = getterSetter; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2584 |
computed.canReadForChangeEvent = eventName === false ? false : true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2585 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2586 |
var handlers = setupComputeHandlers(computed, getterSetter, context || this, setCached); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2587 |
on = handlers.on; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2588 |
off = handlers.off; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2589 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2590 |
// ###Observing a property of an object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2591 |
// If `can.compute` is called with an |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2592 |
// [object, property name, and optional event name](http://canjs.com/docs/can.compute.html#sig_can_compute_object_propertyName__eventName__), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2593 |
// create a compute from a property of an object. This allows the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2594 |
// creation of a compute on objects that can be listened to with [`can.bind`](http://canjs.com/docs/can.bind.html) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2595 |
} else if (context) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2596 |
if (typeof context === 'string') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2597 |
// `can.compute(obj, "propertyName", [eventName])` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2598 |
var propertyName = context, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2599 |
isObserve = getterSetter instanceof can.Map; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2600 |
if (isObserve) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2601 |
computed.hasDependencies = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2602 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2603 |
// If object is observable, `attr` will be used |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2604 |
// for getting and setting. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2605 |
get = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2606 |
if (isObserve) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2607 |
return getterSetter.attr(propertyName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2608 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2609 |
return getterSetter[propertyName]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2610 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2611 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2612 |
set = function(newValue) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2613 |
if (isObserve) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2614 |
getterSetter.attr(propertyName, newValue); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2615 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2616 |
getterSetter[propertyName] = newValue; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2617 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2618 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2619 |
var handler; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2620 |
on = function(update) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2621 |
handler = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2622 |
update(get(), value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2623 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2624 |
can.bind.call(getterSetter, eventName || propertyName, handler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2625 |
// use can.__read because |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2626 |
// we should not be indicating that some parent |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2627 |
// reads this property if it happens to be binding on it |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2628 |
value = can.__read(get) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2629 |
.value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2630 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2631 |
off = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2632 |
can.unbind.call(getterSetter, eventName || propertyName, handler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2633 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2634 |
// ###Specifying an initial value and a setter |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2635 |
// If `can.compute` is called with an [initial value and a setter function](http://canjs.com/docs/can.compute.html#sig_can_compute_initialValue_setter_newVal_oldVal__), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2636 |
// a compute that can adjust incoming values is set up. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2637 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2638 |
// `can.compute(initialValue, setter)` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2639 |
if (typeof context === 'function') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2640 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2641 |
value = getterSetter; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2642 |
set = context; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2643 |
context = eventName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2644 |
form = 'setter'; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2645 |
// ###Specifying an initial value and a settings object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2646 |
// If `can.compute` is called with an [initial value and optionally a settings object](http://canjs.com/docs/can.compute.html#sig_can_compute_initialValue__settings__), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2647 |
// a can.compute is created that can optionally specify how to read, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2648 |
// update, and listen to changes in dependent values. This form of |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2649 |
// can.compute can be used to derive a compute that derives its |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2650 |
// value from any source |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2651 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2652 |
// `can.compute(initialValue,{get:, set:, on:, off:})` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2653 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2654 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2655 |
value = getterSetter; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2656 |
var options = context, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2657 |
oldUpdater = updater; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2658 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2659 |
context = options.context || options; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2660 |
get = options.get || get; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2661 |
set = options.set || function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2662 |
return value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2663 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2664 |
// This is a "hack" to allow async computes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2665 |
if (options.fn) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2666 |
var fn = options.fn, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2667 |
data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2668 |
// make sure get is called with the newVal, but not setter |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2669 |
get = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2670 |
return fn.call(context, value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2671 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2672 |
// Check the number of arguments the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2673 |
// async function takes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2674 |
if (fn.length === 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2675 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2676 |
data = setupComputeHandlers(computed, fn, context, setCached); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2677 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2678 |
} else if (fn.length === 1) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2679 |
data = setupComputeHandlers(computed, function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2680 |
return fn.call(context, value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2681 |
}, context, setCached); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2682 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2683 |
updater = function(newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2684 |
if (newVal !== undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2685 |
oldUpdater(newVal, value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2686 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2687 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2688 |
data = setupComputeHandlers(computed, function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2689 |
var res = fn.call(context, value, function(newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2690 |
oldUpdater(newVal, value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2691 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2692 |
// If undefined is returned, don't update the value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2693 |
return res !== undefined ? res : value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2694 |
}, context, setCached); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2695 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2696 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2697 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2698 |
on = data.on; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2699 |
off = data.off; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2700 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2701 |
updater = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2702 |
var newVal = get.call(context); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2703 |
oldUpdater(newVal, value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2704 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2705 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2706 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2707 |
on = options.on || on; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2708 |
off = options.off || off; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2709 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2710 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2711 |
// ###Specifying only a value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2712 |
// If can.compute is called with an initialValue only, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2713 |
// reads to this value can be observed. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2714 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2715 |
// `can.compute(initialValue)` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2716 |
value = getterSetter; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2717 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2718 |
can.cid(computed, 'compute'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2719 |
return can.simpleExtend(computed, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2720 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2721 |
isComputed: true, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2722 |
_bindsetup: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2723 |
this.bound = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2724 |
// Set up live-binding |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2725 |
// While binding, this should not count as a read |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2726 |
var oldReading = can.__clearReading(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2727 |
on.call(this, updater); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2728 |
// Restore "Observed" for reading |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2729 |
can.__setReading(oldReading); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2730 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2731 |
_bindteardown: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2732 |
off.call(this, updater); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2733 |
this.bound = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2734 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2735 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2736 |
bind: can.bindAndSetup, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2737 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2738 |
unbind: can.unbindAndTeardown, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2739 |
clone: function(context) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2740 |
if (context) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2741 |
if (form === 'setter') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2742 |
args[2] = context; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2743 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2744 |
args[1] = context; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2745 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2746 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2747 |
return can.compute.apply(can, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2748 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2749 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2750 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2751 |
// A list of temporarily bound computes |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2752 |
var computes, unbindComputes = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2753 |
for (var i = 0, len = computes.length; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2754 |
computes[i].unbind('change', k); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2755 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2756 |
computes = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2757 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2758 |
// Binds computes for a moment to retain their value and prevent caching |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2759 |
can.compute.temporarilyBind = function(compute) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2760 |
compute.bind('change', k); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2761 |
if (!computes) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2762 |
computes = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2763 |
setTimeout(unbindComputes, 10); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2764 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2765 |
computes.push(compute); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2766 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2767 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2768 |
// Whether a compute is truthy |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2769 |
can.compute.truthy = function(compute) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2770 |
return can.compute(function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2771 |
var res = compute(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2772 |
if (typeof res === 'function') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2773 |
res = res(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2774 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2775 |
return !!res; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2776 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2777 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2778 |
can.compute.async = function(initialValue, asyncComputer, context) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2779 |
return can.compute(initialValue, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2780 |
fn: asyncComputer, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2781 |
context: context |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2782 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2783 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2784 |
// {map: new can.Map({first: "Justin"})}, ["map","first"] |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2785 |
can.compute.read = function(parent, reads, options) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2786 |
options = options || {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2787 |
// `cur` is the current value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2788 |
var cur = parent, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2789 |
type, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2790 |
// `prev` is the object we are reading from. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2791 |
prev, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2792 |
// `foundObs` did we find an observable. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2793 |
foundObs; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2794 |
for (var i = 0, readLength = reads.length; i < readLength; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2795 |
// Update what we are reading from. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2796 |
prev = cur; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2797 |
// Read from the compute. We can't read a property yet. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2798 |
if (prev && prev.isComputed) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2799 |
if (options.foundObservable) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2800 |
options.foundObservable(prev, i); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2801 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2802 |
prev = prev(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2803 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2804 |
// Look to read a property from something. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2805 |
if (isObserve(prev)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2806 |
if (!foundObs && options.foundObservable) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2807 |
options.foundObservable(prev, i); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2808 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2809 |
foundObs = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2810 |
// is it a method on the prototype? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2811 |
if (typeof prev[reads[i]] === 'function' && prev.constructor.prototype[reads[i]] === prev[reads[i]]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2812 |
// call that method |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2813 |
if (options.returnObserveMethods) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2814 |
cur = cur[reads[i]]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2815 |
} else if (reads[i] === 'constructor' && prev instanceof can.Construct) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2816 |
cur = prev[reads[i]]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2817 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2818 |
cur = prev[reads[i]].apply(prev, options.args || []); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2819 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2820 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2821 |
// use attr to get that value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2822 |
cur = cur.attr(reads[i]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2823 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2824 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2825 |
// just do the dot operator |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2826 |
cur = prev[reads[i]]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2827 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2828 |
type = typeof cur; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2829 |
// If it's a compute, get the compute's value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2830 |
// unless we are at the end of the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2831 |
if (cur && cur.isComputed && (!options.isArgument && i < readLength - 1)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2832 |
if (!foundObs && options.foundObservable) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2833 |
options.foundObservable(prev, i + 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2834 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2835 |
cur = cur(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2836 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2837 |
// If it's an anonymous function, execute as requested |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2838 |
else if (i < reads.length - 1 && type === 'function' && options.executeAnonymousFunctions && !(can.Construct && cur.prototype instanceof can.Construct)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2839 |
cur = cur(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2840 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2841 |
// if there are properties left to read, and we don't have an object, early exit |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2842 |
if (i < reads.length - 1 && (cur === null || type !== 'function' && type !== 'object')) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2843 |
if (options.earlyExit) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2844 |
options.earlyExit(prev, i, cur); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2845 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2846 |
// return undefined so we know this isn't the right value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2847 |
return { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2848 |
value: undefined, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2849 |
parent: prev |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2850 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2851 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2852 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2853 |
// handle an ending function |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2854 |
// unless it is a can.Construct-derived constructor |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2855 |
if (typeof cur === 'function' && !(can.Construct && cur.prototype instanceof can.Construct)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2856 |
if (options.isArgument) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2857 |
if (!cur.isComputed && options.proxyMethods !== false) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2858 |
cur = can.proxy(cur, prev); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2859 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2860 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2861 |
if (cur.isComputed && !foundObs && options.foundObservable) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2862 |
options.foundObservable(cur, i); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2863 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2864 |
cur = cur.call(prev); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2865 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2866 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2867 |
// if we don't have a value, exit early. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2868 |
if (cur === undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2869 |
if (options.earlyExit) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2870 |
options.earlyExit(prev, i - 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2871 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2872 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2873 |
return { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2874 |
value: cur, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2875 |
parent: prev |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2876 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2877 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2878 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2879 |
return can.compute; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2880 |
})(__m3, __m11, __m13); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2881 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2882 |
// ## can/model/model.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2883 |
var __m16 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2884 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2885 |
// ## model.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2886 |
// (Don't steal this file directly in your code.) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2887 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2888 |
// ## pipe |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2889 |
// `pipe` lets you pipe the results of a successful deferred |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2890 |
// through a function before resolving the deferred. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2891 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2892 |
var pipe = function(def, thisArg, func) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2893 |
// The piped result will be available through a new Deferred. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2894 |
var d = new can.Deferred(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2895 |
def.then(function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2896 |
var args = can.makeArray(arguments), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2897 |
success = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2898 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2899 |
try { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2900 |
// Pipe the results through the function. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2901 |
args[0] = func.apply(thisArg, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2902 |
} catch (e) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2903 |
success = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2904 |
// The function threw an error, so reject the Deferred. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2905 |
d.rejectWith(d, [e].concat(args)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2906 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2907 |
if (success) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2908 |
// Resolve the new Deferred with the piped value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2909 |
d.resolveWith(d, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2910 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2911 |
}, function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2912 |
// Pass on the rejection if the original Deferred never resolved. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2913 |
d.rejectWith(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2914 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2915 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2916 |
// `can.ajax` returns a Deferred with an abort method to halt the AJAX call. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2917 |
if (typeof def.abort === 'function') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2918 |
d.abort = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2919 |
return def.abort(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2920 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2921 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2922 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2923 |
// Return the new (piped) Deferred. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2924 |
return d; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2925 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2926 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2927 |
// ## modelNum |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2928 |
// When new model constructors are set up without a full name, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2929 |
// `modelNum` lets us name them uniquely (to keep track of them). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2930 |
modelNum = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2931 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2932 |
// ## getId |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2933 |
getId = function(inst) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2934 |
// `can.__reading` makes a note that `id` was just read. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2935 |
can.__reading(inst, inst.constructor.id); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2936 |
// Use `__get` instead of `attr` for performance. (But that means we have to remember to call `can.__reading`.) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2937 |
return inst.__get(inst.constructor.id); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2938 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2939 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2940 |
// ## ajax |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2941 |
// This helper method makes it easier to make an AJAX call from the configuration of the Model. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2942 |
ajax = function(ajaxOb, data, type, dataType, success, error) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2943 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2944 |
var params = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2945 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2946 |
// A string here would be something like `"GET /endpoint"`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2947 |
if (typeof ajaxOb === 'string') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2948 |
// Split on spaces to separate the HTTP method and the URL. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2949 |
var parts = ajaxOb.split(/\s+/); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2950 |
params.url = parts.pop(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2951 |
if (parts.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2952 |
params.type = parts.pop(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2953 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2954 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2955 |
// If the first argument is an object, just load it into `params`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2956 |
can.extend(params, ajaxOb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2957 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2958 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2959 |
// If the `data` argument is a plain object, copy it into `params`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2960 |
params.data = typeof data === "object" && !can.isArray(data) ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2961 |
can.extend(params.data || {}, data) : data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2962 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2963 |
// Substitute in data for any templated parts of the URL. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2964 |
params.url = can.sub(params.url, params.data, true); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2965 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2966 |
return can.ajax(can.extend({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2967 |
type: type || 'post', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2968 |
dataType: dataType || 'json', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2969 |
success: success, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2970 |
error: error |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2971 |
}, params)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2972 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2973 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2974 |
// ## makeRequest |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2975 |
// This function abstracts making the actual AJAX request away from the Model. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2976 |
makeRequest = function(modelObj, type, success, error, method) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2977 |
var args; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2978 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2979 |
// If `modelObj` is an Array, it it means we are coming from |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2980 |
// the queued request, and we're passing already-serialized data. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2981 |
if (can.isArray(modelObj)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2982 |
// In that case, modelObj's signature will be `[modelObj, serializedData]`, so we need to unpack it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2983 |
args = modelObj[1]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2984 |
modelObj = modelObj[0]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2985 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2986 |
// If we aren't supplied with serialized data, we'll make our own. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2987 |
args = modelObj.serialize(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2988 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2989 |
args = [args]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2990 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2991 |
var deferred, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2992 |
model = modelObj.constructor, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2993 |
jqXHR; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2994 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2995 |
// When calling `update` and `destroy`, the current ID needs to be the first parameter in the AJAX call. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2996 |
if (type === 'update' || type === 'destroy') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2997 |
args.unshift(getId(modelObj)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2998 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2999 |
jqXHR = model[type].apply(model, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3000 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3001 |
// Make sure that can.Model can react to the request before anything else does. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3002 |
deferred = pipe(jqXHR, modelObj, function(data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3003 |
// `method` is here because `"destroyed" !== "destroy" + "d"`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3004 |
// TODO: Do something smarter/more consistent here? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3005 |
modelObj[method || type + "d"](data, jqXHR); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3006 |
return modelObj; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3007 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3008 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3009 |
// Hook up `abort` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3010 |
if (jqXHR.abort) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3011 |
deferred.abort = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3012 |
jqXHR.abort(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3013 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3014 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3015 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3016 |
deferred.then(success, error); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3017 |
return deferred; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3018 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3019 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3020 |
initializers = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3021 |
// ## models |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3022 |
// Returns a function that, when handed a list of objects, makes them into models and returns a model list of them. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3023 |
// `prop` is the property on `instancesRawData` that has the array of objects in it (if it's not `data`). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3024 |
models: function(prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3025 |
return function(instancesRawData, oldList) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3026 |
// Increment reqs counter so new instances will be added to the store. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3027 |
// (This is cleaned up at the end of the method.) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3028 |
can.Model._reqs++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3029 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3030 |
// If there is no data, we can't really do anything with it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3031 |
if (!instancesRawData) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3032 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3033 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3034 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3035 |
// If the "raw" data is already a List, it's not raw. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3036 |
if (instancesRawData instanceof this.List) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3037 |
return instancesRawData; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3038 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3039 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3040 |
var self = this, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3041 |
// `tmp` will hold the models before we push them onto `modelList`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3042 |
tmp = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3043 |
// `ML` (see way below) is just `can.Model.List`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3044 |
ListClass = self.List || ML, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3045 |
modelList = oldList instanceof can.List ? oldList : new ListClass(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3046 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3047 |
// Check if we were handed an Array or a model list. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3048 |
rawDataIsArray = can.isArray(instancesRawData), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3049 |
rawDataIsList = instancesRawData instanceof ML, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3050 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3051 |
// Get the "plain" objects from the models from the list/array. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3052 |
raw = rawDataIsArray ? instancesRawData : ( |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3053 |
rawDataIsList ? instancesRawData.serialize() : can.getObject(prop || "data", instancesRawData)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3054 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3055 |
if (typeof raw === 'undefined') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3056 |
throw new Error('Could not get any raw data while converting using .models'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3057 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3058 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3059 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3060 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3061 |
// If there was anything left in the list we were given, get rid of it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3062 |
if (modelList.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3063 |
modelList.splice(0); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3064 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3065 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3066 |
// If we pushed these directly onto the list, it would cause a change event for each model. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3067 |
// So, we push them onto `tmp` first and then push everything at once, causing one atomic change event that contains all the models at once. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3068 |
can.each(raw, function(rawPart) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3069 |
tmp.push(self.model(rawPart)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3070 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3071 |
modelList.push.apply(modelList, tmp); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3072 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3073 |
// If there was other stuff on `instancesRawData`, let's transfer that onto `modelList` too. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3074 |
if (!rawDataIsArray) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3075 |
can.each(instancesRawData, function(val, prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3076 |
if (prop !== 'data') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3077 |
modelList.attr(prop, val); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3078 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3079 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3080 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3081 |
// Clean up the store on the next turn of the event loop. (`this` is a model constructor.) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3082 |
setTimeout(can.proxy(this._clean, this), 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3083 |
return modelList; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3084 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3085 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3086 |
// ## model |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3087 |
// Returns a function that, when handed a plain object, turns it into a model. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3088 |
// `prop` is the property on `attributes` that has the properties for the model in it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3089 |
model: function(prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3090 |
return function(attributes) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3091 |
// If there're no properties, there can be no model. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3092 |
if (!attributes) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3093 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3094 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3095 |
// If this object knows how to serialize, parse, or access itself, we'll use that instead. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3096 |
if (typeof attributes.serialize === 'function') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3097 |
attributes = attributes.serialize(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3098 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3099 |
if (this.parseModel) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3100 |
attributes = this.parseModel.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3101 |
} else if (prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3102 |
attributes = can.getObject(prop || "data", attributes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3103 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3104 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3105 |
var id = attributes[this.id], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3106 |
// 0 is a valid ID. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3107 |
model = (id || id === 0) && this.store[id] ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3108 |
// If this model is in the store already, just update it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3109 |
this.store[id].attr(attributes, this.removeAttr || false) : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3110 |
// Otherwise, we need a new model. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3111 |
new this(attributes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3112 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3113 |
return model; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3114 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3115 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3116 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3117 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3118 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3119 |
parserMaker = function(prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3120 |
return function(attributes) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3121 |
return prop ? can.getObject(prop || "data", attributes) : attributes; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3122 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3123 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3124 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3125 |
// ## parsers |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3126 |
// This object describes how to take the data from an AJAX request and prepare it for `models` and `model`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3127 |
// These functions are meant to be overwritten (if necessary) in an extended model constructor. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3128 |
parsers = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3129 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3130 |
parseModel: parserMaker, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3131 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3132 |
parseModels: parserMaker |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3133 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3134 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3135 |
// ## ajaxMethods |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3136 |
// This object describes how to make an AJAX request for each ajax method (`create`, `update`, etc.) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3137 |
// Each AJAX method is an object in `ajaxMethods` and can have the following properties: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3138 |
// - `url`: Which property on the model contains the default URL for this method. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3139 |
// - `type`: The default HTTP request method. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3140 |
// - `data`: A method that takes the arguments from `makeRequest` (see above) and returns a data object for use in the AJAX call. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3141 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3142 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3143 |
ajaxMethods = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3144 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3145 |
create: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3146 |
url: "_shortName", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3147 |
type: "post" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3148 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3149 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3150 |
update: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3151 |
// ## update.data |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3152 |
data: function(id, attrs) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3153 |
attrs = attrs || {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3154 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3155 |
// `this.id` is the property that represents the ID (and is usually `"id"`). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3156 |
var identity = this.id; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3157 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3158 |
// If the value of the property being used as the ID changed, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3159 |
// indicate that in the request and replace the current ID property. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3160 |
if (attrs[identity] && attrs[identity] !== id) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3161 |
attrs["new" + can.capitalize(id)] = attrs[identity]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3162 |
delete attrs[identity]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3163 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3164 |
attrs[identity] = id; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3165 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3166 |
return attrs; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3167 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3168 |
type: "put" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3169 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3170 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3171 |
destroy: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3172 |
type: 'delete', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3173 |
// ## destroy.data |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3174 |
data: function(id, attrs) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3175 |
attrs = attrs || {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3176 |
// `this.id` is the property that represents the ID (and is usually `"id"`). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3177 |
attrs.id = attrs[this.id] = id; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3178 |
return attrs; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3179 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3180 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3181 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3182 |
findAll: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3183 |
url: "_shortName" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3184 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3185 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3186 |
findOne: {} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3187 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3188 |
// ## ajaxMaker |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3189 |
// Takes a method defined just above and a string that describes how to call that method |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3190 |
// and makes a function that calls that method with the given data. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3191 |
// - `ajaxMethod`: The object defined above in `ajaxMethods`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3192 |
// - `str`: The string the configuration provided (such as `"/recipes.json"` for a `findAll` call). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3193 |
ajaxMaker = function(ajaxMethod, str) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3194 |
return function(data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3195 |
data = ajaxMethod.data ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3196 |
// If the AJAX method mentioned above has its own way of getting `data`, use that. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3197 |
ajaxMethod.data.apply(this, arguments) : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3198 |
// Otherwise, just use the data passed in. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3199 |
data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3200 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3201 |
// Make the AJAX call with the URL, data, and type indicated by the proper `ajaxMethod` above. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3202 |
return ajax(str || this[ajaxMethod.url || "_url"], data, ajaxMethod.type || "get"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3203 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3204 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3205 |
// ## createURLFromResource |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3206 |
// For each of the names (create, update, destroy, findOne, and findAll) use the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3207 |
// URL provided by the `resource` property. For example: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3208 |
// ToDo = can.Model.extend({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3209 |
// resource: "/todos" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3210 |
// }, {}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3211 |
// Will create a can.Model that is identical to: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3212 |
// ToDo = can.Model.extend({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3213 |
// findAll: "GET /todos", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3214 |
// findOne: "GET /todos/{id}", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3215 |
// create: "POST /todos", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3216 |
// update: "PUT /todos/{id}", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3217 |
// destroy: "DELETE /todos/{id}" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3218 |
// },{}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3219 |
// - `model`: the can.Model that has the resource property |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3220 |
// - `method`: a property from the ajaxMethod object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3221 |
createURLFromResource = function(model, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3222 |
if (!model.resource) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3223 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3224 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3225 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3226 |
var resource = model.resource.replace(/\/+$/, ""); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3227 |
if (name === "findAll" || name === "create") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3228 |
return resource; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3229 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3230 |
return resource + "/{" + model.id + "}"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3231 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3232 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3233 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3234 |
// # can.Model |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3235 |
// A can.Map that connects to a RESTful interface. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3236 |
can.Model = can.Map.extend({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3237 |
// `fullName` identifies the model type in debugging. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3238 |
fullName: "can.Model", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3239 |
_reqs: 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3240 |
// ## can.Model.setup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3241 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3242 |
setup: function(base, fullName, staticProps, protoProps) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3243 |
// Assume `fullName` wasn't passed. (`can.Model.extend({ ... }, { ... })`) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3244 |
// This is pretty usual. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3245 |
if (fullName !== "string") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3246 |
protoProps = staticProps; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3247 |
staticProps = fullName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3248 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3249 |
// Assume no static properties were passed. (`can.Model.extend({ ... })`) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3250 |
// This is really unusual for a model though, since there's so much configuration. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3251 |
if (!protoProps) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3252 |
protoProps = staticProps; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3253 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3254 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3255 |
// Create the model store here, in case someone wants to use can.Model without inheriting from it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3256 |
this.store = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3257 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3258 |
can.Map.setup.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3259 |
if (!can.Model) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3260 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3261 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3262 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3263 |
// `List` is just a regular can.Model.List that knows what kind of Model it's hooked up to. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3264 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3265 |
if (staticProps && staticProps.List) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3266 |
this.List = staticProps.List; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3267 |
this.List.Map = this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3268 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3269 |
this.List = base.List.extend({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3270 |
Map: this |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3271 |
}, {}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3272 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3273 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3274 |
var self = this, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3275 |
clean = can.proxy(this._clean, self); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3276 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3277 |
// Go through `ajaxMethods` and set up static methods according to their configurations. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3278 |
can.each(ajaxMethods, function(method, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3279 |
// Check the configuration for this ajaxMethod. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3280 |
// If the configuration isn't a function, it should be a string (like `"GET /endpoint"`) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3281 |
// or an object like `{url: "/endpoint", type: 'GET'}`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3282 |
if (!can.isFunction(self[name])) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3283 |
// Etiher way, `ajaxMaker` will turn it into a function for us. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3284 |
self[name] = ajaxMaker(method, self[name] ? self[name] : createURLFromResource(self, name)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3285 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3286 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3287 |
// There may also be a "maker" function (like `makeFindAll`) that alters the behavior of acting upon models |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3288 |
// by changing when and how the function we just made with `ajaxMaker` gets called. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3289 |
// For example, you might cache responses and only make a call when you don't have a cached response. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3290 |
if (self["make" + can.capitalize(name)]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3291 |
// Use the "maker" function to make the new "ajaxMethod" function. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3292 |
var newMethod = self["make" + can.capitalize(name)](self[name]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3293 |
// Replace the "ajaxMethod" function in the configuration with the new one. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3294 |
// (`_overwrite` just overwrites a property in a given Construct.) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3295 |
can.Construct._overwrite(self, base, name, function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3296 |
// Increment the numer of requests... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3297 |
can.Model._reqs++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3298 |
// ...make the AJAX call (and whatever else you're doing)... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3299 |
var def = newMethod.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3300 |
// ...and clean up the store. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3301 |
var then = def.then(clean, clean); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3302 |
// Pass along `abort` so you can still abort the AJAX call. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3303 |
then.abort = def.abort; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3304 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3305 |
return then; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3306 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3307 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3308 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3309 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3310 |
// Set up the methods that will set up `models` and `model`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3311 |
can.each(initializers, function(makeInitializer, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3312 |
var parseName = "parse" + can.capitalize(name), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3313 |
dataProperty = self[name]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3314 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3315 |
// If there was a different property to find the model's data in than `data`, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3316 |
// make `parseModel` and `parseModels` functions that look that up instead. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3317 |
if (typeof dataProperty === "string") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3318 |
can.Construct._overwrite(self, base, parseName, parsers[parseName](dataProperty)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3319 |
can.Construct._overwrite(self, base, name, makeInitializer(dataProperty)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3320 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3321 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3322 |
// If there was no prototype, or no `model` and no `parseModel`, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3323 |
// we'll have to create a `parseModel`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3324 |
else if (!protoProps || (!protoProps[name] && !protoProps[parseName])) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3325 |
can.Construct._overwrite(self, base, parseName, parsers[parseName]()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3326 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3327 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3328 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3329 |
// With the overridden parse methods, set up `models` and `model`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3330 |
can.each(parsers, function(makeParser, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3331 |
// If there was a different property to find the model's data in than `data`, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3332 |
// make `model` and `models` functions that look that up instead. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3333 |
if (typeof self[name] === "string") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3334 |
can.Construct._overwrite(self, base, name, makeParser(self[name])); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3335 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3336 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3337 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3338 |
// Make sure we have a unique name for this Model. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3339 |
if (self.fullName === "can.Model" || !self.fullName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3340 |
self.fullName = "Model" + (++modelNum); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3341 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3342 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3343 |
can.Model._reqs = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3344 |
this._url = this._shortName + "/{" + this.id + "}"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3345 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3346 |
_ajax: ajaxMaker, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3347 |
_makeRequest: makeRequest, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3348 |
// ## can.Model._clean |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3349 |
// `_clean` cleans up the model store after a request happens. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3350 |
_clean: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3351 |
can.Model._reqs--; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3352 |
// Don't clean up unless we have no pending requests. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3353 |
if (!can.Model._reqs) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3354 |
for (var id in this.store) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3355 |
// Delete all items in the store without any event bindings. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3356 |
if (!this.store[id]._bindings) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3357 |
delete this.store[id]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3358 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3359 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3360 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3361 |
return arguments[0]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3362 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3363 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3364 |
models: initializers.models("data"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3365 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3366 |
model: initializers.model() |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3367 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3368 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3369 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3370 |
{ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3371 |
// ## can.Model#setup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3372 |
setup: function(attrs) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3373 |
// Try to add things as early as possible to the store (#457). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3374 |
// This is the earliest possible moment, even before any properties are set. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3375 |
var id = attrs && attrs[this.constructor.id]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3376 |
if (can.Model._reqs && id != null) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3377 |
this.constructor.store[id] = this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3378 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3379 |
can.Map.prototype.setup.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3380 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3381 |
// ## can.Model#isNew |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3382 |
// Something is new if its ID is `null` or `undefined`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3383 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3384 |
isNew: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3385 |
var id = getId(this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3386 |
// 0 is a valid ID. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3387 |
// TODO: Why not `return id === null || id === undefined;`? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3388 |
return !(id || id === 0); // If `null` or `undefined` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3389 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3390 |
// ## can.Model#save |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3391 |
// `save` calls `create` or `update` as necessary, based on whether a model is new. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3392 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3393 |
save: function(success, error) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3394 |
return makeRequest(this, this.isNew() ? 'create' : 'update', success, error); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3395 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3396 |
// ## can.Model#destroy |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3397 |
// Acts like can.Map.destroy but it also makes an AJAX call. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3398 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3399 |
destroy: function(success, error) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3400 |
// If this model is new, don't make an AJAX call. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3401 |
// Instead, we have to construct the Deferred ourselves and return it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3402 |
if (this.isNew()) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3403 |
var self = this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3404 |
var def = can.Deferred(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3405 |
def.then(success, error); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3406 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3407 |
return def.done(function(data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3408 |
self.destroyed(data); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3409 |
}).resolve(self); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3410 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3411 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3412 |
// If it isn't new, though, go ahead and make a request. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3413 |
return makeRequest(this, 'destroy', success, error, 'destroyed'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3414 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3415 |
// ## can.Model#bind and can.Model#unbind |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3416 |
// These aren't actually implemented here, but their setup needs to be changed to account for the store. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3417 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3418 |
_bindsetup: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3419 |
this.constructor.store[this.__get(this.constructor.id)] = this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3420 |
return can.Map.prototype._bindsetup.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3421 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3422 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3423 |
_bindteardown: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3424 |
delete this.constructor.store[getId(this)]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3425 |
return can.Map.prototype._bindteardown.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3426 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3427 |
// Change the behavior of `___set` to account for the store. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3428 |
___set: function(prop, val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3429 |
can.Map.prototype.___set.call(this, prop, val); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3430 |
// If we add or change the ID, update the store accordingly. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3431 |
// TODO: shouldn't this also delete the record from the old ID in the store? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3432 |
if (prop === this.constructor.id && this._bindings) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3433 |
this.constructor.store[getId(this)] = this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3434 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3435 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3436 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3437 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3438 |
// Returns a function that knows how to prepare data from `findAll` or `findOne` calls. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3439 |
// `name` should be either `model` or `models`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3440 |
var makeGetterHandler = function(name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3441 |
var parseName = "parse" + can.capitalize(name); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3442 |
return function(data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3443 |
// If there's a `parse...` function, use its output. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3444 |
if (this[parseName]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3445 |
data = this[parseName].apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3446 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3447 |
// Run our maybe-parsed data through `model` or `models`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3448 |
return this[name](data); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3449 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3450 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3451 |
// Handle data returned from `create`, `update`, and `destroy` calls. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3452 |
createUpdateDestroyHandler = function(data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3453 |
if (this.parseModel) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3454 |
return this.parseModel.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3455 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3456 |
return this.model(data); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3457 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3458 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3459 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3460 |
var responseHandlers = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3461 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3462 |
makeFindAll: makeGetterHandler("models"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3463 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3464 |
makeFindOne: makeGetterHandler("model"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3465 |
makeCreate: createUpdateDestroyHandler, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3466 |
makeUpdate: createUpdateDestroyHandler |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3467 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3468 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3469 |
// Go through the response handlers and make the actual "make" methods. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3470 |
can.each(responseHandlers, function(method, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3471 |
can.Model[name] = function(oldMethod) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3472 |
return function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3473 |
var args = can.makeArray(arguments), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3474 |
// If args[1] is a function, we were only passed one argument before success and failure callbacks. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3475 |
oldArgs = can.isFunction(args[1]) ? args.splice(0, 1) : args.splice(0, 2), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3476 |
// Call the AJAX method (`findAll` or `update`, etc.) and pipe it through the response handler from above. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3477 |
def = pipe(oldMethod.apply(this, oldArgs), this, method); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3478 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3479 |
def.then(args[0], args[1]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3480 |
return def; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3481 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3482 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3483 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3484 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3485 |
// ## can.Model.created, can.Model.updated, and can.Model.destroyed |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3486 |
// Livecycle methods for models. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3487 |
can.each([ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3488 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3489 |
"created", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3490 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3491 |
"updated", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3492 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3493 |
"destroyed" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3494 |
], function(funcName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3495 |
// Each of these is pretty much the same, except for the events they trigger. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3496 |
can.Model.prototype[funcName] = function(attrs) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3497 |
var stub, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3498 |
constructor = this.constructor; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3499 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3500 |
// Update attributes if attributes have been passed |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3501 |
stub = attrs && typeof attrs === 'object' && this.attr(attrs.attr ? attrs.attr() : attrs); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3502 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3503 |
// triggers change event that bubble's like |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3504 |
// handler( 'change','1.destroyed' ). This is used |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3505 |
// to remove items on destroyed from Model Lists. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3506 |
// but there should be a better way. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3507 |
can.trigger(this, "change", funcName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3508 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3509 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3510 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3511 |
// Call event on the instance's Class |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3512 |
can.trigger(constructor, funcName, this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3513 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3514 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3515 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3516 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3517 |
// # can.Model.List |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3518 |
// Model Lists are just like `Map.List`s except that when their items are |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3519 |
// destroyed, they automatically get removed from the List. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3520 |
var ML = can.Model.List = can.List.extend({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3521 |
// ## can.Model.List.setup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3522 |
// On change or a nested named event, setup change bubbling. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3523 |
// On any other type of event, setup "destroyed" bubbling. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3524 |
_bubbleRule: function(eventName, list) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3525 |
return can.List._bubbleRule(eventName, list) || "destroyed"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3526 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3527 |
}, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3528 |
setup: function(params) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3529 |
// If there was a plain object passed to the List constructor, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3530 |
// we use those as parameters for an initial findAll. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3531 |
if (can.isPlainObject(params) && !can.isArray(params)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3532 |
can.List.prototype.setup.apply(this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3533 |
this.replace(this.constructor.Map.findAll(params)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3534 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3535 |
// Otherwise, set up the list like normal. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3536 |
can.List.prototype.setup.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3537 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3538 |
this._init = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3539 |
this.bind('destroyed', can.proxy(this._destroyed, this)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3540 |
delete this._init; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3541 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3542 |
_destroyed: function(ev, attr) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3543 |
if (/\w+/.test(attr)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3544 |
var index; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3545 |
while ((index = this.indexOf(ev.target)) > -1) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3546 |
this.splice(index, 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3547 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3548 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3549 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3550 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3551 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3552 |
return can.Model; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3553 |
})(__m3, __m10, __m14); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3554 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3555 |
// ## can/view/view.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3556 |
var __m17 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3557 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3558 |
var isFunction = can.isFunction, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3559 |
makeArray = can.makeArray, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3560 |
// Used for hookup `id`s. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3561 |
hookupId = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3562 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3563 |
// internal utility methods |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3564 |
// ------------------------ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3565 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3566 |
// ##### makeRenderer |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3567 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3568 |
var makeRenderer = function(textRenderer) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3569 |
var renderer = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3570 |
return $view.frag(textRenderer.apply(this, arguments)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3571 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3572 |
renderer.render = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3573 |
return textRenderer.apply(textRenderer, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3574 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3575 |
return renderer; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3576 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3577 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3578 |
// ##### checkText |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3579 |
// Makes sure there's a template, if not, have `steal` provide a warning. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3580 |
var checkText = function(text, url) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3581 |
if (!text.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3582 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3583 |
// _removed if not used as a steal module_ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3584 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3585 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3586 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3587 |
throw "can.view: No template or empty template:" + url; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3588 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3589 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3590 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3591 |
// ##### get |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3592 |
// get a deferred renderer for provided url |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3593 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3594 |
var get = function(obj, async) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3595 |
var url = typeof obj === 'string' ? obj : obj.url, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3596 |
suffix = (obj.engine && '.' + obj.engine) || url.match(/\.[\w\d]+$/), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3597 |
type, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3598 |
// If we are reading a script element for the content of the template, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3599 |
// `el` will be set to that script element. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3600 |
el, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3601 |
// A unique identifier for the view (used for caching). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3602 |
// This is typically derived from the element id or |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3603 |
// the url for the template. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3604 |
id; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3605 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3606 |
//If the url has a #, we assume we want to use an inline template |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3607 |
//from a script element and not current page's HTML |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3608 |
if (url.match(/^#/)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3609 |
url = url.substr(1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3610 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3611 |
// If we have an inline template, derive the suffix from the `text/???` part. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3612 |
// This only supports `<script>` tags. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3613 |
if (el = document.getElementById(url)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3614 |
suffix = '.' + el.type.match(/\/(x\-)?(.+)/)[2]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3615 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3616 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3617 |
// If there is no suffix, add one. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3618 |
if (!suffix && !$view.cached[url]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3619 |
url += suffix = $view.ext; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3620 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3621 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3622 |
// if the suffix was derived from the .match() operation, pluck out the first value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3623 |
if (can.isArray(suffix)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3624 |
suffix = suffix[0]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3625 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3626 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3627 |
// Convert to a unique and valid id. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3628 |
id = $view.toId(url); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3629 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3630 |
// If an absolute path, use `steal`/`require` to get it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3631 |
// You should only be using `//` if you are using an AMD loader like `steal` or `require` (not almond). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3632 |
if (url.match(/^\/\//)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3633 |
url = url.substr(2); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3634 |
url = !window.steal ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3635 |
url : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3636 |
steal.config() |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3637 |
.root.mapJoin("" + steal.id(url)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3638 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3639 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3640 |
// Localize for `require` (not almond) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3641 |
if (window.require) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3642 |
if (require.toUrl) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3643 |
url = require.toUrl(url); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3644 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3645 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3646 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3647 |
// Set the template engine type. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3648 |
type = $view.types[suffix]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3649 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3650 |
// If it is cached, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3651 |
if ($view.cached[id]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3652 |
// Return the cached deferred renderer. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3653 |
return $view.cached[id]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3654 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3655 |
// Otherwise if we are getting this from a `<script>` element. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3656 |
} else if (el) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3657 |
// Resolve immediately with the element's `innerHTML`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3658 |
return $view.registerView(id, el.innerHTML, type); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3659 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3660 |
// Make an ajax request for text. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3661 |
var d = new can.Deferred(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3662 |
can.ajax({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3663 |
async: async, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3664 |
url: url, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3665 |
dataType: 'text', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3666 |
error: function(jqXHR) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3667 |
checkText('', url); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3668 |
d.reject(jqXHR); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3669 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3670 |
success: function(text) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3671 |
// Make sure we got some text back. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3672 |
checkText(text, url); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3673 |
$view.registerView(id, text, type, d); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3674 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3675 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3676 |
return d; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3677 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3678 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3679 |
// ##### getDeferreds |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3680 |
// Gets an `array` of deferreds from an `object`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3681 |
// This only goes one level deep. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3682 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3683 |
var getDeferreds = function(data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3684 |
var deferreds = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3685 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3686 |
// pull out deferreds |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3687 |
if (can.isDeferred(data)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3688 |
return [data]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3689 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3690 |
for (var prop in data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3691 |
if (can.isDeferred(data[prop])) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3692 |
deferreds.push(data[prop]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3693 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3694 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3695 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3696 |
return deferreds; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3697 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3698 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3699 |
// ##### usefulPart |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3700 |
// Gets the useful part of a resolved deferred. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3701 |
// When a jQuery.when is resolved, it returns an array to each argument. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3702 |
// Reference ($.when)[https://api.jquery.com/jQuery.when/] |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3703 |
// This is for `model`s and `can.ajax` that resolve to an `array`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3704 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3705 |
var usefulPart = function(resolved) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3706 |
return can.isArray(resolved) && resolved[1] === 'success' ? resolved[0] : resolved; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3707 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3708 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3709 |
// #### can.view |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3710 |
//defines $view for internal use, can.template for backwards compatibility |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3711 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3712 |
var $view = can.view = can.template = function(view, data, helpers, callback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3713 |
// If helpers is a `function`, it is actually a callback. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3714 |
if (isFunction(helpers)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3715 |
callback = helpers; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3716 |
helpers = undefined; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3717 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3718 |
var result; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3719 |
// Get the result, if a renderer function is passed in, then we just use that to render the data |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3720 |
if (isFunction(view)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3721 |
result = view(data, helpers, callback); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3722 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3723 |
result = $view.renderAs("fragment", view, data, helpers, callback); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3724 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3725 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3726 |
return result; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3727 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3728 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3729 |
// can.view methods |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3730 |
// -------------------------- |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3731 |
can.extend($view, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3732 |
// ##### frag |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3733 |
// creates a fragment and hooks it up all at once |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3734 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3735 |
frag: function(result, parentNode) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3736 |
return $view.hookup($view.fragment(result), parentNode); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3737 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3738 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3739 |
// #### fragment |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3740 |
// this is used internally to create a document fragment, insert it,then hook it up |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3741 |
fragment: function(result) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3742 |
if (typeof result !== "string" && result.nodeType === 11) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3743 |
return result; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3744 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3745 |
var frag = can.buildFragment(result, document.body); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3746 |
// If we have an empty frag... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3747 |
if (!frag.childNodes.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3748 |
frag.appendChild(document.createTextNode('')); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3749 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3750 |
return frag; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3751 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3752 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3753 |
// ##### toId |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3754 |
// Convert a path like string into something that's ok for an `element` ID. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3755 |
toId: function(src) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3756 |
return can.map(src.toString() |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3757 |
.split(/\/|\./g), function(part) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3758 |
// Dont include empty strings in toId functions |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3759 |
if (part) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3760 |
return part; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3761 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3762 |
}) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3763 |
.join('_'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3764 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3765 |
// ##### toStr |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3766 |
// convert argument to a string |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3767 |
toStr: function(txt) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3768 |
return txt == null ? "" : "" + txt; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3769 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3770 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3771 |
// ##### hookup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3772 |
// attach the provided `fragment` to `parentNode` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3773 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3774 |
hookup: function(fragment, parentNode) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3775 |
var hookupEls = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3776 |
id, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3777 |
func; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3778 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3779 |
// Get all `childNodes`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3780 |
can.each(fragment.childNodes ? can.makeArray(fragment.childNodes) : fragment, function(node) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3781 |
if (node.nodeType === 1) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3782 |
hookupEls.push(node); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3783 |
hookupEls.push.apply(hookupEls, can.makeArray(node.getElementsByTagName('*'))); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3784 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3785 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3786 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3787 |
// Filter by `data-view-id` attribute. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3788 |
can.each(hookupEls, function(el) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3789 |
if (el.getAttribute && (id = el.getAttribute('data-view-id')) && (func = $view.hookups[id])) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3790 |
func(el, parentNode, id); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3791 |
delete $view.hookups[id]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3792 |
el.removeAttribute('data-view-id'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3793 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3794 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3795 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3796 |
return fragment; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3797 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3798 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3799 |
// `hookups` keeps list of pending hookups, ie fragments to attach to a parent node |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3800 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3801 |
hookups: {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3802 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3803 |
// `hook` factory method for hookup function inserted into templates |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3804 |
// hookup functions are called after the html is rendered to the page |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3805 |
// only implemented by EJS templates. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3806 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3807 |
hook: function(cb) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3808 |
$view.hookups[++hookupId] = cb; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3809 |
return ' data-view-id=\'' + hookupId + '\''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3810 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3811 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3812 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3813 |
cached: {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3814 |
cachedRenderers: {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3815 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3816 |
// cache view templates resolved via XHR on the client |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3817 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3818 |
cache: true, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3819 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3820 |
// ##### register |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3821 |
// given an info object, register a template type |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3822 |
// different templating solutions produce strings or document fragments via their renderer function |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3823 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3824 |
register: function(info) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3825 |
this.types['.' + info.suffix] = info; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3826 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3827 |
// _removed if not used as a steal module_ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3828 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3829 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3830 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3831 |
can[info.suffix] = $view[info.suffix] = function(id, text) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3832 |
// If there is no text, assume id is the template text, so return a nameless renderer. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3833 |
if (!text) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3834 |
// if the template has a fragRenderer already, just return that. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3835 |
if (info.fragRenderer) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3836 |
return info.fragRenderer(null, id); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3837 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3838 |
return makeRenderer(info.renderer(null, id)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3839 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3840 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3841 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3842 |
if (info.fragRenderer) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3843 |
return $view.preload(id, info.fragRenderer(id, text)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3844 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3845 |
return $view.preloadStringRenderer(id, info.renderer(id, text)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3846 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3847 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3848 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3849 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3850 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3851 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3852 |
//registered view types |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3853 |
types: {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3854 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3855 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3856 |
ext: ".ejs", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3857 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3858 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3859 |
registerScript: function(type, id, src) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3860 |
return 'can.view.preloadStringRenderer(\'' + id + '\',' + $view.types['.' + type].script(id, src) + ');'; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3861 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3862 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3863 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3864 |
preload: function(id, renderer) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3865 |
var def = $view.cached[id] = new can.Deferred() |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3866 |
.resolve(function(data, helpers) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3867 |
return renderer.call(data, data, helpers); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3868 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3869 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3870 |
// set cache references (otherwise preloaded recursive views won't recurse properly) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3871 |
def.__view_id = id; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3872 |
$view.cachedRenderers[id] = renderer; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3873 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3874 |
return renderer; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3875 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3876 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3877 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3878 |
preloadStringRenderer: function(id, stringRenderer) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3879 |
return this.preload(id, makeRenderer(stringRenderer)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3880 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3881 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3882 |
// #### renderers |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3883 |
// --------------- |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3884 |
// can.view's primary purpose is to load templates (from strings or filesystem) and render them |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3885 |
// can.view supports two different forms of rendering systems |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3886 |
// mustache templates return a string based rendering function |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3887 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3888 |
// stache (or other fragment based templating systems) return a document fragment, so 'hookup' steps are not required |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3889 |
// ##### render |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3890 |
//call `renderAs` with a hardcoded string, as view.render |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3891 |
// always operates against resolved template files or hardcoded strings |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3892 |
render: function(view, data, helpers, callback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3893 |
return can.view.renderAs("string", view, data, helpers, callback); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3894 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3895 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3896 |
// ##### renderTo |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3897 |
renderTo: function(format, renderer, data, helpers) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3898 |
return (format === "string" && renderer.render ? renderer.render : renderer)(data, helpers); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3899 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3900 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3901 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3902 |
renderAs: function(format, view, data, helpers, callback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3903 |
// If helpers is a `function`, it is actually a callback. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3904 |
if (isFunction(helpers)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3905 |
callback = helpers; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3906 |
helpers = undefined; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3907 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3908 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3909 |
// See if we got passed any deferreds. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3910 |
var deferreds = getDeferreds(data); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3911 |
var reading, deferred, dataCopy, async, response; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3912 |
if (deferreds.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3913 |
// Does data contain any deferreds? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3914 |
// The deferred that resolves into the rendered content... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3915 |
deferred = new can.Deferred(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3916 |
dataCopy = can.extend({}, data); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3917 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3918 |
// Add the view request to the list of deferreds. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3919 |
deferreds.push(get(view, true)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3920 |
// Wait for the view and all deferreds to finish... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3921 |
can.when.apply(can, deferreds) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3922 |
.then(function(resolved) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3923 |
// Get all the resolved deferreds. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3924 |
var objs = makeArray(arguments), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3925 |
// Renderer is the last index of the data. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3926 |
renderer = objs.pop(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3927 |
// The result of the template rendering with data. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3928 |
result; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3929 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3930 |
// Make data look like the resolved deferreds. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3931 |
if (can.isDeferred(data)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3932 |
dataCopy = usefulPart(resolved); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3933 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3934 |
// Go through each prop in data again and |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3935 |
// replace the defferreds with what they resolved to. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3936 |
for (var prop in data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3937 |
if (can.isDeferred(data[prop])) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3938 |
dataCopy[prop] = usefulPart(objs.shift()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3939 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3940 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3941 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3942 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3943 |
// Get the rendered result. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3944 |
result = can.view.renderTo(format, renderer, dataCopy, helpers); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3945 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3946 |
// Resolve with the rendered view. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3947 |
deferred.resolve(result, dataCopy); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3948 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3949 |
// If there's a `callback`, call it back with the result. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3950 |
if (callback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3951 |
callback(result, dataCopy); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3952 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3953 |
}, function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3954 |
deferred.reject.apply(deferred, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3955 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3956 |
// Return the deferred... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3957 |
return deferred; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3958 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3959 |
// get is called async but in |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3960 |
// ff will be async so we need to temporarily reset |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3961 |
reading = can.__clearReading(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3962 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3963 |
// If there's a `callback` function |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3964 |
async = isFunction(callback); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3965 |
// Get the `view` type |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3966 |
deferred = get(view, async); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3967 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3968 |
if (reading) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3969 |
can.__setReading(reading); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3970 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3971 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3972 |
// If we are `async`... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3973 |
if (async) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3974 |
// Return the deferred |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3975 |
response = deferred; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3976 |
// And fire callback with the rendered result. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3977 |
deferred.then(function(renderer) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3978 |
callback(data ? can.view.renderTo(format, renderer, data, helpers) : renderer); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3979 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3980 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3981 |
// if the deferred is resolved, call the cached renderer instead |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3982 |
// this is because it's possible, with recursive deferreds to |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3983 |
// need to render a view while its deferred is _resolving_. A _resolving_ deferred |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3984 |
// is a deferred that was just resolved and is calling back it's success callbacks. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3985 |
// If a new success handler is called while resoliving, it does not get fired by |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3986 |
// jQuery's deferred system. So instead of adding a new callback |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3987 |
// we use the cached renderer. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3988 |
// We also add __view_id on the deferred so we can look up it's cached renderer. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3989 |
// In the future, we might simply store either a deferred or the cached result. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3990 |
if (deferred.state() === 'resolved' && deferred.__view_id) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3991 |
var currentRenderer = $view.cachedRenderers[deferred.__view_id]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3992 |
return data ? can.view.renderTo(format, currentRenderer, data, helpers) : currentRenderer; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3993 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3994 |
// Otherwise, the deferred is complete, so |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3995 |
// set response to the result of the rendering. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3996 |
deferred.then(function(renderer) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3997 |
response = data ? can.view.renderTo(format, renderer, data, helpers) : renderer; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3998 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3999 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4000 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4001 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4002 |
return response; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4003 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4004 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4005 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4006 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4007 |
registerView: function(id, text, type, def) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4008 |
// Get the renderer function. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4009 |
var info = (typeof type === "object" ? type : $view.types[type || $view.ext]), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4010 |
renderer; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4011 |
if (info.fragRenderer) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4012 |
renderer = info.fragRenderer(id, text); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4013 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4014 |
renderer = makeRenderer(info.renderer(id, text)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4015 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4016 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4017 |
def = def || new can.Deferred(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4018 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4019 |
// Cache if we are caching. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4020 |
if ($view.cache) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4021 |
$view.cached[id] = def; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4022 |
def.__view_id = id; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4023 |
$view.cachedRenderers[id] = renderer; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4024 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4025 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4026 |
// Return the objects for the response's `dataTypes` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4027 |
// (in this case view). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4028 |
return def.resolve(renderer); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4029 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4030 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4031 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4032 |
// _removed if not used as a steal module_ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4033 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4034 |
return can; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4035 |
})(__m3); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4036 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4037 |
// ## can/control/control.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4038 |
var __m18 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4039 |
// ### bind |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4040 |
// this helper binds to one element and returns a function that unbinds from that element. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4041 |
var bind = function(el, ev, callback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4042 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4043 |
can.bind.call(el, ev, callback); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4044 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4045 |
return function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4046 |
can.unbind.call(el, ev, callback); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4047 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4048 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4049 |
isFunction = can.isFunction, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4050 |
extend = can.extend, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4051 |
each = can.each, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4052 |
slice = [].slice, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4053 |
paramReplacer = /\{([^\}]+)\}/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4054 |
special = can.getObject("$.event.special", [can]) || {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4055 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4056 |
// ### delegate |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4057 |
// this helper binds to elements based on a selector and returns a |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4058 |
// function that unbinds. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4059 |
delegate = function(el, selector, ev, callback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4060 |
can.delegate.call(el, selector, ev, callback); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4061 |
return function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4062 |
can.undelegate.call(el, selector, ev, callback); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4063 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4064 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4065 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4066 |
// ### binder |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4067 |
// Calls bind or unbind depending if there is a selector. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4068 |
binder = function(el, ev, callback, selector) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4069 |
return selector ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4070 |
delegate(el, can.trim(selector), ev, callback) : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4071 |
bind(el, ev, callback); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4072 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4073 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4074 |
basicProcessor; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4075 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4076 |
var Control = can.Control = can.Construct( |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4077 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4078 |
// ## *static functions* |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4079 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4080 |
{ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4081 |
// ## can.Control.setup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4082 |
// This function pre-processes which methods are event listeners and which are methods of |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4083 |
// the control. It has a mechanism to allow controllers to inherit default values from super |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4084 |
// classes, like `can.Construct`, and will cache functions that are action functions (see `_isAction`) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4085 |
// or functions with an underscored name. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4086 |
setup: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4087 |
can.Construct.setup.apply(this, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4088 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4089 |
if (can.Control) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4090 |
var control = this, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4091 |
funcName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4092 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4093 |
control.actions = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4094 |
for (funcName in control.prototype) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4095 |
if (control._isAction(funcName)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4096 |
control.actions[funcName] = control._action(funcName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4097 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4098 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4099 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4100 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4101 |
// ## can.Control._shifter |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4102 |
// Moves `this` to the first argument, wraps it with `jQuery` if it's |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4103 |
// an element. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4104 |
_shifter: function(context, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4105 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4106 |
var method = typeof name === "string" ? context[name] : name; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4107 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4108 |
if (!isFunction(method)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4109 |
method = context[method]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4110 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4111 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4112 |
return function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4113 |
context.called = name; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4114 |
return method.apply(context, [this.nodeName ? can.$(this) : this].concat(slice.call(arguments, 0))); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4115 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4116 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4117 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4118 |
// ## can.Control._isAction |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4119 |
// Return `true` if `methodName` refers to an action. An action is a `methodName` value that |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4120 |
// is not the constructor, and is either a function or string that refers to a function, or is |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4121 |
// defined in `special`, `processors`. Detects whether `methodName` is also a valid method name. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4122 |
_isAction: function(methodName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4123 |
var val = this.prototype[methodName], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4124 |
type = typeof val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4125 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4126 |
return (methodName !== 'constructor') && |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4127 |
(type === "function" || (type === "string" && isFunction(this.prototype[val]))) && !! (special[methodName] || processors[methodName] || /[^\w]/.test(methodName)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4128 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4129 |
// ## can.Control._action |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4130 |
// Takes a method name and the options passed to a control and tries to return the data |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4131 |
// necessary to pass to a processor (something that binds things). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4132 |
// For performance reasons, `_action` is called twice: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4133 |
// * It's called when the Control class is created. for templated method names (e.g., `{window} foo`), it returns null. For non-templated method names it returns the event binding data. That data is added to `this.actions`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4134 |
// * It is called wehn a control instance is created, but only for templated actions. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4135 |
_action: function(methodName, options) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4136 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4137 |
// If we don't have options (a `control` instance), we'll run this later. If we have |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4138 |
// options, run `can.sub` to replace the action template `{}` with values from the `options` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4139 |
// or `window`. If a `{}` template resolves to an object, `convertedName` will be an array. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4140 |
// In that case, the event name we want will be the last item in that array. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4141 |
paramReplacer.lastIndex = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4142 |
if (options || !paramReplacer.test(methodName)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4143 |
var convertedName = options ? can.sub(methodName, this._lookup(options)) : methodName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4144 |
if (!convertedName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4145 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4146 |
return null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4147 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4148 |
var arr = can.isArray(convertedName), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4149 |
name = arr ? convertedName[1] : convertedName, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4150 |
parts = name.split(/\s+/g), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4151 |
event = parts.pop(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4152 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4153 |
return { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4154 |
processor: processors[event] || basicProcessor, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4155 |
parts: [name, parts.join(" "), event], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4156 |
delegate: arr ? convertedName[0] : undefined |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4157 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4158 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4159 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4160 |
_lookup: function(options) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4161 |
return [options, window]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4162 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4163 |
// ## can.Control.processors |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4164 |
// An object of `{eventName : function}` pairs that Control uses to |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4165 |
// hook up events automatically. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4166 |
processors: {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4167 |
// ## can.Control.defaults |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4168 |
// A object of name-value pairs that act as default values for a control instance |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4169 |
defaults: {} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4170 |
}, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4171 |
// ## *prototype functions* |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4172 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4173 |
// ## setup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4174 |
// Setup is where most of the Control's magic happens. It performs several pre-initialization steps: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4175 |
// - Sets `this.element` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4176 |
// - Adds the Control's name to the element's className |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4177 |
// - Saves the Control in `$.data` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4178 |
// - Merges Options |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4179 |
// - Binds event handlers using `delegate` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4180 |
// The final step is to return pass the element and prepareed options, to be used in `init`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4181 |
setup: function(element, options) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4182 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4183 |
var cls = this.constructor, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4184 |
pluginname = cls.pluginName || cls._fullName, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4185 |
arr; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4186 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4187 |
// Retrieve the raw element, then set the plugin name as a class there. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4188 |
this.element = can.$(element); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4189 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4190 |
if (pluginname && pluginname !== 'can_control') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4191 |
this.element.addClass(pluginname); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4192 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4193 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4194 |
// Set up the 'controls' data on the element. If it does not exist, initialize |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4195 |
// it to an empty array. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4196 |
arr = can.data(this.element, 'controls'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4197 |
if (!arr) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4198 |
arr = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4199 |
can.data(this.element, 'controls', arr); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4200 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4201 |
arr.push(this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4202 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4203 |
// The `this.options` property is an Object that contains configuration data |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4204 |
// passed to a control when it is created (`new can.Control(element, options)`) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4205 |
// The `options` argument passed when creating the control is merged with `can.Control.defaults` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4206 |
// in [can.Control.prototype.setup setup]. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4207 |
// If no `options` value is used during creation, the value in `defaults` is used instead |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4208 |
this.options = extend({}, cls.defaults, options); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4209 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4210 |
this.on(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4211 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4212 |
return [this.element, this.options]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4213 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4214 |
// ## on |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4215 |
// This binds an event handler for an event to a selector under the scope of `this.element` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4216 |
// If no options are specified, all events are rebound to their respective elements. The actions, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4217 |
// which were cached in `setup`, are used and all elements are bound using `delegate` from `this.element`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4218 |
on: function(el, selector, eventName, func) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4219 |
if (!el) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4220 |
this.off(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4221 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4222 |
var cls = this.constructor, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4223 |
bindings = this._bindings, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4224 |
actions = cls.actions, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4225 |
element = this.element, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4226 |
destroyCB = can.Control._shifter(this, "destroy"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4227 |
funcName, ready; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4228 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4229 |
for (funcName in actions) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4230 |
// Only push if we have the action and no option is `undefined` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4231 |
if (actions.hasOwnProperty(funcName)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4232 |
ready = actions[funcName] || cls._action(funcName, this.options, this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4233 |
if (ready) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4234 |
bindings.control[funcName] = ready.processor(ready.delegate || element, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4235 |
ready.parts[2], ready.parts[1], funcName, this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4236 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4237 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4238 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4239 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4240 |
// Set up the ability to `destroy` the control later. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4241 |
can.bind.call(element, "removed", destroyCB); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4242 |
bindings.user.push(function(el) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4243 |
can.unbind.call(el, "removed", destroyCB); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4244 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4245 |
return bindings.user.length; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4246 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4247 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4248 |
// if `el` is a string, use that as `selector` and re-set it to this control's element... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4249 |
if (typeof el === 'string') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4250 |
func = eventName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4251 |
eventName = selector; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4252 |
selector = el; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4253 |
el = this.element; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4254 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4255 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4256 |
// ...otherwise, set `selector` to null |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4257 |
if (func === undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4258 |
func = eventName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4259 |
eventName = selector; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4260 |
selector = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4261 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4262 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4263 |
if (typeof func === 'string') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4264 |
func = can.Control._shifter(this, func); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4265 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4266 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4267 |
this._bindings.user.push(binder(el, eventName, func, selector)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4268 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4269 |
return this._bindings.user.length; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4270 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4271 |
// ## off |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4272 |
// Unbinds all event handlers on the controller. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4273 |
// This should _only_ be called in combination with .on() |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4274 |
off: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4275 |
var el = this.element[0], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4276 |
bindings = this._bindings; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4277 |
if (bindings) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4278 |
each(bindings.user || [], function(value) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4279 |
value(el); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4280 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4281 |
each(bindings.control || {}, function(value) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4282 |
value(el); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4283 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4284 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4285 |
// Adds bindings. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4286 |
this._bindings = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4287 |
user: [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4288 |
control: {} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4289 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4290 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4291 |
// ## destroy |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4292 |
// Prepares a `control` for garbage collection. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4293 |
// First checks if it has already been removed. Then, removes all the bindings, data, and |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4294 |
// the element from the Control instance. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4295 |
destroy: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4296 |
if (this.element === null) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4297 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4298 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4299 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4300 |
var Class = this.constructor, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4301 |
pluginName = Class.pluginName || Class._fullName, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4302 |
controls; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4303 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4304 |
this.off(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4305 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4306 |
if (pluginName && pluginName !== 'can_control') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4307 |
this.element.removeClass(pluginName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4308 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4309 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4310 |
controls = can.data(this.element, "controls"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4311 |
controls.splice(can.inArray(this, controls), 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4312 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4313 |
can.trigger(this, "destroyed"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4314 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4315 |
this.element = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4316 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4317 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4318 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4319 |
// ## Processors |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4320 |
// Processors do the binding. This basic processor binds events. Each returns a function that unbinds |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4321 |
// when called. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4322 |
var processors = can.Control.processors; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4323 |
basicProcessor = function(el, event, selector, methodName, control) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4324 |
return binder(el, event, can.Control._shifter(control, methodName), selector); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4325 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4326 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4327 |
// Set common events to be processed as a `basicProcessor` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4328 |
each(["change", "click", "contextmenu", "dblclick", "keydown", "keyup", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4329 |
"keypress", "mousedown", "mousemove", "mouseout", "mouseover", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4330 |
"mouseup", "reset", "resize", "scroll", "select", "submit", "focusin", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4331 |
"focusout", "mouseenter", "mouseleave", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4332 |
"touchstart", "touchmove", "touchcancel", "touchend", "touchleave", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4333 |
"inserted", "removed" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4334 |
], function(v) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4335 |
processors[v] = basicProcessor; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4336 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4337 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4338 |
return Control; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4339 |
})(__m3, __m1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4340 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4341 |
// ## can/util/string/deparam/deparam.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4342 |
var __m20 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4343 |
// ## deparam.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4344 |
// `can.deparam` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4345 |
// _Takes a string of name value pairs and returns a Object literal that represents those params._ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4346 |
var digitTest = /^\d+$/, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4347 |
keyBreaker = /([^\[\]]+)|(\[\])/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4348 |
paramTest = /([^?#]*)(#.*)?$/, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4349 |
prep = function(str) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4350 |
return decodeURIComponent(str.replace(/\+/g, ' ')); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4351 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4352 |
can.extend(can, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4353 |
deparam: function(params) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4354 |
var data = {}, pairs, lastPart; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4355 |
if (params && paramTest.test(params)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4356 |
pairs = params.split('&'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4357 |
can.each(pairs, function(pair) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4358 |
var parts = pair.split('='), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4359 |
key = prep(parts.shift()), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4360 |
value = prep(parts.join('=')), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4361 |
current = data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4362 |
if (key) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4363 |
parts = key.match(keyBreaker); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4364 |
for (var j = 0, l = parts.length - 1; j < l; j++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4365 |
if (!current[parts[j]]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4366 |
// If what we are pointing to looks like an `array` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4367 |
current[parts[j]] = digitTest.test(parts[j + 1]) || parts[j + 1] === '[]' ? [] : {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4368 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4369 |
current = current[parts[j]]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4370 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4371 |
lastPart = parts.pop(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4372 |
if (lastPart === '[]') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4373 |
current.push(value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4374 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4375 |
current[lastPart] = value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4376 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4377 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4378 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4379 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4380 |
return data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4381 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4382 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4383 |
return can; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4384 |
})(__m3, __m2); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4385 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4386 |
// ## can/route/route.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4387 |
var __m19 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4388 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4389 |
// ## route.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4390 |
// `can.route` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4391 |
// _Helps manage browser history (and client state) by synchronizing the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4392 |
// `window.location.hash` with a `can.Map`._ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4393 |
// Helper methods used for matching routes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4394 |
var |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4395 |
// `RegExp` used to match route variables of the type ':name'. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4396 |
// Any word character or a period is matched. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4397 |
matcher = /\:([\w\.]+)/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4398 |
// Regular expression for identifying &key=value lists. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4399 |
paramsMatcher = /^(?:&[^=]+=[^&]*)+/, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4400 |
// Converts a JS Object into a list of parameters that can be |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4401 |
// inserted into an html element tag. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4402 |
makeProps = function(props) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4403 |
var tags = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4404 |
can.each(props, function(val, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4405 |
tags.push((name === 'className' ? 'class' : name) + '="' + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4406 |
(name === "href" ? val : can.esc(val)) + '"'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4407 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4408 |
return tags.join(" "); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4409 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4410 |
// Checks if a route matches the data provided. If any route variable |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4411 |
// is not present in the data, the route does not match. If all route |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4412 |
// variables are present in the data, the number of matches is returned |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4413 |
// to allow discerning between general and more specific routes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4414 |
matchesData = function(route, data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4415 |
var count = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4416 |
i = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4417 |
defaults = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4418 |
// look at default values, if they match ... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4419 |
for (var name in route.defaults) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4420 |
if (route.defaults[name] === data[name]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4421 |
// mark as matched |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4422 |
defaults[name] = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4423 |
count++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4424 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4425 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4426 |
for (; i < route.names.length; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4427 |
if (!data.hasOwnProperty(route.names[i])) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4428 |
return -1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4429 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4430 |
if (!defaults[route.names[i]]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4431 |
count++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4432 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4433 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4434 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4435 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4436 |
return count; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4437 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4438 |
location = window.location, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4439 |
wrapQuote = function(str) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4440 |
return (str + '') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4441 |
.replace(/([.?*+\^$\[\]\\(){}|\-])/g, "\\$1"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4442 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4443 |
each = can.each, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4444 |
extend = can.extend, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4445 |
// Helper for convert any object (or value) to stringified object (or value) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4446 |
stringify = function(obj) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4447 |
// Object is array, plain object, Map or List |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4448 |
if (obj && typeof obj === "object") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4449 |
// Get native object or array from Map or List |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4450 |
if (obj instanceof can.Map) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4451 |
obj = obj.attr(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4452 |
// Clone object to prevent change original values |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4453 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4454 |
obj = can.isFunction(obj.slice) ? obj.slice() : can.extend({}, obj); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4455 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4456 |
// Convert each object property or array item into stringified new |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4457 |
can.each(obj, function(val, prop) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4458 |
obj[prop] = stringify(val); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4459 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4460 |
// Object supports toString function |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4461 |
} else if (obj !== undefined && obj !== null && can.isFunction(obj.toString)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4462 |
obj = obj.toString(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4463 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4464 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4465 |
return obj; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4466 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4467 |
removeBackslash = function(str) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4468 |
return str.replace(/\\/g, ""); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4469 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4470 |
// A ~~throttled~~ debounced function called multiple times will only fire once the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4471 |
// timer runs down. Each call resets the timer. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4472 |
timer, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4473 |
// Intermediate storage for `can.route.data`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4474 |
curParams, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4475 |
// The last hash caused by a data change |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4476 |
lastHash, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4477 |
// Are data changes pending that haven't yet updated the hash |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4478 |
changingData, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4479 |
// If the `can.route.data` changes, update the hash. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4480 |
// Using `.serialize()` retrieves the raw data contained in the `observable`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4481 |
// This function is ~~throttled~~ debounced so it only updates once even if multiple values changed. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4482 |
// This might be able to use batchNum and avoid this. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4483 |
onRouteDataChange = function(ev, attr, how, newval) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4484 |
// indicate that data is changing |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4485 |
changingData = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4486 |
clearTimeout(timer); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4487 |
timer = setTimeout(function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4488 |
// indicate that the hash is set to look like the data |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4489 |
changingData = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4490 |
var serialized = can.route.data.serialize(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4491 |
path = can.route.param(serialized, true); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4492 |
can.route._call("setURL", path); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4493 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4494 |
lastHash = path; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4495 |
}, 10); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4496 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4497 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4498 |
can.route = function(url, defaults) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4499 |
// if route ends with a / and url starts with a /, remove the leading / of the url |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4500 |
var root = can.route._call("root"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4501 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4502 |
if (root.lastIndexOf("/") === root.length - 1 && |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4503 |
url.indexOf("/") === 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4504 |
url = url.substr(1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4505 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4506 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4507 |
defaults = defaults || {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4508 |
// Extract the variable names and replace with `RegExp` that will match |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4509 |
// an atual URL with values. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4510 |
var names = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4511 |
res, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4512 |
test = "", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4513 |
lastIndex = matcher.lastIndex = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4514 |
next, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4515 |
querySeparator = can.route._call("querySeparator"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4516 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4517 |
// res will be something like [":foo","foo"] |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4518 |
while (res = matcher.exec(url)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4519 |
names.push(res[1]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4520 |
test += removeBackslash(url.substring(lastIndex, matcher.lastIndex - res[0].length)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4521 |
next = "\\" + (removeBackslash(url.substr(matcher.lastIndex, 1)) || querySeparator); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4522 |
// a name without a default value HAS to have a value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4523 |
// a name that has a default value can be empty |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4524 |
// The `\\` is for string-escaping giving single `\` for `RegExp` escaping. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4525 |
test += "([^" + next + "]" + (defaults[res[1]] ? "*" : "+") + ")"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4526 |
lastIndex = matcher.lastIndex; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4527 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4528 |
test += url.substr(lastIndex) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4529 |
.replace("\\", ""); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4530 |
// Add route in a form that can be easily figured out. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4531 |
can.route.routes[url] = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4532 |
// A regular expression that will match the route when variable values |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4533 |
// are present; i.e. for `:page/:type` the `RegExp` is `/([\w\.]*)/([\w\.]*)/` which |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4534 |
// will match for any value of `:page` and `:type` (word chars or period). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4535 |
test: new RegExp("^" + test + "($|" + wrapQuote(querySeparator) + ")"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4536 |
// The original URL, same as the index for this entry in routes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4537 |
route: url, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4538 |
// An `array` of all the variable names in this route. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4539 |
names: names, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4540 |
// Default values provided for the variables. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4541 |
defaults: defaults, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4542 |
// The number of parts in the URL separated by `/`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4543 |
length: url.split('/') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4544 |
.length |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4545 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4546 |
return can.route; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4547 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4548 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4549 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4550 |
extend(can.route, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4551 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4552 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4553 |
param: function(data, _setRoute) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4554 |
// Check if the provided data keys match the names in any routes; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4555 |
// Get the one with the most matches. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4556 |
var route, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4557 |
// Need to have at least 1 match. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4558 |
matches = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4559 |
matchCount, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4560 |
routeName = data.route, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4561 |
propCount = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4562 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4563 |
delete data.route; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4564 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4565 |
each(data, function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4566 |
propCount++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4567 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4568 |
// Otherwise find route. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4569 |
each(can.route.routes, function(temp, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4570 |
// best route is the first with all defaults matching |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4571 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4572 |
matchCount = matchesData(temp, data); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4573 |
if (matchCount > matches) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4574 |
route = temp; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4575 |
matches = matchCount; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4576 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4577 |
if (matchCount >= propCount) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4578 |
return false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4579 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4580 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4581 |
// If we have a route name in our `can.route` data, and it's |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4582 |
// just as good as what currently matches, use that |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4583 |
if (can.route.routes[routeName] && matchesData(can.route.routes[routeName], data) === matches) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4584 |
route = can.route.routes[routeName]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4585 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4586 |
// If this is match... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4587 |
if (route) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4588 |
var cpy = extend({}, data), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4589 |
// Create the url by replacing the var names with the provided data. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4590 |
// If the default value is found an empty string is inserted. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4591 |
res = route.route.replace(matcher, function(whole, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4592 |
delete cpy[name]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4593 |
return data[name] === route.defaults[name] ? "" : encodeURIComponent(data[name]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4594 |
}) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4595 |
.replace("\\", ""), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4596 |
after; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4597 |
// Remove matching default values |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4598 |
each(route.defaults, function(val, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4599 |
if (cpy[name] === val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4600 |
delete cpy[name]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4601 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4602 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4603 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4604 |
// The remaining elements of data are added as |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4605 |
// `&` separated parameters to the url. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4606 |
after = can.param(cpy); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4607 |
// if we are paraming for setting the hash |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4608 |
// we also want to make sure the route value is updated |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4609 |
if (_setRoute) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4610 |
can.route.attr('route', route.route); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4611 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4612 |
return res + (after ? can.route._call("querySeparator") + after : ""); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4613 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4614 |
// If no route was found, there is no hash URL, only paramters. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4615 |
return can.isEmptyObject(data) ? "" : can.route._call("querySeparator") + can.param(data); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4616 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4617 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4618 |
deparam: function(url) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4619 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4620 |
// remove the url |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4621 |
var root = can.route._call("root"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4622 |
if (root.lastIndexOf("/") === root.length - 1 && |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4623 |
url.indexOf("/") === 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4624 |
url = url.substr(1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4625 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4626 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4627 |
// See if the url matches any routes by testing it against the `route.test` `RegExp`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4628 |
// By comparing the URL length the most specialized route that matches is used. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4629 |
var route = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4630 |
length: -1 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4631 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4632 |
querySeparator = can.route._call("querySeparator"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4633 |
paramsMatcher = can.route._call("paramsMatcher"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4634 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4635 |
each(can.route.routes, function(temp, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4636 |
if (temp.test.test(url) && temp.length > route.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4637 |
route = temp; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4638 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4639 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4640 |
// If a route was matched. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4641 |
if (route.length > -1) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4642 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4643 |
var // Since `RegExp` backreferences are used in `route.test` (parens) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4644 |
// the parts will contain the full matched string and each variable (back-referenced) value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4645 |
parts = url.match(route.test), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4646 |
// Start will contain the full matched string; parts contain the variable values. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4647 |
start = parts.shift(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4648 |
// The remainder will be the `&key=value` list at the end of the URL. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4649 |
remainder = url.substr(start.length - (parts[parts.length - 1] === querySeparator ? 1 : 0)), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4650 |
// If there is a remainder and it contains a `&key=value` list deparam it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4651 |
obj = (remainder && paramsMatcher.test(remainder)) ? can.deparam(remainder.slice(1)) : {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4652 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4653 |
// Add the default values for this route. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4654 |
obj = extend(true, {}, route.defaults, obj); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4655 |
// Overwrite each of the default values in `obj` with those in |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4656 |
// parts if that part is not empty. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4657 |
each(parts, function(part, i) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4658 |
if (part && part !== querySeparator) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4659 |
obj[route.names[i]] = decodeURIComponent(part); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4660 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4661 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4662 |
obj.route = route.route; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4663 |
return obj; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4664 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4665 |
// If no route was matched, it is parsed as a `&key=value` list. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4666 |
if (url.charAt(0) !== querySeparator) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4667 |
url = querySeparator + url; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4668 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4669 |
return paramsMatcher.test(url) ? can.deparam(url.slice(1)) : {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4670 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4671 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4672 |
data: new can.Map({}), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4673 |
map: function(data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4674 |
var appState; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4675 |
// appState is a can.Map constructor function |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4676 |
if (data.prototype instanceof can.Map) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4677 |
appState = new data(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4678 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4679 |
// appState is an instance of can.Map |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4680 |
else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4681 |
appState = data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4682 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4683 |
can.route.data = appState; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4684 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4685 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4686 |
routes: {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4687 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4688 |
ready: function(val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4689 |
if (val !== true) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4690 |
can.route._setup(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4691 |
can.route.setState(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4692 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4693 |
return can.route; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4694 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4695 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4696 |
url: function(options, merge) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4697 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4698 |
if (merge) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4699 |
options = can.extend({}, can.route.deparam(can.route._call("matchingPartOfURL")), options); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4700 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4701 |
return can.route._call("root") + can.route.param(options); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4702 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4703 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4704 |
link: function(name, options, props, merge) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4705 |
return "<a " + makeProps( |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4706 |
extend({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4707 |
href: can.route.url(options, merge) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4708 |
}, props)) + ">" + name + "</a>"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4709 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4710 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4711 |
current: function(options) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4712 |
return this._call("matchingPartOfURL") === can.route.param(options); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4713 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4714 |
bindings: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4715 |
hashchange: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4716 |
paramsMatcher: paramsMatcher, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4717 |
querySeparator: "&", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4718 |
bind: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4719 |
can.bind.call(window, 'hashchange', setState); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4720 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4721 |
unbind: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4722 |
can.unbind.call(window, 'hashchange', setState); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4723 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4724 |
// Gets the part of the url we are determinging the route from. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4725 |
// For hashbased routing, it's everything after the #, for |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4726 |
// pushState it's configurable |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4727 |
matchingPartOfURL: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4728 |
return location.href.split(/#!?/)[1] || ""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4729 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4730 |
// gets called with the serialized can.route data after a route has changed |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4731 |
// returns what the url has been updated to (for matching purposes) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4732 |
setURL: function(path) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4733 |
location.hash = "#!" + path; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4734 |
return path; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4735 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4736 |
root: "#!" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4737 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4738 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4739 |
defaultBinding: "hashchange", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4740 |
currentBinding: null, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4741 |
// ready calls setup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4742 |
// setup binds and listens to data changes |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4743 |
// bind listens to whatever you should be listening to |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4744 |
// data changes tries to set the path |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4745 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4746 |
// we need to be able to |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4747 |
// easily kick off calling setState |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4748 |
// teardown whatever is there |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4749 |
// turn on a particular binding |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4750 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4751 |
// called when the route is ready |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4752 |
_setup: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4753 |
if (!can.route.currentBinding) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4754 |
can.route._call("bind"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4755 |
can.route.bind("change", onRouteDataChange); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4756 |
can.route.currentBinding = can.route.defaultBinding; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4757 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4758 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4759 |
_teardown: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4760 |
if (can.route.currentBinding) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4761 |
can.route._call("unbind"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4762 |
can.route.unbind("change", onRouteDataChange); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4763 |
can.route.currentBinding = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4764 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4765 |
clearTimeout(timer); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4766 |
changingData = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4767 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4768 |
// a helper to get stuff from the current or default bindings |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4769 |
_call: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4770 |
var args = can.makeArray(arguments), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4771 |
prop = args.shift(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4772 |
binding = can.route.bindings[can.route.currentBinding || can.route.defaultBinding], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4773 |
method = binding[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4774 |
if (method.apply) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4775 |
return method.apply(binding, args); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4776 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4777 |
return method; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4778 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4779 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4780 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4781 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4782 |
// The functions in the following list applied to `can.route` (e.g. `can.route.attr('...')`) will |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4783 |
// instead act on the `can.route.data` observe. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4784 |
each(['bind', 'unbind', 'on', 'off', 'delegate', 'undelegate', 'removeAttr', 'compute', '_get', '__get'], function(name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4785 |
can.route[name] = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4786 |
// `delegate` and `undelegate` require |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4787 |
// the `can/map/delegate` plugin |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4788 |
if (!can.route.data[name]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4789 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4790 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4791 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4792 |
return can.route.data[name].apply(can.route.data, arguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4793 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4794 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4795 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4796 |
// Because everything in hashbang is in fact a string this will automaticaly convert new values to string. Works with single value, or deep hashes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4797 |
// Main motivation for this is to prevent double route event call for same value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4798 |
// Example (the problem): |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4799 |
// When you load page with hashbang like #!&some_number=2 and bind 'some_number' on routes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4800 |
// It will fire event with adding of "2" (string) to 'some_number' property |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4801 |
// But when you after this set can.route.attr({some_number: 2}) or can.route.attr('some_number', 2). it fires another event with change of 'some_number' from "2" (string) to 2 (integer) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4802 |
// This wont happen again with this normalization |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4803 |
can.route.attr = function(attr, val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4804 |
var type = typeof attr, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4805 |
newArguments; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4806 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4807 |
// Reading |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4808 |
if (val === undefined) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4809 |
newArguments = arguments; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4810 |
// Sets object |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4811 |
} else if (type !== "string" && type !== "number") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4812 |
newArguments = [stringify(attr), val]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4813 |
// Sets key - value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4814 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4815 |
newArguments = [attr, stringify(val)]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4816 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4817 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4818 |
return can.route.data.attr.apply(can.route.data, newArguments); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4819 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4820 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4821 |
var // Deparameterizes the portion of the hash of interest and assign the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4822 |
// values to the `can.route.data` removing existing values no longer in the hash. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4823 |
// setState is called typically by hashchange which fires asynchronously |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4824 |
// So it's possible that someone started changing the data before the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4825 |
// hashchange event fired. For this reason, it will not set the route data |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4826 |
// if the data is changing or the hash already matches the hash that was set. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4827 |
setState = can.route.setState = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4828 |
var hash = can.route._call("matchingPartOfURL"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4829 |
var oldParams = curParams; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4830 |
curParams = can.route.deparam(hash); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4831 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4832 |
// if the hash data is currently changing, or |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4833 |
// the hash is what we set it to anyway, do NOT change the hash |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4834 |
if (!changingData || hash !== lastHash) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4835 |
can.batch.start(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4836 |
for (var attr in oldParams) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4837 |
if (!curParams[attr]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4838 |
can.route.removeAttr(attr); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4839 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4840 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4841 |
can.route.attr(curParams); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4842 |
can.batch.stop(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4843 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4844 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4845 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4846 |
return can.route; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4847 |
})(__m3, __m10, __m14, __m20); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4848 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4849 |
// ## can/control/route/route.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4850 |
var __m21 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4851 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4852 |
// ## control/route.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4853 |
// _Controller route integration._ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4854 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4855 |
can.Control.processors.route = function(el, event, selector, funcName, controller) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4856 |
selector = selector || ""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4857 |
if (!can.route.routes[selector]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4858 |
if (selector[0] === '/') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4859 |
selector = selector.substring(1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4860 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4861 |
can.route(selector); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4862 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4863 |
var batchNum, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4864 |
check = function(ev, attr, how) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4865 |
if (can.route.attr('route') === (selector) && |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4866 |
(ev.batchNum === undefined || ev.batchNum !== batchNum)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4867 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4868 |
batchNum = ev.batchNum; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4869 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4870 |
var d = can.route.attr(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4871 |
delete d.route; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4872 |
if (can.isFunction(controller[funcName])) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4873 |
controller[funcName](d); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4874 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4875 |
controller[controller[funcName]](d); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4876 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4877 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4878 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4879 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4880 |
can.route.bind('change', check); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4881 |
return function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4882 |
can.route.unbind('change', check); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4883 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4884 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4885 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4886 |
return can; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4887 |
})(__m3, __m19, __m18); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4888 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4889 |
// ## can/view/elements.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4890 |
var __m24 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4891 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4892 |
var selectsCommentNodes = (function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4893 |
return can.$(document.createComment('~')).length === 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4894 |
})(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4895 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4896 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4897 |
var elements = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4898 |
tagToContentPropMap: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4899 |
option: 'textContent' in document.createElement('option') ? 'textContent' : 'innerText', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4900 |
textarea: 'value' |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4901 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4902 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4903 |
// 3.0 TODO: remove |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4904 |
attrMap: can.attr.map, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4905 |
// matches the attrName of a regexp |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4906 |
attrReg: /([^\s=]+)[\s]*=[\s]*/, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4907 |
// 3.0 TODO: remove |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4908 |
defaultValue: can.attr.defaultValue, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4909 |
// a map of parent element to child elements |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4910 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4911 |
tagMap: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4912 |
'': 'span', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4913 |
table: 'tbody', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4914 |
tr: 'td', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4915 |
ol: 'li', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4916 |
ul: 'li', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4917 |
tbody: 'tr', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4918 |
thead: 'tr', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4919 |
tfoot: 'tr', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4920 |
select: 'option', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4921 |
optgroup: 'option' |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4922 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4923 |
// a tag's parent element |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4924 |
reverseTagMap: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4925 |
tr: 'tbody', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4926 |
option: 'select', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4927 |
td: 'tr', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4928 |
th: 'tr', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4929 |
li: 'ul' |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4930 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4931 |
// Used to determine the parentNode if el is directly within a documentFragment |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4932 |
getParentNode: function(el, defaultParentNode) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4933 |
return defaultParentNode && el.parentNode.nodeType === 11 ? defaultParentNode : el.parentNode; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4934 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4935 |
// 3.0 TODO: remove |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4936 |
setAttr: can.attr.set, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4937 |
// 3.0 TODO: remove |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4938 |
getAttr: can.attr.get, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4939 |
// 3.0 TODO: remove |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4940 |
removeAttr: can.attr.remove, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4941 |
// Gets a "pretty" value for something |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4942 |
contentText: function(text) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4943 |
if (typeof text === 'string') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4944 |
return text; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4945 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4946 |
// If has no value, return an empty string. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4947 |
if (!text && text !== 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4948 |
return ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4949 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4950 |
return '' + text; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4951 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4952 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4953 |
after: function(oldElements, newFrag) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4954 |
var last = oldElements[oldElements.length - 1]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4955 |
// Insert it in the `document` or `documentFragment` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4956 |
if (last.nextSibling) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4957 |
can.insertBefore(last.parentNode, newFrag, last.nextSibling); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4958 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4959 |
can.appendChild(last.parentNode, newFrag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4960 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4961 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4962 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4963 |
replace: function(oldElements, newFrag) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4964 |
elements.after(oldElements, newFrag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4965 |
if (can.remove(can.$(oldElements)).length < oldElements.length && !selectsCommentNodes) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4966 |
can.each(oldElements, function(el) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4967 |
if (el.nodeType === 8) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4968 |
el.parentNode.removeChild(el); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4969 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4970 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4971 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4972 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4973 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4974 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4975 |
can.view.elements = elements; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4976 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4977 |
return elements; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4978 |
})(__m3, __m17); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4979 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4980 |
// ## can/view/callbacks/callbacks.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4981 |
var __m25 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4982 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4983 |
var attr = can.view.attr = function(attributeName, attrHandler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4984 |
if (attrHandler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4985 |
if (typeof attributeName === "string") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4986 |
attributes[attributeName] = attrHandler; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4987 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4988 |
regExpAttributes.push({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4989 |
match: attributeName, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4990 |
handler: attrHandler |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4991 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4992 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4993 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4994 |
var cb = attributes[attributeName]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4995 |
if (!cb) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4996 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4997 |
for (var i = 0, len = regExpAttributes.length; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4998 |
var attrMatcher = regExpAttributes[i]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4999 |
if (attrMatcher.match.test(attributeName)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5000 |
cb = attrMatcher.handler; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5001 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5002 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5003 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5004 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5005 |
return cb; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5006 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5007 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5008 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5009 |
var attributes = {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5010 |
regExpAttributes = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5011 |
automaticCustomElementCharacters = /[-\:]/; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5012 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5013 |
var tag = can.view.tag = function(tagName, tagHandler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5014 |
if (tagHandler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5015 |
// if we have html5shive ... re-generate |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5016 |
if (window.html5) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5017 |
window.html5.elements += " " + tagName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5018 |
window.html5.shivDocument(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5019 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5020 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5021 |
tags[tagName.toLowerCase()] = tagHandler; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5022 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5023 |
var cb = tags[tagName.toLowerCase()]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5024 |
if (!cb && automaticCustomElementCharacters.test(tagName)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5025 |
// empty callback for things that look like special tags |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5026 |
cb = function() {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5027 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5028 |
return cb; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5029 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5030 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5031 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5032 |
var tags = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5033 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5034 |
can.view.callbacks = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5035 |
_tags: tags, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5036 |
_attributes: attributes, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5037 |
_regExpAttributes: regExpAttributes, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5038 |
tag: tag, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5039 |
attr: attr, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5040 |
// handles calling back a tag callback |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5041 |
tagHandler: function(el, tagName, tagData) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5042 |
var helperTagCallback = tagData.options.read('tags.' + tagName, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5043 |
isArgument: true, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5044 |
proxyMethods: false |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5045 |
}) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5046 |
.value, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5047 |
tagCallback = helperTagCallback || tags[tagName]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5048 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5049 |
// If this was an element like <foo-bar> that doesn't have a component, just render its content |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5050 |
var scope = tagData.scope, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5051 |
res; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5052 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5053 |
if (tagCallback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5054 |
var reads = can.__clearReading(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5055 |
res = tagCallback(el, tagData); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5056 |
can.__setReading(reads); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5057 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5058 |
res = scope; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5059 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5060 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5061 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5062 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5063 |
// If the tagCallback gave us something to render with, and there is content within that element |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5064 |
// render it! |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5065 |
if (res && tagData.subtemplate) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5066 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5067 |
if (scope !== res) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5068 |
scope = scope.add(res); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5069 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5070 |
var result = tagData.subtemplate(scope, tagData.options); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5071 |
var frag = typeof result === "string" ? can.view.frag(result) : result; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5072 |
can.appendChild(el, frag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5073 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5074 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5075 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5076 |
return can.view.callbacks; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5077 |
})(__m3, __m17); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5078 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5079 |
// ## can/view/scanner.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5080 |
var __m23 = (function(can, elements, viewCallbacks) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5081 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5082 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5083 |
var newLine = /(\r|\n)+/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5084 |
notEndTag = /\//, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5085 |
// Escapes characters starting with `\`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5086 |
clean = function(content) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5087 |
return content |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5088 |
.split('\\') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5089 |
.join("\\\\") |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5090 |
.split("\n") |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5091 |
.join("\\n") |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5092 |
.split('"') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5093 |
.join('\\"') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5094 |
.split("\t") |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5095 |
.join("\\t"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5096 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5097 |
// Returns a tagName to use as a temporary placeholder for live content |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5098 |
// looks forward ... could be slow, but we only do it when necessary |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5099 |
getTag = function(tagName, tokens, i) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5100 |
// if a tagName is provided, use that |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5101 |
if (tagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5102 |
return tagName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5103 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5104 |
// otherwise go searching for the next two tokens like "<",TAG |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5105 |
while (i < tokens.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5106 |
if (tokens[i] === "<" && !notEndTag.test(tokens[i + 1])) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5107 |
return elements.reverseTagMap[tokens[i + 1]] || 'span'; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5108 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5109 |
i++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5110 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5111 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5112 |
return ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5113 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5114 |
bracketNum = function(content) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5115 |
return (--content.split("{") |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5116 |
.length) - (--content.split("}") |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5117 |
.length); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5118 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5119 |
myEval = function(script) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5120 |
eval(script); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5121 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5122 |
attrReg = /([^\s]+)[\s]*=[\s]*$/, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5123 |
// Commands for caching. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5124 |
startTxt = 'var ___v1ew = [];', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5125 |
finishTxt = "return ___v1ew.join('')", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5126 |
put_cmd = "___v1ew.push(\n", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5127 |
insert_cmd = put_cmd, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5128 |
// Global controls (used by other functions to know where we are). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5129 |
// Are we inside a tag? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5130 |
htmlTag = null, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5131 |
// Are we within a quote within a tag? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5132 |
quote = null, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5133 |
// What was the text before the current quote? (used to get the `attr` name) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5134 |
beforeQuote = null, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5135 |
// Whether a rescan is in progress |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5136 |
rescan = null, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5137 |
getAttrName = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5138 |
var matches = beforeQuote.match(attrReg); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5139 |
return matches && matches[1]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5140 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5141 |
// Used to mark where the element is. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5142 |
status = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5143 |
// `t` - `1`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5144 |
// `h` - `0`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5145 |
// `q` - String `beforeQuote`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5146 |
return quote ? "'" + getAttrName() + "'" : (htmlTag ? 1 : 0); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5147 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5148 |
// returns the top of a stack |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5149 |
top = function(stack) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5150 |
return stack[stack.length - 1]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5151 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5152 |
Scanner; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5153 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5154 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5155 |
can.view.Scanner = Scanner = function(options) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5156 |
// Set options on self |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5157 |
can.extend(this, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5158 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5159 |
text: {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5160 |
tokens: [] |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5161 |
}, options); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5162 |
// make sure it's an empty string if it's not |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5163 |
this.text.options = this.text.options || ""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5164 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5165 |
// Cache a token lookup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5166 |
this.tokenReg = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5167 |
this.tokenSimple = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5168 |
"<": "<", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5169 |
">": ">", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5170 |
'"': '"', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5171 |
"'": "'" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5172 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5173 |
this.tokenComplex = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5174 |
this.tokenMap = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5175 |
for (var i = 0, token; token = this.tokens[i]; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5176 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5177 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5178 |
// Save complex mappings (custom regexp) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5179 |
if (token[2]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5180 |
this.tokenReg.push(token[2]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5181 |
this.tokenComplex.push({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5182 |
abbr: token[1], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5183 |
re: new RegExp(token[2]), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5184 |
rescan: token[3] |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5185 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5186 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5187 |
// Save simple mappings (string only, no regexp) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5188 |
else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5189 |
this.tokenReg.push(token[1]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5190 |
this.tokenSimple[token[1]] = token[0]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5191 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5192 |
this.tokenMap[token[0]] = token[1]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5193 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5194 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5195 |
// Cache the token registry. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5196 |
this.tokenReg = new RegExp("(" + this.tokenReg.slice(0) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5197 |
.concat(["<", ">", '"', "'"]) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5198 |
.join("|") + ")", "g"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5199 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5200 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5201 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5202 |
Scanner.prototype = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5203 |
// a default that can be overwritten |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5204 |
helpers: [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5205 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5206 |
scan: function(source, name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5207 |
var tokens = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5208 |
last = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5209 |
simple = this.tokenSimple, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5210 |
complex = this.tokenComplex; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5211 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5212 |
source = source.replace(newLine, "\n"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5213 |
if (this.transform) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5214 |
source = this.transform(source); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5215 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5216 |
source.replace(this.tokenReg, function(whole, part) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5217 |
// offset is the second to last argument |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5218 |
var offset = arguments[arguments.length - 2]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5219 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5220 |
// if the next token starts after the last token ends |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5221 |
// push what's in between |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5222 |
if (offset > last) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5223 |
tokens.push(source.substring(last, offset)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5224 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5225 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5226 |
// push the simple token (if there is one) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5227 |
if (simple[whole]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5228 |
tokens.push(whole); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5229 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5230 |
// otherwise lookup complex tokens |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5231 |
else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5232 |
for (var i = 0, token; token = complex[i]; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5233 |
if (token.re.test(whole)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5234 |
tokens.push(token.abbr); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5235 |
// Push a rescan function if one exists |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5236 |
if (token.rescan) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5237 |
tokens.push(token.rescan(part)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5238 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5239 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5240 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5241 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5242 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5243 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5244 |
// update the position of the last part of the last token |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5245 |
last = offset + part.length; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5246 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5247 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5248 |
// if there's something at the end, add it |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5249 |
if (last < source.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5250 |
tokens.push(source.substr(last)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5251 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5252 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5253 |
var content = '', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5254 |
buff = [startTxt + (this.text.start || '')], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5255 |
// Helper `function` for putting stuff in the view concat. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5256 |
put = function(content, bonus) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5257 |
buff.push(put_cmd, '"', clean(content), '"' + (bonus || '') + ');'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5258 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5259 |
// A stack used to keep track of how we should end a bracket |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5260 |
// `}`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5261 |
// Once we have a `<%= %>` with a `leftBracket`, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5262 |
// we store how the file should end here (either `))` or `;`). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5263 |
endStack = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5264 |
// The last token, used to remember which tag we are in. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5265 |
lastToken, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5266 |
// The corresponding magic tag. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5267 |
startTag = null, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5268 |
// Was there a magic tag inside an html tag? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5269 |
magicInTag = false, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5270 |
// was there a special state |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5271 |
specialStates = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5272 |
attributeHookups: [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5273 |
// a stack of tagHookups |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5274 |
tagHookups: [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5275 |
//last tag hooked up |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5276 |
lastTagHookup: '' |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5277 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5278 |
// Helper `function` for removing tagHookups from the hookup stack |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5279 |
popTagHookup = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5280 |
// The length of tagHookups is the nested depth which can be used to uniquely identify custom tags of the same type |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5281 |
specialStates.lastTagHookup = specialStates.tagHookups.pop() + specialStates.tagHookups.length; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5282 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5283 |
// The current tag name. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5284 |
tagName = '', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5285 |
// stack of tagNames |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5286 |
tagNames = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5287 |
// Pop from tagNames? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5288 |
popTagName = false, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5289 |
// Declared here. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5290 |
bracketCount, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5291 |
// in a special attr like src= or style= |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5292 |
specialAttribute = false, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5293 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5294 |
i = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5295 |
token, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5296 |
tmap = this.tokenMap, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5297 |
attrName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5298 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5299 |
// Reinitialize the tag state goodness. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5300 |
htmlTag = quote = beforeQuote = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5301 |
for (; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5302 |
(token = tokens[i++]) !== undefined;) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5303 |
if (startTag === null) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5304 |
switch (token) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5305 |
case tmap.left: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5306 |
case tmap.escapeLeft: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5307 |
case tmap.returnLeft: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5308 |
magicInTag = htmlTag && 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5309 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5310 |
case tmap.commentLeft: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5311 |
// A new line -- just add whatever content within a clean. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5312 |
// Reset everything. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5313 |
startTag = token; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5314 |
if (content.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5315 |
put(content); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5316 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5317 |
content = ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5318 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5319 |
case tmap.escapeFull: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5320 |
// This is a full line escape (a line that contains only whitespace and escaped logic) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5321 |
// Break it up into escape left and right |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5322 |
magicInTag = htmlTag && 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5323 |
rescan = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5324 |
startTag = tmap.escapeLeft; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5325 |
if (content.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5326 |
put(content); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5327 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5328 |
rescan = tokens[i++]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5329 |
content = rescan.content || rescan; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5330 |
if (rescan.before) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5331 |
put(rescan.before); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5332 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5333 |
tokens.splice(i, 0, tmap.right); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5334 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5335 |
case tmap.commentFull: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5336 |
// Ignore full line comments. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5337 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5338 |
case tmap.templateLeft: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5339 |
content += tmap.left; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5340 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5341 |
case '<': |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5342 |
// Make sure we are not in a comment. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5343 |
if (tokens[i].indexOf("!--") !== 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5344 |
htmlTag = 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5345 |
magicInTag = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5346 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5347 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5348 |
content += token; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5349 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5350 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5351 |
case '>': |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5352 |
htmlTag = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5353 |
// content.substr(-1) doesn't work in IE7/8 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5354 |
var emptyElement = (content.substr(content.length - 1) === "/" || content.substr(content.length - 2) === "--"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5355 |
attrs = ""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5356 |
// if there was a magic tag |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5357 |
// or it's an element that has text content between its tags, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5358 |
// but content is not other tags add a hookup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5359 |
// TODO: we should only add `can.EJS.pending()` if there's a magic tag |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5360 |
// within the html tags. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5361 |
if (specialStates.attributeHookups.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5362 |
attrs = "attrs: ['" + specialStates.attributeHookups.join("','") + "'], "; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5363 |
specialStates.attributeHookups = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5364 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5365 |
// this is the > of a special tag |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5366 |
// comparison to lastTagHookup makes sure the same custom tags can be nested |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5367 |
if ((tagName + specialStates.tagHookups.length) !== specialStates.lastTagHookup && tagName === top(specialStates.tagHookups)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5368 |
// If it's a self closing tag (like <content/>) make sure we put the / at the end. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5369 |
if (emptyElement) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5370 |
content = content.substr(0, content.length - 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5371 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5372 |
// Put the start of the end |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5373 |
buff.push(put_cmd, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5374 |
'"', clean(content), '"', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5375 |
",can.view.pending({tagName:'" + tagName + "'," + (attrs) + "scope: " + (this.text.scope || "this") + this.text.options); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5376 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5377 |
// if it's a self closing tag (like <content/>) close and end the tag |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5378 |
if (emptyElement) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5379 |
buff.push("}));"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5380 |
content = "/>"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5381 |
popTagHookup(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5382 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5383 |
// if it's an empty tag |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5384 |
else if (tokens[i] === "<" && tokens[i + 1] === "/" + tagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5385 |
buff.push("}));"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5386 |
content = token; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5387 |
popTagHookup(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5388 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5389 |
// it has content |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5390 |
buff.push(",subtemplate: function(" + this.text.argNames + "){\n" + startTxt + (this.text.start || '')); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5391 |
content = ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5392 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5393 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5394 |
} else if (magicInTag || (!popTagName && elements.tagToContentPropMap[tagNames[tagNames.length - 1]]) || attrs) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5395 |
// make sure / of /> is on the right of pending |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5396 |
var pendingPart = ",can.view.pending({" + attrs + "scope: " + (this.text.scope || "this") + this.text.options + "}),\""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5397 |
if (emptyElement) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5398 |
put(content.substr(0, content.length - 1), pendingPart + "/>\""); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5399 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5400 |
put(content, pendingPart + ">\""); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5401 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5402 |
content = ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5403 |
magicInTag = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5404 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5405 |
content += token; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5406 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5407 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5408 |
// if it's a tag like <input/> |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5409 |
if (emptyElement || popTagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5410 |
// remove the current tag in the stack |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5411 |
tagNames.pop(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5412 |
// set the current tag to the previous parent |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5413 |
tagName = tagNames[tagNames.length - 1]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5414 |
// Don't pop next time |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5415 |
popTagName = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5416 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5417 |
specialStates.attributeHookups = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5418 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5419 |
case "'": |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5420 |
case '"': |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5421 |
// If we are in an html tag, finding matching quotes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5422 |
if (htmlTag) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5423 |
// We have a quote and it matches. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5424 |
if (quote && quote === token) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5425 |
// We are exiting the quote. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5426 |
quote = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5427 |
// Otherwise we are creating a quote. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5428 |
// TODO: does this handle `\`? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5429 |
var attr = getAttrName(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5430 |
if (viewCallbacks.attr(attr)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5431 |
specialStates.attributeHookups.push(attr); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5432 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5433 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5434 |
if (specialAttribute) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5435 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5436 |
content += token; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5437 |
put(content); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5438 |
buff.push(finishTxt, "}));\n"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5439 |
content = ""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5440 |
specialAttribute = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5441 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5442 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5443 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5444 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5445 |
} else if (quote === null) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5446 |
quote = token; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5447 |
beforeQuote = lastToken; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5448 |
attrName = getAttrName(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5449 |
// TODO: check if there's magic!!!! |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5450 |
if ((tagName === "img" && attrName === "src") || attrName === "style") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5451 |
// put content that was before the attr name, but don't include the src= |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5452 |
put(content.replace(attrReg, "")); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5453 |
content = ""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5454 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5455 |
specialAttribute = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5456 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5457 |
buff.push(insert_cmd, "can.view.txt(2,'" + getTag(tagName, tokens, i) + "'," + status() + ",this,function(){", startTxt); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5458 |
put(attrName + "=" + token); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5459 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5460 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5461 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5462 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5463 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5464 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5465 |
default: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5466 |
// Track the current tag |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5467 |
if (lastToken === '<') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5468 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5469 |
tagName = token.substr(0, 3) === "!--" ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5470 |
"!--" : token.split(/\s/)[0]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5471 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5472 |
var isClosingTag = false, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5473 |
cleanedTagName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5474 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5475 |
if (tagName.indexOf("/") === 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5476 |
isClosingTag = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5477 |
cleanedTagName = tagName.substr(1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5478 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5479 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5480 |
if (isClosingTag) { // </tag> |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5481 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5482 |
// when we enter a new tag, pop the tag name stack |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5483 |
if (top(tagNames) === cleanedTagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5484 |
// set tagName to the last tagName |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5485 |
// if there are no more tagNames, we'll rely on getTag. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5486 |
tagName = cleanedTagName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5487 |
popTagName = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5488 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5489 |
// if we are in a closing tag of a custom tag |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5490 |
if (top(specialStates.tagHookups) === cleanedTagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5491 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5492 |
// remove the last < from the content |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5493 |
put(content.substr(0, content.length - 1)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5494 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5495 |
// finish the "section" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5496 |
buff.push(finishTxt + "}}) );"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5497 |
// the < belongs to the outside |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5498 |
content = "><"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5499 |
popTagHookup(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5500 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5501 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5502 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5503 |
if (tagName.lastIndexOf("/") === tagName.length - 1) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5504 |
tagName = tagName.substr(0, tagName.length - 1); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5505 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5506 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5507 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5508 |
if (tagName !== "!--" && (viewCallbacks.tag(tagName))) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5509 |
// if the content tag is inside something it doesn't belong ... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5510 |
if (tagName === "content" && elements.tagMap[top(tagNames)]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5511 |
// convert it to an element that will work |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5512 |
token = token.replace("content", elements.tagMap[top(tagNames)]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5513 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5514 |
// we will hookup at the ending tag> |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5515 |
specialStates.tagHookups.push(tagName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5516 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5517 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5518 |
tagNames.push(tagName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5519 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5520 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5521 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5522 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5523 |
content += token; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5524 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5525 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5526 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5527 |
// We have a start tag. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5528 |
switch (token) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5529 |
case tmap.right: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5530 |
case tmap.returnRight: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5531 |
switch (startTag) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5532 |
case tmap.left: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5533 |
// Get the number of `{ minus }` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5534 |
bracketCount = bracketNum(content); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5535 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5536 |
// We are ending a block. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5537 |
if (bracketCount === 1) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5538 |
// We are starting on. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5539 |
buff.push(insert_cmd, 'can.view.txt(0,\'' + getTag(tagName, tokens, i) + '\',' + status() + ',this,function(){', startTxt, content); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5540 |
endStack.push({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5541 |
before: "", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5542 |
after: finishTxt + "}));\n" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5543 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5544 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5545 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5546 |
// How are we ending this statement? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5547 |
last = // If the stack has value and we are ending a block... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5548 |
endStack.length && bracketCount === -1 ? // Use the last item in the block stack. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5549 |
endStack.pop() : // Or use the default ending. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5550 |
{ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5551 |
after: ";" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5552 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5553 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5554 |
// If we are ending a returning block, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5555 |
// add the finish text which returns the result of the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5556 |
// block. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5557 |
if (last.before) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5558 |
buff.push(last.before); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5559 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5560 |
// Add the remaining content. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5561 |
buff.push(content, ";", last.after); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5562 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5563 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5564 |
case tmap.escapeLeft: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5565 |
case tmap.returnLeft: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5566 |
// We have an extra `{` -> `block`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5567 |
// Get the number of `{ minus }`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5568 |
bracketCount = bracketNum(content); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5569 |
// If we have more `{`, it means there is a block. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5570 |
if (bracketCount) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5571 |
// When we return to the same # of `{` vs `}` end with a `doubleParent`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5572 |
endStack.push({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5573 |
before: finishTxt, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5574 |
after: "}));\n" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5575 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5576 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5577 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5578 |
var escaped = startTag === tmap.escapeLeft ? 1 : 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5579 |
commands = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5580 |
insert: insert_cmd, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5581 |
tagName: getTag(tagName, tokens, i), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5582 |
status: status(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5583 |
specialAttribute: specialAttribute |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5584 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5585 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5586 |
for (var ii = 0; ii < this.helpers.length; ii++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5587 |
// Match the helper based on helper |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5588 |
// regex name value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5589 |
var helper = this.helpers[ii]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5590 |
if (helper.name.test(content)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5591 |
content = helper.fn(content, commands); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5592 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5593 |
// dont escape partials |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5594 |
if (helper.name.source === /^>[\s]*\w*/.source) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5595 |
escaped = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5596 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5597 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5598 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5599 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5600 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5601 |
// Handle special cases |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5602 |
if (typeof content === 'object') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5603 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5604 |
if (content.startTxt && content.end && specialAttribute) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5605 |
buff.push(insert_cmd, "can.view.toStr( ", content.content, '() ) );'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5606 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5607 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5608 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5609 |
if (content.startTxt) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5610 |
buff.push(insert_cmd, "can.view.txt(\n" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5611 |
(typeof status() === "string" || (content.escaped != null ? content.escaped : escaped)) + ",\n'" + tagName + "',\n" + status() + ",\nthis,\n"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5612 |
} else if (content.startOnlyTxt) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5613 |
buff.push(insert_cmd, 'can.view.onlytxt(this,\n'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5614 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5615 |
buff.push(content.content); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5616 |
if (content.end) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5617 |
buff.push('));'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5618 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5619 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5620 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5621 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5622 |
} else if (specialAttribute) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5623 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5624 |
buff.push(insert_cmd, content, ');'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5625 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5626 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5627 |
// If we have `<%== a(function(){ %>` then we want |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5628 |
// `can.EJS.text(0,this, function(){ return a(function(){ var _v1ew = [];`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5629 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5630 |
buff.push(insert_cmd, "can.view.txt(\n" + (typeof status() === "string" || escaped) + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5631 |
",\n'" + tagName + "',\n" + status() + ",\nthis,\nfunction(){ " + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5632 |
(this.text.escape || '') + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5633 |
"return ", content, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5634 |
// If we have a block. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5635 |
bracketCount ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5636 |
// Start with startTxt `"var _v1ew = [];"`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5637 |
startTxt : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5638 |
// If not, add `doubleParent` to close push and text. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5639 |
"}));\n"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5640 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5641 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5642 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5643 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5644 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5645 |
if (rescan && rescan.after && rescan.after.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5646 |
put(rescan.after.length); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5647 |
rescan = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5648 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5649 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5650 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5651 |
startTag = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5652 |
content = ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5653 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5654 |
case tmap.templateLeft: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5655 |
content += tmap.left; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5656 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5657 |
default: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5658 |
content += token; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5659 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5660 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5661 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5662 |
lastToken = token; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5663 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5664 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5665 |
// Put it together... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5666 |
if (content.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5667 |
// Should be `content.dump` in Ruby. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5668 |
put(content); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5669 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5670 |
buff.push(";"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5671 |
var template = buff.join(''), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5672 |
out = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5673 |
out: (this.text.outStart || "") + template + " " + finishTxt + (this.text.outEnd || "") |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5674 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5675 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5676 |
// Use `eval` instead of creating a function, because it is easier to debug. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5677 |
myEval.call(out, 'this.fn = (function(' + this.text.argNames + '){' + out.out + '});\r\n//# sourceURL=' + name + '.js'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5678 |
return out; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5679 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5680 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5681 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5682 |
// can.view.attr |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5683 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5684 |
// This is called when there is a special tag |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5685 |
can.view.pending = function(viewData) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5686 |
// we need to call any live hookups |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5687 |
// so get that and return the hook |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5688 |
// a better system will always be called with the same stuff |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5689 |
var hooks = can.view.getHooks(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5690 |
return can.view.hook(function(el) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5691 |
can.each(hooks, function(fn) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5692 |
fn(el); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5693 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5694 |
viewData.templateType = "legacy"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5695 |
if (viewData.tagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5696 |
viewCallbacks.tagHandler(el, viewData.tagName, viewData); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5697 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5698 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5699 |
can.each(viewData && viewData.attrs || [], function(attributeName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5700 |
viewData.attributeName = attributeName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5701 |
var callback = viewCallbacks.attr(attributeName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5702 |
if (callback) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5703 |
callback(el, viewData); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5704 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5705 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5706 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5707 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5708 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5709 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5710 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5711 |
can.view.tag("content", function(el, tagData) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5712 |
return tagData.scope; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5713 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5714 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5715 |
can.view.Scanner = Scanner; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5716 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5717 |
return Scanner; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5718 |
})(__m17, __m24, __m25); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5719 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5720 |
// ## can/view/node_lists/node_lists.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5721 |
var __m28 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5722 |
// ## Helpers |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5723 |
// Some browsers don't allow expando properties on HTMLTextNodes |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5724 |
// so let's try to assign a custom property, an 'expando' property. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5725 |
// We use this boolean to determine how we are going to hold on |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5726 |
// to HTMLTextNode within a nodeList. More about this in the 'id' |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5727 |
// function. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5728 |
var canExpando = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5729 |
try { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5730 |
document.createTextNode('')._ = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5731 |
} catch (ex) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5732 |
canExpando = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5733 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5734 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5735 |
// A mapping of element ids to nodeList id allowing us to quickly find an element |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5736 |
// that needs to be replaced when updated. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5737 |
var nodeMap = {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5738 |
// A mapping of ids to text nodes, this map will be used in the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5739 |
// case of the browser not supporting expando properties. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5740 |
textNodeMap = {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5741 |
// The name of the expando property; the value returned |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5742 |
// given a nodeMap key. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5743 |
expando = 'ejs_' + Math.random(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5744 |
// The id used as the key in our nodeMap, this integer |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5745 |
// will be preceded by 'element_' or 'obj_' depending on whether |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5746 |
// the element has a nodeName. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5747 |
_id = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5748 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5749 |
// ## nodeLists.id |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5750 |
// Given a template node, create an id on the node as a expando |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5751 |
// property, or if the node is an HTMLTextNode and the browser |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5752 |
// doesn't support expando properties store the id with a |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5753 |
// reference to the text node in an internal collection then return |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5754 |
// the lookup id. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5755 |
id = function(node) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5756 |
// If the browser supports expando properties or the node |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5757 |
// provided is not an HTMLTextNode, we don't need to work |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5758 |
// with the internal textNodeMap and we can place the property |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5759 |
// on the node. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5760 |
if (canExpando || node.nodeType !== 3) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5761 |
// If the node already has an (internal) id, then just |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5762 |
// return the key of the nodeMap. This would be the case |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5763 |
// in updating and unregistering a nodeList. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5764 |
if (node[expando]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5765 |
return node[expando]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5766 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5767 |
// If the node isn't already referenced in the map we need |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5768 |
// to generate a lookup id and place it on the node itself. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5769 |
++_id; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5770 |
return node[expando] = (node.nodeName ? 'element_' : 'obj_') + _id; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5771 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5772 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5773 |
// The nodeList has a specific collection for HTMLTextNodes for |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5774 |
// (older) browsers that do not support expando properties. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5775 |
for (var textNodeID in textNodeMap) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5776 |
if (textNodeMap[textNodeID] === node) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5777 |
return textNodeID; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5778 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5779 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5780 |
// If we didn't find the node, we need to register it and return |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5781 |
// the id used. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5782 |
++_id; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5783 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5784 |
// If we didn't find the node, we need to register it and return |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5785 |
// the id used. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5786 |
// We have to store the node itself because of the browser's lack |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5787 |
// of support for expando properties (i.e. we can't use a look-up |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5788 |
// table and store the id on the node as a custom property). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5789 |
textNodeMap['text_' + _id] = node; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5790 |
return 'text_' + _id; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5791 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5792 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5793 |
splice = [].splice, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5794 |
push = [].push, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5795 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5796 |
// ## nodeLists.itemsInChildListTree |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5797 |
// Given a nodeList return the number of child items in the provided |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5798 |
// list and any child lists. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5799 |
itemsInChildListTree = function(list) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5800 |
var count = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5801 |
for (var i = 0, len = list.length; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5802 |
var item = list[i]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5803 |
// If the item is an HTMLElement then increment the count by 1. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5804 |
if (item.nodeType) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5805 |
count++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5806 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5807 |
// If the item is not an HTMLElement it is a list, so |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5808 |
// increment the count by the number of items in the child |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5809 |
// list. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5810 |
count += itemsInChildListTree(item); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5811 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5812 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5813 |
return count; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5814 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5815 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5816 |
// ## Registering & Updating |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5817 |
// To keep all live-bound sections knowing which elements they are managing, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5818 |
// all live-bound elments are registered and updated when they change. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5819 |
// For example, the above template, when rendered with data like: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5820 |
// data = new can.Map({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5821 |
// items: ["first","second"] |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5822 |
// }) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5823 |
// This will first render the following content: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5824 |
// <div> |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5825 |
// <span data-view-id='5'/> |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5826 |
// </div> |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5827 |
// When the `5` callback is called, this will register the `<span>` like: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5828 |
// var ifsNodes = [<span 5>] |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5829 |
// nodeLists.register(ifsNodes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5830 |
// And then render `{{if}}`'s contents and update `ifsNodes` with it: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5831 |
// nodeLists.update( ifsNodes, [<"\nItems:\n">, <span data-view-id="6">] ); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5832 |
// Next, hookup `6` is called which will regsiter the `<span>` like: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5833 |
// var eachsNodes = [<span 6>]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5834 |
// nodeLists.register(eachsNodes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5835 |
// And then it will render `{{#each}}`'s content and update `eachsNodes` with it: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5836 |
// nodeLists.update(eachsNodes, [<label>,<label>]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5837 |
// As `nodeLists` knows that `eachsNodes` is inside `ifsNodes`, it also updates |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5838 |
// `ifsNodes`'s nodes to look like: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5839 |
// [<"\nItems:\n">,<label>,<label>] |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5840 |
// Now, if all items were removed, `{{#if}}` would be able to remove |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5841 |
// all the `<label>` elements. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5842 |
// When you regsiter a nodeList, you can also provide a callback to know when |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5843 |
// that nodeList has been replaced by a parent nodeList. This is |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5844 |
// useful for tearing down live-binding. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5845 |
var nodeLists = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5846 |
id: id, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5847 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5848 |
// ## nodeLists.update |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5849 |
// Updates a nodeList with new items, i.e. when values for the template have changed. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5850 |
update: function(nodeList, newNodes) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5851 |
// Unregister all childNodeLists. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5852 |
var oldNodes = nodeLists.unregisterChildren(nodeList); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5853 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5854 |
newNodes = can.makeArray(newNodes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5855 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5856 |
var oldListLength = nodeList.length; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5857 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5858 |
// Replace oldNodeLists's contents. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5859 |
splice.apply(nodeList, [ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5860 |
0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5861 |
oldListLength |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5862 |
].concat(newNodes)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5863 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5864 |
nodeLists.nestList(nodeList); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5865 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5866 |
return oldNodes; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5867 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5868 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5869 |
// ## nodeLists.nestList |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5870 |
// If a given list does not exist in the nodeMap then create an lookup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5871 |
// id for it in the nodeMap and assign the list to it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5872 |
// If the the provided does happen to exist in the nodeMap update the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5873 |
// elements in the list. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5874 |
// @param {Array.<HTMLElement>} nodeList The nodeList being nested. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5875 |
nestList: function(list) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5876 |
var index = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5877 |
while (index < list.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5878 |
var node = list[index], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5879 |
childNodeList = nodeMap[id(node)]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5880 |
if (childNodeList) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5881 |
if (childNodeList !== list) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5882 |
list.splice(index, itemsInChildListTree(childNodeList), childNodeList); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5883 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5884 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5885 |
// Indicate the new nodes belong to this list. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5886 |
nodeMap[id(node)] = list; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5887 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5888 |
index++; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5889 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5890 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5891 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5892 |
// ## nodeLists.last |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5893 |
// Return the last HTMLElement in a nodeList, if the last |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5894 |
// element is a nodeList, returns the last HTMLElement of |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5895 |
// the child list, etc. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5896 |
last: function(nodeList) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5897 |
var last = nodeList[nodeList.length - 1]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5898 |
// If the last node in the list is not an HTMLElement |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5899 |
// it is a nodeList so call `last` again. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5900 |
if (last.nodeType) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5901 |
return last; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5902 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5903 |
return nodeLists.last(last); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5904 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5905 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5906 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5907 |
// ## nodeLists.first |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5908 |
// Return the first HTMLElement in a nodeList, if the first |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5909 |
// element is a nodeList, returns the first HTMLElement of |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5910 |
// the child list, etc. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5911 |
first: function(nodeList) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5912 |
var first = nodeList[0]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5913 |
// If the first node in the list is not an HTMLElement |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5914 |
// it is a nodeList so call `first` again. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5915 |
if (first.nodeType) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5916 |
return first; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5917 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5918 |
return nodeLists.first(first); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5919 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5920 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5921 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5922 |
// ## nodeLists.register |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5923 |
// Registers a nodeList and returns the nodeList passed to register |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5924 |
register: function(nodeList, unregistered, parent) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5925 |
// If a unregistered callback has been provided assign it to the nodeList |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5926 |
// as a property to be called when the nodeList is unregistred. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5927 |
nodeList.unregistered = unregistered; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5928 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5929 |
nodeLists.nestList(nodeList); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5930 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5931 |
return nodeList; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5932 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5933 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5934 |
// ## nodeLists.unregisterChildren |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5935 |
// Unregister all childen within the provided list and return the |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5936 |
// unregistred nodes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5937 |
// @param {Array.<HTMLElement>} nodeList The child list to unregister. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5938 |
unregisterChildren: function(nodeList) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5939 |
var nodes = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5940 |
// For each node in the nodeList we want to compute it's id |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5941 |
// and delete it from the nodeList's internal map. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5942 |
can.each(nodeList, function(node) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5943 |
// If the node does not have a nodeType it is an array of |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5944 |
// nodes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5945 |
if (node.nodeType) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5946 |
delete nodeMap[id(node)]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5947 |
nodes.push(node); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5948 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5949 |
// Recursively unregister each of the child lists in |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5950 |
// the nodeList. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5951 |
push.apply(nodes, nodeLists.unregister(node)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5952 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5953 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5954 |
return nodes; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5955 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5956 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5957 |
// ## nodeLists.unregister |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5958 |
// Unregister's a nodeList and returns the unregistered nodes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5959 |
// Call if the nodeList is no longer being updated. This will |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5960 |
// also unregister all child nodeLists. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5961 |
unregister: function(nodeList) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5962 |
var nodes = nodeLists.unregisterChildren(nodeList); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5963 |
// If an 'unregisted' function was provided during registration, remove |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5964 |
// it from the list, and call the function provided. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5965 |
if (nodeList.unregistered) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5966 |
var unregisteredCallback = nodeList.unregistered; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5967 |
delete nodeList.unregistered; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5968 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5969 |
unregisteredCallback(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5970 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5971 |
return nodes; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5972 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5973 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5974 |
nodeMap: nodeMap |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5975 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5976 |
can.view.nodeLists = nodeLists; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5977 |
return nodeLists; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5978 |
})(__m3, __m24); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5979 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5980 |
// ## can/view/parser/parser.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5981 |
var __m29 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5982 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5983 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5984 |
function makeMap(str) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5985 |
var obj = {}, items = str.split(","); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5986 |
for (var i = 0; i < items.length; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5987 |
obj[items[i]] = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5988 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5989 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5990 |
return obj; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5991 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5992 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5993 |
var alphaNumericHU = "-A-Za-z0-9_", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5994 |
attributeNames = "[a-zA-Z_:][" + alphaNumericHU + ":.]+", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5995 |
spaceEQspace = "\\s*=\\s*", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5996 |
dblQuote2dblQuote = "\"((?:\\\\.|[^\"])*)\"", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5997 |
quote2quote = "'((?:\\\\.|[^'])*)'", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5998 |
attributeEqAndValue = "(?:" + spaceEQspace + "(?:" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5999 |
"(?:\"[^\"]*\")|(?:'[^']*')|[^>\\s]+))?", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6000 |
matchStash = "\\{\\{[^\\}]*\\}\\}\\}?", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6001 |
stash = "\\{\\{([^\\}]*)\\}\\}\\}?", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6002 |
startTag = new RegExp("^<([" + alphaNumericHU + "]+)" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6003 |
"(" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6004 |
"(?:\\s*" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6005 |
"(?:(?:" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6006 |
"(?:" + attributeNames + ")?" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6007 |
attributeEqAndValue + ")|" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6008 |
"(?:" + matchStash + ")+)" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6009 |
")*" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6010 |
")\\s*(\\/?)>"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6011 |
endTag = new RegExp("^<\\/([" + alphaNumericHU + "]+)[^>]*>"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6012 |
attr = new RegExp("(?:" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6013 |
"(?:(" + attributeNames + ")|" + stash + ")" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6014 |
"(?:" + spaceEQspace + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6015 |
"(?:" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6016 |
"(?:" + dblQuote2dblQuote + ")|(?:" + quote2quote + ")|([^>\\s]+)" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6017 |
")" + |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6018 |
")?)", "g"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6019 |
mustache = new RegExp(stash, "g"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6020 |
txtBreak = /<|\{\{/; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6021 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6022 |
// Empty Elements - HTML 5 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6023 |
var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6024 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6025 |
// Block Elements - HTML 5 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6026 |
var block = makeMap("address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6027 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6028 |
// Inline Elements - HTML 5 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6029 |
var inline = makeMap("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6030 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6031 |
// Elements that you can, intentionally, leave open |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6032 |
// (and which close themselves) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6033 |
var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6034 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6035 |
// Attributes that have their values filled in disabled="disabled" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6036 |
var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6037 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6038 |
// Special Elements (can contain anything) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6039 |
var special = makeMap("script,style"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6040 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6041 |
var HTMLParser = function(html, handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6042 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6043 |
function parseStartTag(tag, tagName, rest, unary) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6044 |
tagName = tagName.toLowerCase(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6045 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6046 |
if (block[tagName]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6047 |
while (stack.last() && inline[stack.last()]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6048 |
parseEndTag("", stack.last()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6049 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6050 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6051 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6052 |
if (closeSelf[tagName] && stack.last() === tagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6053 |
parseEndTag("", tagName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6054 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6055 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6056 |
unary = empty[tagName] || !! unary; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6057 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6058 |
handler.start(tagName, unary); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6059 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6060 |
if (!unary) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6061 |
stack.push(tagName); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6062 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6063 |
// find attribute or special |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6064 |
HTMLParser.parseAttrs(rest, handler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6065 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6066 |
handler.end(tagName, unary); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6067 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6068 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6069 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6070 |
function parseEndTag(tag, tagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6071 |
// If no tag name is provided, clean shop |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6072 |
var pos; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6073 |
if (!tagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6074 |
pos = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6075 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6076 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6077 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6078 |
// Find the closest opened tag of the same type |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6079 |
else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6080 |
for (pos = stack.length - 1; pos >= 0; pos--) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6081 |
if (stack[pos] === tagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6082 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6083 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6084 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6085 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6086 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6087 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6088 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6089 |
if (pos >= 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6090 |
// Close all the open elements, up the stack |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6091 |
for (var i = stack.length - 1; i >= pos; i--) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6092 |
if (handler.close) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6093 |
handler.close(stack[i]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6094 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6095 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6096 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6097 |
// Remove the open elements from the stack |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6098 |
stack.length = pos; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6099 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6100 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6101 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6102 |
function parseMustache(mustache, inside) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6103 |
if (handler.special) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6104 |
handler.special(inside); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6105 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6106 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6107 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6108 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6109 |
var index, chars, match, stack = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6110 |
last = html; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6111 |
stack.last = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6112 |
return this[this.length - 1]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6113 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6114 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6115 |
while (html) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6116 |
chars = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6117 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6118 |
// Make sure we're not in a script or style element |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6119 |
if (!stack.last() || !special[stack.last()]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6120 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6121 |
// Comment |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6122 |
if (html.indexOf("<!--") === 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6123 |
index = html.indexOf("-->"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6124 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6125 |
if (index >= 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6126 |
if (handler.comment) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6127 |
handler.comment(html.substring(4, index)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6128 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6129 |
html = html.substring(index + 3); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6130 |
chars = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6131 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6132 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6133 |
// end tag |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6134 |
} else if (html.indexOf("</") === 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6135 |
match = html.match(endTag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6136 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6137 |
if (match) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6138 |
html = html.substring(match[0].length); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6139 |
match[0].replace(endTag, parseEndTag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6140 |
chars = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6141 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6142 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6143 |
// start tag |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6144 |
} else if (html.indexOf("<") === 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6145 |
match = html.match(startTag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6146 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6147 |
if (match) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6148 |
html = html.substring(match[0].length); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6149 |
match[0].replace(startTag, parseStartTag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6150 |
chars = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6151 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6152 |
} else if (html.indexOf("{{") === 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6153 |
match = html.match(mustache); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6154 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6155 |
if (match) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6156 |
html = html.substring(match[0].length); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6157 |
match[0].replace(mustache, parseMustache); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6158 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6159 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6160 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6161 |
if (chars) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6162 |
index = html.search(txtBreak); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6163 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6164 |
var text = index < 0 ? html : html.substring(0, index); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6165 |
html = index < 0 ? "" : html.substring(index); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6166 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6167 |
if (handler.chars && text) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6168 |
handler.chars(text); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6169 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6170 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6171 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6172 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6173 |
html = html.replace(new RegExp("([\\s\\S]*?)<\/" + stack.last() + "[^>]*>"), function(all, text) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6174 |
text = text.replace(/<!--([\s\S]*?)-->|<!\[CDATA\[([\s\S]*?)]]>/g, "$1$2"); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6175 |
if (handler.chars) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6176 |
handler.chars(text); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6177 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6178 |
return ""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6179 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6180 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6181 |
parseEndTag("", stack.last()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6182 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6183 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6184 |
if (html === last) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6185 |
throw "Parse Error: " + html; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6186 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6187 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6188 |
last = html; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6189 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6190 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6191 |
// Clean up any remaining tags |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6192 |
parseEndTag(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6193 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6194 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6195 |
handler.done(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6196 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6197 |
HTMLParser.parseAttrs = function(rest, handler) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6198 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6199 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6200 |
(rest != null ? rest : "").replace(attr, function(text, name, special, dblQuote, singleQuote, val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6201 |
if (special) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6202 |
handler.special(special); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6203 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6204 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6205 |
if (name || dblQuote || singleQuote || val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6206 |
var value = arguments[3] ? arguments[3] : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6207 |
arguments[4] ? arguments[4] : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6208 |
arguments[5] ? arguments[5] : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6209 |
fillAttrs[name.toLowerCase()] ? name : ""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6210 |
handler.attrStart(name || ""); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6211 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6212 |
var last = mustache.lastIndex = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6213 |
res = mustache.exec(value), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6214 |
chars; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6215 |
while (res) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6216 |
chars = value.substring( |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6217 |
last, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6218 |
mustache.lastIndex - res[0].length); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6219 |
if (chars.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6220 |
handler.attrValue(chars); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6221 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6222 |
handler.special(res[1]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6223 |
last = mustache.lastIndex; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6224 |
res = mustache.exec(value); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6225 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6226 |
chars = value.substr( |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6227 |
last, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6228 |
value.length); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6229 |
if (chars) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6230 |
handler.attrValue(chars); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6231 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6232 |
handler.attrEnd(name || ""); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6233 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6234 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6235 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6236 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6237 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6238 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6239 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6240 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6241 |
can.view.parser = HTMLParser; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6242 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6243 |
return HTMLParser; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6244 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6245 |
})(__m17); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6246 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6247 |
// ## can/view/live/live.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6248 |
var __m27 = (function(can, elements, view, nodeLists, parser) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6249 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6250 |
elements = elements || can.view.elements; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6251 |
nodeLists = nodeLists || can.view.NodeLists; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6252 |
parser = parser || can.view.parser; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6253 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6254 |
// ## live.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6255 |
// The live module provides live binding for computes |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6256 |
// and can.List. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6257 |
// Currently, it's API is designed for `can/view/render`, but |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6258 |
// it could easily be used for other purposes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6259 |
// ### Helper methods |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6260 |
// #### setup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6261 |
// `setup(HTMLElement, bind(data), unbind(data)) -> data` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6262 |
// Calls bind right away, but will call unbind |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6263 |
// if the element is "destroyed" (removed from the DOM). |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6264 |
var setup = function(el, bind, unbind) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6265 |
// Removing an element can call teardown which |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6266 |
// unregister the nodeList which calls teardown |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6267 |
var tornDown = false, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6268 |
teardown = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6269 |
if (!tornDown) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6270 |
tornDown = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6271 |
unbind(data); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6272 |
can.unbind.call(el, 'removed', teardown); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6273 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6274 |
return true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6275 |
}, data = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6276 |
teardownCheck: function(parent) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6277 |
return parent ? false : teardown(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6278 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6279 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6280 |
can.bind.call(el, 'removed', teardown); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6281 |
bind(data); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6282 |
return data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6283 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6284 |
// #### listen |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6285 |
// Calls setup, but presets bind and unbind to |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6286 |
// operate on a compute |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6287 |
listen = function(el, compute, change) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6288 |
return setup(el, function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6289 |
compute.bind('change', change); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6290 |
}, function(data) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6291 |
compute.unbind('change', change); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6292 |
if (data.nodeList) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6293 |
nodeLists.unregister(data.nodeList); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6294 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6295 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6296 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6297 |
// #### getAttributeParts |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6298 |
// Breaks up a string like foo='bar' into ["foo","'bar'""] |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6299 |
getAttributeParts = function(newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6300 |
var attrs = {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6301 |
attr; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6302 |
parser.parseAttrs(newVal, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6303 |
attrStart: function(name) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6304 |
attrs[name] = ""; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6305 |
attr = name; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6306 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6307 |
attrValue: function(value) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6308 |
attrs[attr] += value; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6309 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6310 |
attrEnd: function() {} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6311 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6312 |
return attrs; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6313 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6314 |
splice = [].splice, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6315 |
isNode = function(obj) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6316 |
return obj && obj.nodeType; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6317 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6318 |
addTextNodeIfNoChildren = function(frag) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6319 |
if (!frag.childNodes.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6320 |
frag.appendChild(document.createTextNode("")); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6321 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6322 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6323 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6324 |
var live = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6325 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6326 |
list: function(el, compute, render, context, parentNode) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6327 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6328 |
// A nodeList of all elements this live-list manages. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6329 |
// This is here so that if this live list is within another section |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6330 |
// that section is able to remove the items in this list. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6331 |
var masterNodeList = [el], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6332 |
// A mapping of items to their indicies' |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6333 |
indexMap = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6334 |
// Called when items are added to the list. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6335 |
add = function(ev, items, index) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6336 |
// Collect new html and mappings |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6337 |
var frag = document.createDocumentFragment(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6338 |
newNodeLists = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6339 |
newIndicies = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6340 |
// For each new item, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6341 |
can.each(items, function(item, key) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6342 |
var itemIndex = can.compute(key + index), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6343 |
// get its string content |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6344 |
itemHTML = render.call(context, item, itemIndex), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6345 |
gotText = typeof itemHTML === "string", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6346 |
// and convert it into elements. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6347 |
itemFrag = can.frag(itemHTML); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6348 |
// Add those elements to the mappings. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6349 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6350 |
itemFrag = gotText ? can.view.hookup(itemFrag) : itemFrag; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6351 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6352 |
var childNodes = can.makeArray(itemFrag.childNodes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6353 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6354 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6355 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6356 |
newNodeLists.push(nodeLists.register(childNodes)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6357 |
// Hookup the fragment (which sets up child live-bindings) and |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6358 |
// add it to the collection of all added elements. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6359 |
frag.appendChild(itemFrag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6360 |
// track indicies; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6361 |
newIndicies.push(itemIndex); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6362 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6363 |
// The position of elements is always after the initial text placeholder node |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6364 |
var masterListIndex = index + 1; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6365 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6366 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6367 |
// Check if we are adding items at the end |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6368 |
if (!masterNodeList[masterListIndex]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6369 |
elements.after(masterListIndex === 1 ? [text] : [nodeLists.last(masterNodeList[masterListIndex - 1])], frag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6370 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6371 |
// Add elements before the next index's first element. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6372 |
var el = nodeLists.first(masterNodeList[masterListIndex]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6373 |
can.insertBefore(el.parentNode, frag, el); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6374 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6375 |
splice.apply(masterNodeList, [ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6376 |
masterListIndex, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6377 |
0 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6378 |
].concat(newNodeLists)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6379 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6380 |
// update indices after insert point |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6381 |
splice.apply(indexMap, [ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6382 |
index, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6383 |
0 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6384 |
].concat(newIndicies)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6385 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6386 |
for (var i = index + newIndicies.length, len = indexMap.length; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6387 |
indexMap[i](i); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6388 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6389 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6390 |
// Called when items are removed or when the bindings are torn down. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6391 |
remove = function(ev, items, index, duringTeardown, fullTeardown) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6392 |
// If this is because an element was removed, we should |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6393 |
// check to make sure the live elements are still in the page. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6394 |
// If we did this during a teardown, it would cause an infinite loop. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6395 |
if (!duringTeardown && data.teardownCheck(text.parentNode)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6396 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6397 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6398 |
var removedMappings = masterNodeList.splice(index + 1, items.length), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6399 |
itemsToRemove = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6400 |
can.each(removedMappings, function(nodeList) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6401 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6402 |
// Unregister to free up event bindings. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6403 |
var nodesToRemove = nodeLists.unregister(nodeList); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6404 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6405 |
// add items that we will remove all at once |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6406 |
[].push.apply(itemsToRemove, nodesToRemove); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6407 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6408 |
// update indices after remove point |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6409 |
indexMap.splice(index, items.length); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6410 |
for (var i = index, len = indexMap.length; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6411 |
indexMap[i](i); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6412 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6413 |
// don't remove elements during teardown. Something else will probably be doing that. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6414 |
if (!fullTeardown) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6415 |
can.remove(can.$(itemsToRemove)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6416 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6417 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6418 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6419 |
// A text node placeholder |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6420 |
text = document.createTextNode(''), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6421 |
// The current list. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6422 |
list, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6423 |
// Called when the list is replaced with a new list or the binding is torn-down. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6424 |
teardownList = function(fullTeardown) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6425 |
// there might be no list right away, and the list might be a plain |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6426 |
// array |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6427 |
if (list && list.unbind) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6428 |
list.unbind('add', add) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6429 |
.unbind('remove', remove); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6430 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6431 |
// use remove to clean stuff up for us |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6432 |
remove({}, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6433 |
length: masterNodeList.length - 1 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6434 |
}, 0, true, fullTeardown); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6435 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6436 |
// Called when the list is replaced or setup. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6437 |
updateList = function(ev, newList, oldList) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6438 |
teardownList(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6439 |
// make an empty list if the compute returns null or undefined |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6440 |
list = newList || []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6441 |
// list might be a plain array |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6442 |
if (list.bind) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6443 |
list.bind('add', add) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6444 |
.bind('remove', remove); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6445 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6446 |
add({}, list, 0); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6447 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6448 |
parentNode = elements.getParentNode(el, parentNode); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6449 |
// Setup binding and teardown to add and remove events |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6450 |
var data = setup(parentNode, function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6451 |
if (can.isFunction(compute)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6452 |
compute.bind('change', updateList); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6453 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6454 |
}, function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6455 |
if (can.isFunction(compute)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6456 |
compute.unbind('change', updateList); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6457 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6458 |
teardownList(true); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6459 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6460 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6461 |
live.replace(masterNodeList, text, data.teardownCheck); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6462 |
// run the list setup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6463 |
updateList({}, can.isFunction(compute) ? compute() : compute); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6464 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6465 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6466 |
html: function(el, compute, parentNode) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6467 |
var data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6468 |
parentNode = elements.getParentNode(el, parentNode); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6469 |
data = listen(parentNode, compute, function(ev, newVal, oldVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6470 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6471 |
// TODO: remove teardownCheck in 2.1 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6472 |
var attached = nodeLists.first(nodes).parentNode; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6473 |
// update the nodes in the DOM with the new rendered value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6474 |
if (attached) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6475 |
makeAndPut(newVal); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6476 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6477 |
data.teardownCheck(nodeLists.first(nodes).parentNode); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6478 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6479 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6480 |
var nodes = [el], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6481 |
makeAndPut = function(val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6482 |
var isString = !isNode(val), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6483 |
frag = can.frag(val), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6484 |
oldNodes = can.makeArray(nodes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6485 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6486 |
// Add a placeholder textNode if necessary. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6487 |
addTextNodeIfNoChildren(frag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6488 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6489 |
if (isString) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6490 |
frag = can.view.hookup(frag, parentNode); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6491 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6492 |
// We need to mark each node as belonging to the node list. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6493 |
oldNodes = nodeLists.update(nodes, frag.childNodes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6494 |
elements.replace(oldNodes, frag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6495 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6496 |
data.nodeList = nodes; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6497 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6498 |
// register the span so nodeLists knows the parentNodeList |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6499 |
nodeLists.register(nodes, data.teardownCheck); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6500 |
makeAndPut(compute()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6501 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6502 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6503 |
replace: function(nodes, val, teardown) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6504 |
var oldNodes = nodes.slice(0), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6505 |
frag = can.frag(val); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6506 |
nodeLists.register(nodes, teardown); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6507 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6508 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6509 |
if (typeof val === 'string') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6510 |
// if it was a string, check for hookups |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6511 |
frag = can.view.hookup(frag, nodes[0].parentNode); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6512 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6513 |
// We need to mark each node as belonging to the node list. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6514 |
nodeLists.update(nodes, frag.childNodes); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6515 |
elements.replace(oldNodes, frag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6516 |
return nodes; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6517 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6518 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6519 |
text: function(el, compute, parentNode) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6520 |
var parent = elements.getParentNode(el, parentNode); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6521 |
// setup listening right away so we don't have to re-calculate value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6522 |
var data = listen(parent, compute, function(ev, newVal, oldVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6523 |
// Sometimes this is 'unknown' in IE and will throw an exception if it is |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6524 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6525 |
if (typeof node.nodeValue !== 'unknown') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6526 |
node.nodeValue = can.view.toStr(newVal); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6527 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6528 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6529 |
// TODO: remove in 2.1 |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6530 |
data.teardownCheck(node.parentNode); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6531 |
}), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6532 |
// The text node that will be updated |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6533 |
node = document.createTextNode(can.view.toStr(compute())); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6534 |
// Replace the placeholder with the live node and do the nodeLists thing. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6535 |
// Add that node to nodeList so we can remove it when the parent element is removed from the page |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6536 |
data.nodeList = live.replace([el], node, data.teardownCheck); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6537 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6538 |
setAttributes: function(el, newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6539 |
var attrs = getAttributeParts(newVal); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6540 |
for (var name in attrs) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6541 |
can.attr.set(el, name, attrs[name]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6542 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6543 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6544 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6545 |
attributes: function(el, compute, currentValue) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6546 |
var oldAttrs = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6547 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6548 |
var setAttrs = function(newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6549 |
var newAttrs = getAttributeParts(newVal), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6550 |
name; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6551 |
for (name in newAttrs) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6552 |
var newValue = newAttrs[name], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6553 |
oldValue = oldAttrs[name]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6554 |
if (newValue !== oldValue) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6555 |
can.attr.set(el, name, newValue); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6556 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6557 |
delete oldAttrs[name]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6558 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6559 |
for (name in oldAttrs) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6560 |
elements.removeAttr(el, name); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6561 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6562 |
oldAttrs = newAttrs; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6563 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6564 |
listen(el, compute, function(ev, newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6565 |
setAttrs(newVal); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6566 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6567 |
// current value has been set |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6568 |
if (arguments.length >= 3) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6569 |
oldAttrs = getAttributeParts(currentValue); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6570 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6571 |
setAttrs(compute()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6572 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6573 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6574 |
attributePlaceholder: '__!!__', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6575 |
attributeReplace: /__!!__/g, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6576 |
attribute: function(el, attributeName, compute) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6577 |
listen(el, compute, function(ev, newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6578 |
elements.setAttr(el, attributeName, hook.render()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6579 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6580 |
var wrapped = can.$(el), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6581 |
hooks; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6582 |
// Get the list of hookups or create one for this element. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6583 |
// Hooks is a map of attribute names to hookup `data`s. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6584 |
// Each hookup data has: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6585 |
// `render` - A `function` to render the value of the attribute. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6586 |
// `funcs` - A list of hookup `function`s on that attribute. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6587 |
// `batchNum` - The last event `batchNum`, used for performance. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6588 |
hooks = can.data(wrapped, 'hooks'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6589 |
if (!hooks) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6590 |
can.data(wrapped, 'hooks', hooks = {}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6591 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6592 |
// Get the attribute value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6593 |
var attr = elements.getAttr(el, attributeName), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6594 |
// Split the attribute value by the template. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6595 |
// Only split out the first __!!__ so if we have multiple hookups in the same attribute, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6596 |
// they will be put in the right spot on first render |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6597 |
parts = attr.split(live.attributePlaceholder), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6598 |
goodParts = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6599 |
hook; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6600 |
goodParts.push(parts.shift(), parts.join(live.attributePlaceholder)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6601 |
// If we already had a hookup for this attribute... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6602 |
if (hooks[attributeName]) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6603 |
// Just add to that attribute's list of `function`s. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6604 |
hooks[attributeName].computes.push(compute); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6605 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6606 |
// Create the hookup data. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6607 |
hooks[attributeName] = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6608 |
render: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6609 |
var i = 0, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6610 |
// attr doesn't have a value in IE |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6611 |
newAttr = attr ? attr.replace(live.attributeReplace, function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6612 |
return elements.contentText(hook.computes[i++]()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6613 |
}) : elements.contentText(hook.computes[i++]()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6614 |
return newAttr; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6615 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6616 |
computes: [compute], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6617 |
batchNum: undefined |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6618 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6619 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6620 |
// Save the hook for slightly faster performance. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6621 |
hook = hooks[attributeName]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6622 |
// Insert the value in parts. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6623 |
goodParts.splice(1, 0, compute()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6624 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6625 |
// Set the attribute. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6626 |
elements.setAttr(el, attributeName, goodParts.join('')); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6627 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6628 |
specialAttribute: function(el, attributeName, compute) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6629 |
listen(el, compute, function(ev, newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6630 |
elements.setAttr(el, attributeName, getValue(newVal)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6631 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6632 |
elements.setAttr(el, attributeName, getValue(compute())); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6633 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6634 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6635 |
simpleAttribute: function(el, attributeName, compute) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6636 |
listen(el, compute, function(ev, newVal) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6637 |
elements.setAttr(el, attributeName, newVal); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6638 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6639 |
elements.setAttr(el, attributeName, compute()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6640 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6641 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6642 |
live.attr = live.simpleAttribute; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6643 |
live.attrs = live.attributes; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6644 |
var newLine = /(\r|\n)+/g; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6645 |
var getValue = function(val) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6646 |
var regexp = /^["'].*["']$/; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6647 |
val = val.replace(elements.attrReg, '') |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6648 |
.replace(newLine, ''); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6649 |
// check if starts and ends with " or ' |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6650 |
return regexp.test(val) ? val.substr(1, val.length - 2) : val; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6651 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6652 |
can.view.live = live; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6653 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6654 |
return live; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6655 |
})(__m3, __m24, __m17, __m28, __m29); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6656 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6657 |
// ## can/view/render.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6658 |
var __m26 = (function(can, elements, live) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6659 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6660 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6661 |
var pendingHookups = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6662 |
tagChildren = function(tagName) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6663 |
var newTag = elements.tagMap[tagName] || "span"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6664 |
if (newTag === "span") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6665 |
//innerHTML in IE doesn't honor leading whitespace after empty elements |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6666 |
return "@@!!@@"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6667 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6668 |
return "<" + newTag + ">" + tagChildren(newTag) + "</" + newTag + ">"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6669 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6670 |
contentText = function(input, tag) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6671 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6672 |
// If it's a string, return. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6673 |
if (typeof input === 'string') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6674 |
return input; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6675 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6676 |
// If has no value, return an empty string. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6677 |
if (!input && input !== 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6678 |
return ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6679 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6680 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6681 |
// If it's an object, and it has a hookup method. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6682 |
var hook = (input.hookup && |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6683 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6684 |
// Make a function call the hookup method. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6685 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6686 |
function(el, id) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6687 |
input.hookup.call(input, el, id); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6688 |
}) || |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6689 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6690 |
// Or if it's a `function`, just use the input. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6691 |
(typeof input === 'function' && input); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6692 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6693 |
// Finally, if there is a `function` to hookup on some dom, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6694 |
// add it to pending hookups. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6695 |
if (hook) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6696 |
if (tag) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6697 |
return "<" + tag + " " + can.view.hook(hook) + "></" + tag + ">"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6698 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6699 |
pendingHookups.push(hook); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6700 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6701 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6702 |
return ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6703 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6704 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6705 |
// Finally, if all else is `false`, `toString()` it. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6706 |
return "" + input; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6707 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6708 |
// Returns escaped/sanatized content for anything other than a live-binding |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6709 |
contentEscape = function(txt, tag) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6710 |
return (typeof txt === 'string' || typeof txt === 'number') ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6711 |
can.esc(txt) : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6712 |
contentText(txt, tag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6713 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6714 |
// A flag to indicate if .txt was called within a live section within an element like the {{name}} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6715 |
// within `<div {{#person}}{{name}}{{/person}}/>`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6716 |
withinTemplatedSectionWithinAnElement = false, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6717 |
emptyHandler = function() {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6718 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6719 |
var lastHookups; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6720 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6721 |
can.extend(can.view, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6722 |
live: live, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6723 |
// called in text to make a temporary |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6724 |
// can.view.lists function that can be called with |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6725 |
// the list to iterate over and the template |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6726 |
// used to produce the content within the list |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6727 |
setupLists: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6728 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6729 |
var old = can.view.lists, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6730 |
data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6731 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6732 |
can.view.lists = function(list, renderer) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6733 |
data = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6734 |
list: list, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6735 |
renderer: renderer |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6736 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6737 |
return Math.random(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6738 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6739 |
// sets back to the old data |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6740 |
return function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6741 |
can.view.lists = old; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6742 |
return data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6743 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6744 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6745 |
getHooks: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6746 |
var hooks = pendingHookups.slice(0); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6747 |
lastHookups = hooks; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6748 |
pendingHookups = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6749 |
return hooks; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6750 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6751 |
onlytxt: function(self, func) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6752 |
return contentEscape(func.call(self)); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6753 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6754 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6755 |
txt: function(escape, tagName, status, self, func) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6756 |
// the temporary tag needed for any live setup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6757 |
var tag = (elements.tagMap[tagName] || "span"), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6758 |
// should live-binding be setup |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6759 |
setupLiveBinding = false, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6760 |
// the compute's value |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6761 |
value, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6762 |
listData, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6763 |
compute, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6764 |
unbind = emptyHandler, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6765 |
attributeName; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6766 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6767 |
// Are we currently within a live section within an element like the {{name}} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6768 |
// within `<div {{#person}}{{name}}{{/person}}/>`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6769 |
if (withinTemplatedSectionWithinAnElement) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6770 |
value = func.call(self); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6771 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6772 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6773 |
// If this magic tag is within an attribute or an html element, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6774 |
// set the flag to true so we avoid trying to live bind |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6775 |
// anything that func might be setup. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6776 |
// TODO: the scanner should be able to set this up. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6777 |
if (typeof status === "string" || status === 1) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6778 |
withinTemplatedSectionWithinAnElement = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6779 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6780 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6781 |
// Sets up a listener so we know any can.view.lists called |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6782 |
// when func is called |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6783 |
var listTeardown = can.view.setupLists(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6784 |
unbind = function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6785 |
compute.unbind("change", emptyHandler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6786 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6787 |
// Create a compute that calls func and looks for dependencies. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6788 |
// By passing `false`, this compute can not be a dependency of other |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6789 |
// computes. This is because live-bits are nested, but |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6790 |
// handle their own updating. For example: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6791 |
// {{#if items.length}}{{#items}}{{.}}{{/items}}{{/if}} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6792 |
// We do not want `{{#if items.length}}` changing the DOM if |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6793 |
// `{{#items}}` text changes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6794 |
compute = can.compute(func, self, false); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6795 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6796 |
// Bind to get and temporarily cache the value of the compute. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6797 |
compute.bind("change", emptyHandler); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6798 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6799 |
// Call the "wrapping" function and get the binding information |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6800 |
listData = listTeardown(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6801 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6802 |
// Get the value of the compute |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6803 |
value = compute(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6804 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6805 |
// Let people know we are no longer within an element. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6806 |
withinTemplatedSectionWithinAnElement = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6807 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6808 |
// If we should setup live-binding. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6809 |
setupLiveBinding = compute.hasDependencies; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6810 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6811 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6812 |
if (listData) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6813 |
unbind(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6814 |
return "<" + tag + can.view.hook(function(el, parentNode) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6815 |
live.list(el, listData.list, listData.renderer, self, parentNode); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6816 |
}) + "></" + tag + ">"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6817 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6818 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6819 |
// If we had no observes just return the value returned by func. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6820 |
if (!setupLiveBinding || typeof value === "function") { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6821 |
unbind(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6822 |
return ((withinTemplatedSectionWithinAnElement || escape === 2 || !escape) ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6823 |
contentText : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6824 |
contentEscape)(value, status === 0 && tag); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6825 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6826 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6827 |
// the property (instead of innerHTML elements) to adjust. For |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6828 |
// example options should use textContent |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6829 |
var contentProp = elements.tagToContentPropMap[tagName]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6830 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6831 |
// The magic tag is outside or between tags. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6832 |
if (status === 0 && !contentProp) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6833 |
// Return an element tag with a hookup in place of the content |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6834 |
return "<" + tag + can.view.hook( |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6835 |
// if value is an object, it's likely something returned by .safeString |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6836 |
escape && typeof value !== "object" ? |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6837 |
// If we are escaping, replace the parentNode with |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6838 |
// a text node who's value is `func`'s return value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6839 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6840 |
function(el, parentNode) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6841 |
live.text(el, compute, parentNode); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6842 |
unbind(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6843 |
} : |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6844 |
// If we are not escaping, replace the parentNode with a |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6845 |
// documentFragment created as with `func`'s return value. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6846 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6847 |
function(el, parentNode) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6848 |
live.html(el, compute, parentNode); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6849 |
unbind(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6850 |
//children have to be properly nested HTML for buildFragment to work properly |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6851 |
}) + ">" + tagChildren(tag) + "</" + tag + ">"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6852 |
// In a tag, but not in an attribute |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6853 |
} else if (status === 1) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6854 |
// remember the old attr name |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6855 |
pendingHookups.push(function(el) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6856 |
live.attributes(el, compute, compute()); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6857 |
unbind(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6858 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6859 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6860 |
return compute(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6861 |
} else if (escape === 2) { // In a special attribute like src or style |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6862 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6863 |
attributeName = status; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6864 |
pendingHookups.push(function(el) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6865 |
live.specialAttribute(el, attributeName, compute); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6866 |
unbind(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6867 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6868 |
return compute(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6869 |
} else { // In an attribute... |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6870 |
attributeName = status === 0 ? contentProp : status; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6871 |
// if the magic tag is inside the element, like `<option><% TAG %></option>`, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6872 |
// we add this hookup to the last element (ex: `option`'s) hookups. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6873 |
// Otherwise, the magic tag is in an attribute, just add to the current element's |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6874 |
// hookups. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6875 |
(status === 0 ? lastHookups : pendingHookups) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6876 |
.push(function(el) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6877 |
live.attribute(el, attributeName, compute); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6878 |
unbind(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6879 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6880 |
return live.attributePlaceholder; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6881 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6882 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6883 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6884 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6885 |
return can; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6886 |
})(__m17, __m24, __m27, __m2); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6887 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6888 |
// ## can/view/ejs/ejs.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6889 |
var __m22 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6890 |
// ## Helper methods |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6891 |
var extend = can.extend, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6892 |
EJS = function(options) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6893 |
// Supports calling EJS without the constructor. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6894 |
// This returns a function that renders the template. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6895 |
if (this.constructor !== EJS) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6896 |
var ejs = new EJS(options); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6897 |
return function(data, helpers) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6898 |
return ejs.render(data, helpers); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6899 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6900 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6901 |
// If we get a `function` directly, it probably is coming from |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6902 |
// a `steal`-packaged view. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6903 |
if (typeof options === 'function') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6904 |
this.template = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6905 |
fn: options |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6906 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6907 |
return; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6908 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6909 |
// Set options on self. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6910 |
extend(this, options); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6911 |
this.template = this.scanner.scan(this.text, this.name); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6912 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6913 |
// Expose EJS via the `can` object. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6914 |
can.EJS = EJS; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6915 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6916 |
EJS.prototype. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6917 |
// ## Render |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6918 |
// Render a view object with data and helpers. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6919 |
render = function(object, extraHelpers) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6920 |
object = object || {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6921 |
return this.template.fn.call(object, object, new EJS.Helpers(object, extraHelpers || {})); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6922 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6923 |
extend(EJS.prototype, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6924 |
// ## Scanner |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6925 |
// Singleton scanner instance for parsing templates. See [scanner.js](scanner.html) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6926 |
// for more information. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6927 |
// ### Text |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6928 |
// #### Definitions |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6929 |
// * `outStart` - Wrapper start text for view function. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6930 |
// * `outEnd` - Wrapper end text for view function. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6931 |
// * `argNames` - Arguments passed into view function. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6932 |
scanner: new can.view.Scanner({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6933 |
text: { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6934 |
outStart: 'with(_VIEW) { with (_CONTEXT) {', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6935 |
outEnd: "}}", |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6936 |
argNames: '_CONTEXT,_VIEW', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6937 |
context: "this" |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6938 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6939 |
// ### Tokens |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6940 |
// An ordered token registry for the scanner. Scanner makes evaluations |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6941 |
// based on which tags are considered opening/closing as well as escaped, etc. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6942 |
tokens: [ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6943 |
["templateLeft", "<%%"], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6944 |
["templateRight", "%>"], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6945 |
["returnLeft", "<%=="], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6946 |
["escapeLeft", "<%="], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6947 |
["commentLeft", "<%#"], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6948 |
["left", "<%"], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6949 |
["right", "%>"], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6950 |
["returnRight", "%>"] |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6951 |
], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6952 |
// ### Helpers |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6953 |
helpers: [{ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6954 |
// Regex to see if its a func like `()->`. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6955 |
name: /\s*\(([\$\w]+)\)\s*->([^\n]*)/, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6956 |
// Evaluate rocket syntax function with correct context. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6957 |
fn: function(content) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6958 |
var quickFunc = /\s*\(([\$\w]+)\)\s*->([^\n]*)/, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6959 |
parts = content.match(quickFunc); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6960 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6961 |
return "can.proxy(function(__){var " + parts[1] + "=can.$(__);" + parts[2] + "}, this);"; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6962 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6963 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6964 |
], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6965 |
// ### transform |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6966 |
// Transforms the EJS template to add support for shared blocks. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6967 |
// Essentially, this breaks up EJS tags into multiple EJS tags |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6968 |
// if they contained unmatched brackets. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6969 |
// For example, this doesn't work: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6970 |
// `<% if (1) { %><% if (1) { %> hi <% } } %>` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6971 |
// ...without isolated EJS blocks: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6972 |
// `<% if (1) { %><% if (1) { %> hi <% } %><% } %>` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6973 |
// The result of transforming: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6974 |
// `<% if (1) { %><% %><% if (1) { %><% %> hi <% } %><% } %>` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6975 |
transform: function(source) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6976 |
return source.replace(/<%([\s\S]+?)%>/gm, function(whole, part) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6977 |
var brackets = [], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6978 |
foundBracketPair, i; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6979 |
// Look for brackets (for removing self-contained blocks) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6980 |
part.replace(/[{}]/gm, function(bracket, offset) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6981 |
brackets.push([ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6982 |
bracket, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6983 |
offset |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6984 |
]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6985 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6986 |
// Remove bracket pairs from the list of replacements |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6987 |
do { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6988 |
foundBracketPair = false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6989 |
for (i = brackets.length - 2; i >= 0; i--) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6990 |
if (brackets[i][0] === '{' && brackets[i + 1][0] === '}') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6991 |
brackets.splice(i, 2); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6992 |
foundBracketPair = true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6993 |
break; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6994 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6995 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6996 |
} while (foundBracketPair); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6997 |
// Unmatched brackets found, inject EJS tags |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6998 |
if (brackets.length >= 2) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6999 |
var result = ['<%'], |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7000 |
bracket, last = 0; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7001 |
for (i = 0; bracket = brackets[i]; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7002 |
result.push(part.substring(last, last = bracket[1])); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7003 |
if (bracket[0] === '{' && i < brackets.length - 1 || bracket[0] === '}' && i > 0) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7004 |
result.push(bracket[0] === '{' ? '{ %><% ' : ' %><% }'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7005 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7006 |
result.push(bracket[0]); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7007 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7008 |
++last; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7009 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7010 |
result.push(part.substring(last), '%>'); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7011 |
return result.join(''); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7012 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7013 |
// Otherwise return the original |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7014 |
else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7015 |
return '<%' + part + '%>'; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7016 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7017 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7018 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7019 |
}) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7020 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7021 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7022 |
// ## Helpers |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7023 |
// In your EJS view you can then call the helper on an element tag: |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7024 |
// `<div <%= upperHtml('javascriptmvc') %>></div>` |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7025 |
EJS.Helpers = function(data, extras) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7026 |
this._data = data; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7027 |
this._extras = extras; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7028 |
extend(this, extras); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7029 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7030 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7031 |
EJS.Helpers.prototype = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7032 |
// List allows for live binding a can.List easily within a template. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7033 |
list: function(list, cb) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7034 |
can.each(list, function(item, i) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7035 |
cb(item, i, list); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7036 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7037 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7038 |
// `each` iterates through a enumerated source(such as can.List or array) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7039 |
// and sets up live binding when possible. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7040 |
each: function(list, cb) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7041 |
// Normal arrays don't get live updated |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7042 |
if (can.isArray(list)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7043 |
this.list(list, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7044 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7045 |
can.view.lists(list, cb); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7046 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7047 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7048 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7049 |
// Registers options for a `steal` build. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7050 |
can.view.register({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7051 |
suffix: 'ejs', |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7052 |
script: function(id, src) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7053 |
return 'can.EJS(function(_CONTEXT,_VIEW) { ' + new EJS({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7054 |
text: src, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7055 |
name: id |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7056 |
}) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7057 |
.template.out + ' })'; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7058 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7059 |
renderer: function(id, text) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7060 |
return EJS({ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7061 |
text: text, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7062 |
name: id |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7063 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7064 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7065 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7066 |
can.ejs.Helpers = EJS.Helpers; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7067 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7068 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7069 |
return can; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7070 |
})(__m3, __m17, __m2, __m15, __m23, __m26); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7071 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7072 |
// ## can/util/object/object.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7073 |
var __m31 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7074 |
var isArray = can.isArray; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7075 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7076 |
can.Object = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7077 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7078 |
var same = can.Object.same = function(a, b, compares, aParent, bParent, deep) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7079 |
var aType = typeof a, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7080 |
aArray = isArray(a), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7081 |
comparesType = typeof compares, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7082 |
compare; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7083 |
if (comparesType === 'string' || compares === null) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7084 |
compares = compareMethods[compares]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7085 |
comparesType = 'function'; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7086 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7087 |
if (comparesType === 'function') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7088 |
return compares(a, b, aParent, bParent); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7089 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7090 |
compares = compares || {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7091 |
if (a === null || b === null) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7092 |
return a === b; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7093 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7094 |
if (a instanceof Date || b instanceof Date) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7095 |
return a === b; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7096 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7097 |
if (deep === -1) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7098 |
return aType === 'object' || a === b; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7099 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7100 |
if (aType !== typeof b || aArray !== isArray(b)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7101 |
return false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7102 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7103 |
if (a === b) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7104 |
return true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7105 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7106 |
if (aArray) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7107 |
if (a.length !== b.length) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7108 |
return false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7109 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7110 |
for (var i = 0; i < a.length; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7111 |
compare = compares[i] === undefined ? compares['*'] : compares[i]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7112 |
if (!same(a[i], b[i], a, b, compare)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7113 |
return false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7114 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7115 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7116 |
return true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7117 |
} else if (aType === 'object' || aType === 'function') { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7118 |
var bCopy = can.extend({}, b); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7119 |
for (var prop in a) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7120 |
compare = compares[prop] === undefined ? compares['*'] : compares[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7121 |
if (!same(a[prop], b[prop], compare, a, b, deep === false ? -1 : undefined)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7122 |
return false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7123 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7124 |
delete bCopy[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7125 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7126 |
// go through bCopy props ... if there is no compare .. return false |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7127 |
for (prop in bCopy) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7128 |
if (compares[prop] === undefined || !same(undefined, b[prop], compares[prop], a, b, deep === false ? -1 : undefined)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7129 |
return false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7130 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7131 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7132 |
return true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7133 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7134 |
return false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7135 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7136 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7137 |
can.Object.subsets = function(checkSet, sets, compares) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7138 |
var len = sets.length, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7139 |
subsets = []; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7140 |
for (var i = 0; i < len; i++) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7141 |
//check this subset |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7142 |
var set = sets[i]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7143 |
if (can.Object.subset(checkSet, set, compares)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7144 |
subsets.push(set); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7145 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7146 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7147 |
return subsets; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7148 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7149 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7150 |
can.Object.subset = function(subset, set, compares) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7151 |
// go through set {type: 'folder'} and make sure every property |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7152 |
// is in subset {type: 'folder', parentId :5} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7153 |
// then make sure that set has fewer properties |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7154 |
// make sure we are only checking 'important' properties |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7155 |
// in subset (ones that have to have a value) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7156 |
compares = compares || {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7157 |
for (var prop in set) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7158 |
if (!same(subset[prop], set[prop], compares[prop], subset, set)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7159 |
return false; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7160 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7161 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7162 |
return true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7163 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7164 |
var compareMethods = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7165 |
'null': function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7166 |
return true; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7167 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7168 |
i: function(a, b) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7169 |
return ('' + a) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7170 |
.toLowerCase() === ('' + b) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7171 |
.toLowerCase(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7172 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7173 |
eq: function(a, b) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7174 |
return a === b; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7175 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7176 |
similar: function(a, b) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7177 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7178 |
return a == b; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7179 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7180 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7181 |
compareMethods.eqeq = compareMethods.similar; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7182 |
return can.Object; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7183 |
})(__m3); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7184 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7185 |
// ## can/map/backup/backup.js |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7186 |
var __m30 = (function(can) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7187 |
var flatProps = function(a, cur) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7188 |
var obj = {}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7189 |
for (var prop in a) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7190 |
if (typeof a[prop] !== 'object' || a[prop] === null || a[prop] instanceof Date) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7191 |
obj[prop] = a[prop]; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7192 |
} else { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7193 |
obj[prop] = cur.attr(prop); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7194 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7195 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7196 |
return obj; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7197 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7198 |
can.extend(can.Map.prototype, { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7199 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7200 |
backup: function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7201 |
this._backupStore = this._attrs(); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7202 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7203 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7204 |
isDirty: function(checkAssociations) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7205 |
return this._backupStore && !can.Object.same(this._attrs(), this._backupStore, undefined, undefined, undefined, !! checkAssociations); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7206 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7207 |
restore: function(restoreAssociations) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7208 |
var props = restoreAssociations ? this._backupStore : flatProps(this._backupStore, this); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7209 |
if (this.isDirty(restoreAssociations)) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7210 |
this._attrs(props, true); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7211 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7212 |
return this; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7213 |
} |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7214 |
}); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7215 |
return can.Map; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7216 |
})(__m3, __m10, __m31); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7217 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7218 |
window['can'] = __m5; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7219 |
})(); |