/*!
jqthumb v1.9.3
copyright (c) 2013-2014
dual licensed under the mit and gpl licenses.
author : pak cheong
version : 1.9.3
repo : https://github.com/pakcheong/jqthumb
demo : http://pakcheong.github.io/jqthumb/
last updated : thursday, july 10th, 2014, 4:32:44 pm
requirements : jquery >=v1.3.0 or zepto (with zepto-data plugin) >=v1.0.0
*/
;(function ( $, window, document, undefined ) {
var pluginname = "jqthumb",
grandglobal = { outputelems: [], inputelems: [] },
defaults = {
classname : 'jqthumb',
width : 100,
height : 100,
position : { top: '50%', left: '50%' },
source : 'src',
showoncomplete : true,
before : function(){},
after : function(){},
done : function(){}
};
function plugin ( element, options ) {// the actual plugin constructor
this.element = element;
this.settings = $.extend( {}, defaults, options );
this.settings.width = this.settings.width.tostring().replace(/px/g, '');
this.settings.height = this.settings.height.tostring().replace(/px/g, '');
this.settings.position.top = this.settings.position.top.tostring().replace(/px/g, '');
this.settings.position.left = this.settings.position.left.tostring().replace(/px/g, '');
this._defaults = defaults;
this._name = pluginname;
if(typeof options == 'string'){
if(options.tolowercase() == 'kill'){
this.kill(this.element);
}
}else{
this.init();
}
}
plugin.prototype = {
init: function () {
if(this.support_css3_attr('backgroundsize') === false){ // old browsers need to do calculation to perform same output like "background-size: cover"
this.noncss3supported_method(this.element, this.settings);
}else{ // modern browsers that support css3 would be easier
this.css3supported_method(this.element, this.settings);
}
},
kill: function(_this){
if( $(_this).data(pluginname)){
if($(_this).prev().data(pluginname) !== pluginname){
console.error('we could not find the element created by jqthumb. it is probably due to one or more element has been added right before the image element after the plugin initialization, or it was removed.');
return false;
}
/* start: remove output elements */
var temparr = [];
$.each(grandglobal.outputelems, function(index, obj){
if($(obj)[0] == $(_this).prev()[0]){
}else{
temparr.push(grandglobal.outputelems[index]);
}
});
grandglobal.outputelems = temparr;
/* end: remove output elements */
/* start: remove input elements */
temparr = [];
$.each(grandglobal.inputelems, function(index, obj){
if($(obj)[0] == $(_this)[0]){
}else{
temparr.push(grandglobal.inputelems[index]);
}
});
grandglobal.inputelems = temparr;
/* end: remove input elements */
$(_this).prev().remove();
$(_this).removeattr('style'); // first, remove all the styles first
if(typeof $(_this).data(pluginname + '-original-styles') !== 'undefined'){
$(_this).attr('style', $(_this).data(pluginname + '-original-styles')); // then re-store the original styles
}
if(typeof $(_this).data(pluginname + '-original-styles') !== 'undefined'){
$(_this).removedata(pluginname + '-original-styles'); // remove data that stores the original stylings before the image being rendered
}
if(typeof $(_this).data(pluginname) !== 'undefined'){
$(_this).removedata(pluginname); // remove data that stored during plugin initialization
}
}
},
noncss3supported_method: function(_this, options){
options.before.call(_this, _this);
var that = this,
$this = $(_this);
$this.data(pluginname + '-original-styles', $this.attr('style')); // keep original styles into data
$this.hide();
var $tempimg = $("");
$tempimg.bind('load', function(){
var newimg = {
obj: $tempimg,
size: {
width: this.width,
height: this.height
}
},
pw = that.percentorpixel(options.width),
ph = that.percentorpixel(options.height),
imgcontainer = $('