Skip to content

Commit

Permalink
Merge pull request #196 from AdrianMarinica/background-with-source
Browse files Browse the repository at this point in the history
added useCachedBackgroundWithSource as an option and updated documentation
  • Loading branch information
adrianmarinica authored Mar 2, 2017
2 parents bd08ce4 + 4d3496a commit 8b09885
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ High level API
* ImgCache.**isBackgroundCached**() *-- checks if a the given element background image exists in the cache - does not check if the latest version of that file is cached*
* ImgCache.**cacheBackground**() *-- caches the background image of an element*
* ImgCache.**useCachedBackground**() *-- replaces the background image source of the given element with the cached version*
* ImgCache.**useCachedBackgroundWithSource**() *-- similar to useCachedBackground but with the image source url as extra parameter*
* ImgCache.**useBackgroundOnlineFile**() *-- replaces back a background image with the original (online) version*
* ImgCache.**removeFile**() *-- removes a given file from the cache*
* ImgCache.**getCurrentSize**() *-- returns the current size of the ImgCache cache in bytes // synchronous method*
Expand Down
21 changes: 15 additions & 6 deletions js/imgcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,12 @@ var ImgCache = {
ImgCache.attributes.filesystem.root.getFile(Private.getCachedFilePath(img_src), {create: false}, _gotFileEntry, _fail);
};

Private.setBackgroundImagePath = function ($element, new_src, old_src) {
DomHelpers.setBackgroundImage($element, 'url("' + new_src + '")');
// store previous url in case we need to reload it
DomHelpers.setAttribute($element, OLD_BACKGROUND_ATTR, old_src);
};

/****************************************************************************/


Expand Down Expand Up @@ -876,13 +882,16 @@ var ImgCache = {
return;
}

var _setBackgroundImagePath = function ($element, new_src, old_src) {
DomHelpers.setBackgroundImage($element, 'url("' + new_src + '")');
// store previous url in case we need to reload it
DomHelpers.setAttribute($element, OLD_BACKGROUND_ATTR, old_src);
};
Private.loadCachedFile($div, img_src, Private.setBackgroundImagePath, success_callback, error_callback);
};

ImgCache.useCachedBackgroundWithSource = function ($div, image_url, success_callback, error_callback) {

if (!Private.isImgCacheLoaded()) {
return;
}

Private.loadCachedFile($div, img_src, _setBackgroundImagePath, success_callback, error_callback);
Private.loadCachedFile($div, image_url, Private.setBackgroundImagePath, success_callback, error_callback);
};


Expand Down

0 comments on commit 8b09885

Please sign in to comment.