summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Zepto/data.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Zepto/data.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Zepto/data.js67
1 files changed, 0 insertions, 67 deletions
diff --git a/frontend/gamma/js/Zepto/data.js b/frontend/gamma/js/Zepto/data.js
deleted file mode 100644
index b4c289f..0000000
--- a/frontend/gamma/js/Zepto/data.js
+++ b/dev/null
@@ -1,67 +0,0 @@
1// Zepto.js
2// (c) 2010-2012 Thomas Fuchs
3// Zepto.js may be freely distributed under the MIT license.
4
5// The following code is heavily inspired by jQuery's $.fn.data()
6
7;(function($) {
8 var data = {}, dataAttr = $.fn.data, camelize = $.camelCase,
9 exp = $.expando = 'Zepto' + (+new Date())
10
11 // Get value from node:
12 // 1. first try key as given,
13 // 2. then try camelized key,
14 // 3. fall back to reading "data-*" attribute.
15 function getData(node, name) {
16 var id = node[exp], store = id && data[id]
17 if (name === undefined) return store || setData(node)
18 else {
19 if (store) {
20 if (name in store) return store[name]
21 var camelName = camelize(name)
22 if (camelName in store) return store[camelName]
23 }
24 return dataAttr.call($(node), name)
25 }
26 }
27
28 // Store value under camelized key on node
29 function setData(node, name, value) {
30 var id = node[exp] || (node[exp] = ++$.uuid),
31 store = data[id] || (data[id] = attributeData(node))
32 if (name !== undefined) store[camelize(name)] = value
33 return store
34 }
35
36 // Read all "data-*" attributes from a node
37 function attributeData(node) {
38 var store = {}
39 $.each(node.attributes, function(i, attr){
40 if (attr.name.indexOf('data-') == 0)
41 store[camelize(attr.name.replace('data-', ''))] =
42 $.zepto.deserializeValue(attr.value)
43 })
44 return store
45 }
46
47 $.fn.data = function(name, value) {
48 return value === undefined ?
49 // set multiple values via object
50 $.isPlainObject(name) ?
51 this.each(function(i, node){
52 $.each(name, function(key, value){ setData(node, key, value) })
53 }) :
54 // get value from first element
55 this.length == 0 ? undefined : getData(this[0], name) :
56 // set value on all elements
57 this.each(function(){ setData(this, name, value) })
58 }
59
60 $.fn.removeData = function(names) {
61 if (typeof names == 'string') names = names.split(/\s+/)
62 return this.each(function(){
63 var id = this[exp], store = id && data[id]
64 if (store) $.each(names, function(){ delete store[camelize(this)] })
65 })
66 }
67})(Zepto)