vendor/assets/javascripts/retina.js in retina_rails-0.0.3 vs vendor/assets/javascripts/retina.js in retina_rails-0.0.4
- old
+ new
@@ -26,13 +26,11 @@
context.onload = function() {
var images = document.getElementsByTagName("img"), retinaImages = [], i, image;
for (i = 0; i < images.length; i++) {
image = images[i];
- if ($(image).attr('data-retina') != 'true') {
- retinaImages.push(new RetinaImage(image));
- }
+ retinaImages.push(new RetinaImage(image));
}
existing_onload();
}
};
@@ -52,13 +50,19 @@
};
root.RetinaImagePath = RetinaImagePath;
- function RetinaImagePath(path) {
+ function RetinaImagePath(path, at_2x_path) {
this.path = path;
- this.at_2x_path = path.replace(/\.\w+$/, function(match) { return "@2x" + match; });
+ if (typeof at_2x_path !== "undefined" && at_2x_path !== null) {
+ this.at_2x_path = at_2x_path;
+ this.perform_check = false;
+ } else {
+ this.at_2x_path = path.replace(/\.\w+$/, function(match) { return "@2x" + match; });
+ this.perform_check = true;
+ }
}
RetinaImagePath.confirmed_paths = [];
RetinaImagePath.prototype.is_external = function() {
@@ -67,10 +71,12 @@
RetinaImagePath.prototype.check_2x_variant = function(callback) {
var http, that = this;
if (this.is_external()) {
return callback(false);
+ } else if (!this.perform_check && typeof this.at_2x_path !== "undefined" && this.at_2x_path !== null) {
+ return callback(true);
} else if (this.at_2x_path in RetinaImagePath.confirmed_paths) {
return callback(true);
} else {
http = new XMLHttpRequest;
http.open('HEAD', this.at_2x_path);
@@ -99,10 +105,10 @@
function RetinaImage(el) {
this.el = el;
- this.path = new RetinaImagePath(this.el.getAttribute('src'));
+ this.path = new RetinaImagePath(this.el.getAttribute('src'), this.el.getAttribute('data-at2x'));
var that = this;
this.path.check_2x_variant(function(hasVariant) {
if (hasVariant) that.swap();
});
}