chrisben / imgcache.js

JS library based on the File API to cache images for offline recovery (target: cordova/phonegap & chrome)
Other
826 stars 216 forks source link

iOs image loading fine in Xcode simulator but not on the device itself. #252

Open CapstoneUX opened 3 years ago

CapstoneUX commented 3 years ago

RangeCollectionCell.prototype.drawCell = function() {

this.addClass("rangeCollection");
this.viewElement.style.width = "50%";
this.viewElement.style.display = "inline-block"
this.row_content.style.position = "relative";

this.imageView = document.createElement('a');
this.imageView.className = "range-image";
this.imageView.style.display = "block";
this.imageView.style.position = "absolute";
this.imageView.style.left = "9px"; 
this.imageView.style.right = "9px";
this.imageView.style.top = "20px";
this.imageView.style.height = "165px";
this.imageView.style.border = "1px solid #aaa";
this.imageView.style.backgroundImage = "url('"+app.url+"/app/brand/placeholder')";
this.imageView.href = "/uploads/product_images/"+this.range.RANGECODE+".jpg";
this.imageView.style.backgroundSize = "contain";
this.imageView.style.backgroundRepeat = "no-repeat";
this.imageView.style.backgroundPosition = "center center";

//Lazy load the product image
if(this.range.IMAGE_EXISTS) {
    var self = this;
    var img = new Image();

    ImgCache.isCached(app.url+"/uploads/product_images/"+self.range.RANGECODE+".jpg", function(path, success){
        if(success){
            ImgCache.getCachedFileURL(app.url+"/uploads/product_images/"+self.range.RANGECODE+".jpg",
                function (src, url) {
                    if (device.platform == "browser") {
                        url = src;
                    }

                    img.src = url;
                    self.imageView.href = url;
                    self.imageView.style.backgroundImage = "url(" + url + ")";
                    self.imageView.setAttribute("data-fresco-group", "gallery");
                    self.imageView.className += " fresco";
                }
            );
        } else {
            ImgCache.cacheFile(app.url+"/uploads/product_images/"+self.range.RANGECODE+".jpg", function () {
                ImgCache.getCachedFileURL(app.url+"/uploads/product_images/"+self.range.RANGECODE+".jpg",
                    function (src, url) {

                        if (device.platform == "browser") {
                            url = src;
                        }
                        img.src = url;
                        self.imageView.href = url;
                        self.imageView.style.backgroundImage = "url(" + url + ")";
                        self.imageView.setAttribute("data-fresco-group", "gallery");
                        self.imageView.className += " fresco";
                    }
                );
            });
        }
    })
}

this.row_content.appendChild(this.imageView);

var name = document.createTextNode(this.range.RANGE_NAME);
this.textLabel = document.createElement('label');
this.textLabel.className = "rangeLabel";
this.textLabel.appendChild(name);
this.textLabel.style.position = "absolute";
this.textLabel.style.left = "9px";
this.textLabel.style.right = "9px";
this.textLabel.style.bottom = "10px";
this.textLabel.style.textAlign = "center";
this.row_content.appendChild(this.textLabel);

return this.row_content;

}