Skip to content

Commit 34a86c5

Browse files
committed
Add compatibility with Zepto
1 parent c39e82d commit 34a86c5

File tree

6 files changed

+113
-30
lines changed

6 files changed

+113
-30
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ The basic structure of the project is given in the following way:
7272
|-- assets/
7373
|-- demo/
7474
| |-- index.html
75+
| |-- index-zepto.html
7576
|-- dist/
7677
| |-- jquery.boilerplate.js
7778
| |-- jquery.boilerplate.min.js
79+
|-- lib/
7880
|-- src/
7981
| |-- jquery.boilerplate.coffee
8082
| |-- jquery.boilerplate.js
@@ -99,6 +101,10 @@ Contains a simple HTML file to demonstrate the plugin.
99101

100102
This is where the generated files are stored once Grunt runs JSHint and other stuff.
101103

104+
#### [lib/](https://github.com/zenorocha/jquery-github/tree/master/lib)
105+
106+
Contains libraries like jQuery and Zepto.
107+
102108
#### [src/](https://github.com/zenorocha/jquery-github/tree/master/src)
103109

104110
Contains the files responsible for the plugin.
@@ -154,12 +160,16 @@ Specify all dependencies loaded via Node.JS.
154160

155161
Let me know! Send a [tweet](http://twitter.com/zenorocha) or [pull request](https://github.com/zenorocha/jquery-github/pull/new/master) and I'll add it here :)
156162

157-
## Forks
163+
## Alternatives
158164

159165
**Prefer a non-jquery version with pure JavaScript?**
160166

161167
No problem, [@ricardobeat](https://github.com/ricardobeat) already did one. Check [his fork!](https://github.com/ricardobeat/github-repos)
162168

169+
**Prefer Zepto instead of jQuery?**
170+
171+
No problem, [@igorlima](https://github.com/igorlima) already did that. Check [demo/index-zepto.html](https://github.com/zenorocha/jquery-github/tree/master/demo/index-zepto.html)
172+
163173
## Contributing
164174

165175
Check [CONTRIBUTING.md](https://github.com/zenorocha/jquery-github/blob/master/CONTRIBUTING.md)

demo/index-zepto.html

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,45 @@
22
<html lang="en-US">
33
<head>
44

5-
<meta charset="UTF-8">
6-
<title>jQuery Github with Zepto</title>
5+
<meta charset="UTF-8">
6+
<title>jQuery Github with Zepto</title>
77

8-
<!-- Plugin CSS -->
9-
<link rel="stylesheet" href="../assets/base.css">
8+
<!-- Plugin CSS -->
9+
<link rel="stylesheet" href="../assets/base.css">
1010

11-
<!-- Demo CSS -->
12-
<link rel="stylesheet" href="css/style.css">
11+
<!-- Demo CSS -->
12+
<link rel="stylesheet" href="css/style.css">
1313

1414
</head>
1515
<body>
1616

17-
<a href="https://github.com/zenorocha/jquery-github">
18-
<img class="github-ribbon" src="img/github-ribbon.png" alt="Fork me on GitHub">
19-
</a>
17+
<a href="https://github.com/zenorocha/jquery-github">
18+
<img class="github-ribbon" src="img/github-ribbon.png" alt="Fork me on GitHub">
19+
</a>
2020

21-
<div class="title">
22-
<h1>jQuery Github</h1>
23-
<p>A jQuery plugin to display your favorite Github Repositories.<br>For more informations, visit our <a href="https://github.com/zenorocha/jquery-github">repository</a>.</p>
24-
</div>
21+
<div class="title">
22+
<h1>jQuery Github</h1>
23+
<p>A jQuery plugin to display your favorite Github Repositories.<br>For more informations, visit our <a href="https://github.com/zenorocha/jquery-github">repository</a>.</p>
24+
</div>
2525

26-
<div class="projects">
27-
<div data-repo="jquery-boilerplate/boilerplate"></div>
28-
<div data-repo="zenorocha/diveintohtml5"></div>
29-
<div data-repo="zenorocha/jquery-github"></div>
30-
<div data-repo="zenorocha/hub.me"></div>
31-
</div>
26+
<div class="projects">
27+
<div data-repo="jquery-boilerplate/boilerplate" class="github-box-wrap"></div>
28+
<div data-repo="zenorocha/diveintohtml5" class="github-box-wrap"></div>
29+
<div data-repo="zenorocha/jquery-github" class="github-box-wrap"></div>
30+
<div data-repo="zenorocha/hub.me" class="github-box-wrap"></div>
31+
</div>
3232

33-
<p class="credits">Made with love by <a href="http://zenorocha.com">Zeno Rocha</a>.</p>
33+
<p class="credits">Made with love by <a href="http://zenorocha.com">Zeno Rocha</a>.</p>
3434

35-
<img id="github-logo" src="img/github-cat.png" alt="Github Cat" />
35+
<img id="github-logo" src="img/github-cat.png" alt="Github Cat" />
3636

37-
<script src="http://zeptojs.com/zepto.min.js"></script>
38-
<script type="text/javascript" src="https://raw.github.com/madrobby/zepto/master/src/data.js"></script>
39-
<script src="../jquery.github.js"></script>
37+
<script src="../lib/zepto.min.js"></script>
38+
<script src="../lib/zepto.data.js"></script>
39+
<script src="../src/jquery.github.js"></script>
4040

41-
<script>
42-
$('[data-repo]').github();
43-
</script>
41+
<script>
42+
$('[data-repo]').github();
43+
</script>
4444

4545
</body>
46-
</html>
46+
</html>

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h1>jQuery Github</h1>
3434

3535
<img id="github-logo" src="img/github-cat.png" alt="Github Cat" />
3636

37-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
37+
<script src="../lib/jquery.min.js"></script>
3838
<script src="../src/jquery.github.js"></script>
3939

4040
<script>

lib/jquery.min.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/zepto.data.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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)

lib/zepto.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)