-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2008 Jim Benton | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Gismos | ||
|
||
A collection of JavaScript utilities and sub-libraries I've built over the course of many projects. | ||
|
||
README should be included in each folder describing usage and any dependencies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## Cycle - a Javascript implementation of Rails' Text Helper | ||
|
||
Built to ease zebra-striping a table. I've avoided any JS library-provided niceties to maximize portability. No support for naming. | ||
|
||
Basic usage: | ||
|
||
>>> Cycle.thru('one', 'two', 'three'); | ||
"one" | ||
>>> Cycle.thru('one', 'two', 'three'); | ||
"two" | ||
>>> Cycle.thru('one', 'two', 'three'); | ||
"three" | ||
>>> Cycle.thru('one', 'two', 'three'); | ||
"one" | ||
>>> Cycle.thru('one', 'two', 'three'); | ||
"two" | ||
>>> Cycle.reset('one', 'two', 'three'); | ||
>>> Cycle.thru('one', 'two', 'three'); | ||
"one" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var Cycle = { | ||
cycles: [], | ||
thru: function() { | ||
var values = Array.prototype.slice.call(arguments); | ||
for(var i=0,len=this.cycles.length;i<len;i++) { | ||
var cycle = this.cycles[i]; | ||
if(cycle.ref == this.toRef(values)) { | ||
var next_value = cycle.values[cycle.index]; | ||
cycle.index = (cycle.index == cycle.values.length -1) ? 0 : (cycle.index +1) | ||
return next_value; | ||
} | ||
} | ||
this.add(values); | ||
return this.thru.apply(this, values); | ||
}, | ||
add: function(values) { | ||
this.cycles.push({ | ||
ref: this.toRef(values), | ||
values: values, | ||
index: 0 | ||
}); | ||
}, | ||
reset: function() { | ||
var values = Array.prototype.slice.call(arguments); | ||
for(var i=0,len=this.cycles.length;i<len;i++) { | ||
if(this.cycles[i].ref == this.toRef(values)) this.cycles[i].index = 0; | ||
} | ||
}, | ||
toRef: function(array) { | ||
return array.join('-'); | ||
} | ||
}; |