Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add minify

  • Loading branch information...
commit a911610e9dd7e2aeb192cdd3cf95efc747105eee 1 parent 157db33
Kevin Peterson authored
Showing with 36 additions and 48 deletions.
  1. +2 −0  .gitignore
  2. +10 −26 bender.js
  3. +2 −0  build.sh
  4. +22 −22 jquery.cookie.js
View
2  .gitignore
@@ -1 +1,3 @@
*~
+bender-min-dev.js
+_site
View
36 bender.js
@@ -1,55 +1,39 @@
function Bender(id) {
- var self = this;
- var styles = {};
- var keys = [];
- var mobile;
- this.set_style = function(style) {
- console.log("Setting " + self.name() + "(" + id + ") to " + style);
+ var self = this, styles = {}, keys = [], mobile;
+ this.set = function(style) {
document.getElementById(id).href = styles[style];
}
- this.name = function() {
- return id;
- }
this.choose = function(style) {
- self.set_style(style);
+ $.cookie("bender-" + id, style, { path: '/', expires: 30});
+ self.set(style);
}
- this.add = function(style, href, auto_mobile) {
- console.log("adding " + style + " to " + this.name());
+ this.add = function(style, href, auto) {
keys = keys.concat(style);
styles[style] = href;
- if (auto_mobile == "auto-mobile") {
+ if (auto == "auto-mobile") {
mobile = style;
}
return self;
}
- this.install_handlers = function() {
+ this.clicks = function() {
keys.forEach(
function(key) {
- console.log("hooking up " + self.name() + " to " + key);
$("#" + key).click(function(e) {
- console.log(self.name());
e.preventDefault();
self.choose(key);
});
- $("#" + key).data("bender", self.name());
});
}
- this.get_cookie = function() {
- return $.cookie("bender-" + id);
- }
- this.set_cookie = function(style) {
- $.cookie("bender-" + id, style, { path: '/', expires: 30 });
- }
this.install = function() {
var selected = $.cookie("bender-" + id);
if (selected) {
- self.set_style(selected);
+ self.set(selected);
} else if (mobile) {
if (navigator.userAgent.toLowerCase().match(/mobile|android/)) {
- self.set_style(mobile);
+ self.set(mobile);
}
}
- return self.install_handlers;
+ return self.clicks;
}
};
function bender(id) {
View
2  build.sh
@@ -0,0 +1,2 @@
+version=${BENDER_VERSION:-"dev"}
+cat jquery.cookie.js bender.js | jsmin "Minified bender.js https://github.com/kevinpet/bender Copyright 2011 Kevin Peterson" "includes jquery.cookie.js Copyright 2006 Klaus Hartl (silbeuro.de)"> bender-min-$version.js
View
44 jquery.cookie.js
@@ -3,40 +3,40 @@ Copyright (c) 2006 Klaus Hartl (stilbuero.de)
Dual licensed under the MIT and GPL licenses:
http://www.opensource.org/licenses/mit-license.php
http://www.gnu.org/licenses/gpl.html */
-jQuery.cookie = function(name, value, options) {
- if (typeof value != 'undefined') {
- options = options || {};
- if (value === null) {
- value = '';
- options.expires = -1;
+$.cookie = function(n, v, opt) {
+ if (typeof v != 'undefined') {
+ opt = opt || {};
+ if (v === null) {
+ v = '';
+ opt.expires = -1;
}
- var expires = '';
- if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
+ var exp = '';
+ if (opt.expires && (typeof opt.expires == 'number' || opt.expires.toUTCString)) {
var date;
- if (typeof options.expires == 'number') {
+ if (typeof opt.expires == 'number') {
date = new Date();
- date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
+ date.setTime(date.getTime() + (opt.expires * 24 * 60 * 60 * 1000));
} else {
- date = options.expires;
+ date = opt.expires;
}
- expires = '; expires=' + date.toUTCString();
+ exp = '; expires=' + date.toUTCString();
}
- var path = options.path ? '; path=' + (options.path) : '';
- var domain = options.domain ? '; domain=' + (options.domain) : '';
- var secure = options.secure ? '; secure' : '';
- document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
+ var path = opt.path ? '; path=' + (opt.path) : '';
+ var domain = opt.domain ? '; domain=' + (opt.domain) : '';
+ var secure = opt.secure ? '; secure' : '';
+ document.cookie = [n, '=', encodeURIComponent(v), exp, path, domain, secure].join('');
} else {
- var cookieValue = null;
+ var content = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
- var cookie = jQuery.trim(cookies[i]);
- if (cookie.substring(0, name.length + 1) == (name + '=')) {
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+ var cookie = $.trim(cookies[i]);
+ if (cookie.substring(0, n.length + 1) == (n + '=')) {
+ content = decodeURIComponent(cookie.substring(n.length + 1));
break;
}
}
}
- return cookieValue;
+ return content;
}
-};
+};
Please sign in to comment.
Something went wrong with that request. Please try again.