Last active
January 3, 2016 00:29
-
-
Save pavelpower/8382795 to your computer and use it in GitHub Desktop.
create special Image for html
This file contains hidden or 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
var FactorySuperImage = (function() { | |
function _onLoad() { | |
this.isloaded = true; | |
if (this.width === 0 && this.height === 0) | |
this.load_deferred.reject( new Error('image is not loaded') ); | |
else { | |
this.originalSize = { | |
width: this.width, | |
height: this.height | |
}; | |
this.load_deferred.resolve(this); | |
} | |
} | |
function _onerror(e) { | |
this.load_deferred.reject(e); | |
} | |
function load(path) { | |
this.src = path; | |
return this.load_deferred; | |
} | |
function setSize(w, h) { | |
this.width = w; | |
this.height = h; | |
} | |
return function (options) { | |
var image = new Image(); | |
image.load_deferred = $.Deferred(); | |
image.isloaded = false; | |
image.onload = _onLoad; | |
image.onerror= _onerror; | |
image.load = load; | |
image.setSize = setSize; | |
return image; | |
} | |
})(); | |
var i = new FactorySuperImage(); | |
i.load('/images/login/watermark.png?123123') | |
.done(function(b) { console.log('->', b, b.originalSize); }) | |
.fail(function(e) { console.log(e) }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment