Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Supports data-at2x attributes.

Uses supplied data-at2x attributes for the @2x asset URLs instead of doing HEAD requests.
  • Loading branch information...
commit 9081a9269dc0a2e189d9f72c96f3568e11d4a12c 1 parent 5671145
@ronny ronny authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/retina.js
View
14 src/retina.js
@@ -52,9 +52,15 @@
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 = [];
@@ -67,6 +73,8 @@
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 {
@@ -99,7 +107,7 @@
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();
Please sign in to comment.
Something went wrong with that request. Please try again.