Created
February 18, 2012 00:21
-
-
Save sgammon/1856475 to your computer and use it in GitHub Desktop.
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
(function($) { | |
var config, cfg, | |
options, | |
methods = { | |
init : function(options) { | |
config = $.extend({ | |
// Default values | |
'height': 500, | |
'width': 75, | |
'fillHeight': 250, | |
'thumbHeight': 26, | |
'display': 'block' | |
}, options); | |
return this.each(function() { | |
if ( ! $(this).data("height") ) { | |
cfg = $.extend(config, {target: $(this)}); | |
for (var i in cfg) { | |
$(this).data(i, cfg[i]); | |
} | |
console.log($(this).data()) | |
} | |
$(this).bind({ | |
click : methods.update | |
}); | |
$(this).click() | |
}); | |
}, | |
close : function() { | |
return this.each(function() { | |
$(this).removeData(); | |
}); | |
}, | |
show : function() { | |
return this.show(); | |
}, | |
hide : function() { | |
return this.hide(); | |
}, | |
update : function() { | |
var data = $(this).data(); | |
$(this).css({ | |
'height': data.height, | |
'width': data.width, | |
'z-index': 1 | |
}); | |
$('#fill').css({ | |
'height': data.fillHeight, | |
'width': data.width, | |
'margin-top': data.height - data.fillHeight, | |
'z-index': 0 | |
}); | |
$('#thumb').css({ | |
'height': data.thumbHeight, | |
'width': data.width/2, | |
'top': function() { | |
var thumbMargin = (data.height - data.fillHeight - (data.thumbHeight/2)); | |
return thumbMargin; | |
}, | |
'right': 10 | |
}); | |
$('#caption').text("INITIALIZED THERMOMETER: " + data.fillHeight + "/" + data.height) | |
}, | |
edit : function(changes) { | |
// edit | |
} | |
}; | |
$.fn.thermometer = function(method) { | |
if ( methods[method] ) { | |
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); | |
} else if( typeof method === 'object' || !method ) { | |
return methods.init.apply(this, arguments); | |
} else { | |
$.error('Method ' + method + ' does not exist on the current object.'); | |
} | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment