Git Product home page Git Product logo

angular-imgcache.js's Introduction

angular-imgcache.js

Simple imgcache.js wrapper for AngularJS, can be user with Ionic/Cordova/Phonegap.

Installation

Install via bower

bower install --save angular-imgcache.js

Link library and dependencies

<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/imgcache.js/js/imgcache.js"></script>
<script src="bower_components/angular-imgcache.js/angular-imgcache.js"></script>

Load module

angular.module('MyApp', [
    'ImgCache'
])

Usage

Configuration

You can override imgcache.js default options in Angulars config section.

.config(function(..., ImgCacheProvider) {

    // set single options
    ImgCacheProvider.setOption('debug', true);
    ImgCacheProvider.setOption('usePersistentCache', true);

    // or more options at once
    ImgCacheProvider.setOptions({
        debug: true,
        usePersistentCache: true
    });

    // ImgCache library is initialized automatically,
    // but set this option if you are using platform like Ionic -
    // in this case we need init imgcache.js manually after device is ready
    ImgCacheProvider.manualInit = true;

    ...

});

If you are using platform like Ionic, you have to init ImgCache manually. Note: you must set ImgCacheProvider.manualInit = true; as in example above.

.run(function($ionicPlatform, ImgCache) {

    $ionicPlatform.ready(function() {
        ImgCache.$init();
    });

});

You can init library manually in other patforms via "deviceready" callback like this:

<body onload="onLoad()">
function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
    ImgCache.$init();
}

(Thx @emps for this note in #1)

Service

Access imgcache.js and its original methods in your components via promise to make sure that imgcache.js library is already initialized

.controller('MyCtrl', function($scope, ImgCache) {

    ImgCache.$promise.then(function() {
        ImgCache.cacheFile('...');
    });

});
Directive

Angular-imgcache.js comes with directive, which first looks into cache for an image. If not present, it downloads image, then stores in cache and uses it.

We can set src of an image with ic-src attribute.

<img img-cache ic-src="{{imgUrl}}" />

Or set elements background-image with ic-bg attribute.

<div img-cache ic-bg="{{imgUrl}}" ></div>

angular-imgcache.js's People

Contributors

jbenes avatar

Stargazers

James Chandler avatar Nick M avatar Sagar Shah avatar Wellington Torrejais da Silva avatar João Holanda avatar S_P avatar Shaabi avatar Giorgio Fellipe avatar  avatar Faisal nawaz avatar septs avatar leob avatar  avatar Fengda Huang avatar Miroslav Vitanov avatar Antonio Rossi avatar Byambatseren B. avatar Maurício Júnior avatar The End avatar Jonas avatar Gino avatar Nathan Mahdavi avatar wei avatar jdahe avatar  avatar Alexander Elgin avatar Jean DAT avatar Frank Wang avatar Alex Dyba avatar Johannes Millan avatar Vladimir Lugovsky avatar Alex Escalante avatar Fabriece Sumuni avatar Crazy Replicant avatar Jean Lucas de Carvalho avatar Spencer Roh avatar haha avatar Frédéric Marcel Falliere avatar lally elias avatar Sean Kennedy avatar Graham Oldfield avatar  avatar Anthony Mills avatar Catold avatar Eusthace Corin avatar Paul Walger avatar  avatar Felipe Gonçalves dos Reis avatar Marco avatar Chris Witko avatar Pachito Marco Calabrese avatar J.L avatar  avatar zooofeex avatar Juscyllan S Queiroz avatar  avatar nbamj avatar Steve Hanna avatar Bernardo de Oliveira Bruning avatar Rafael avatar Nicolae avatar Ryan Rose avatar Emir Kuljanin avatar Cirillo Ferreira avatar Damien Galan avatar Abay Zhuang avatar  avatar  avatar Anees v avatar Leandro Araújo avatar Julien Renaux avatar Murilo avatar Bruno Peres avatar Leonardo Ruhland avatar Zaher Ghaibeh avatar Andrea Gherardi avatar Aditya Sahay avatar José Luis EA avatar Ross Martin avatar Madd.is avatar Julian Frumar avatar  avatar Karol avatar

Watchers

Eusthace Corin avatar Frédéric Marcel Falliere avatar  avatar James Cloos avatar Cirillo Ferreira avatar Shai Snir avatar  avatar Graham Oldfield avatar

angular-imgcache.js's Issues

Directives not working

ImgCache.$promise.then(function() {
+

  •                ImgCache.isCached(src, function(path, success) {
    

Code is not reaching this section

It's not working

Hello, I'm using with ionic.

I think I'm doing all right however seems not working.

I'm link the files

<script src="js/ionic.bundle.min.js"></script>
<script src="js/imgcache.js"></script>
<script src="js/angular-imgcache.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>

In the file app.js I init the imgcache

angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ImgCache'])

.run(function($ionicPlatform, ImgCache) {
    $ionicPlatform.ready(function() {
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }

        ImgCache.$init();
    });
})

.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider, ImgCacheProvider) {
    ImgCacheProvider.manualInit = true;
...
});

And in the templates I'm using

<img img-cache ic-src="http://site/{{ PhotoApp) }}" ng-src="http://site/{{ PhotoApp }}" alt="{{ Name }}">

Checking the cache size the images appear cached.

But after a while accessing the app offline the images don't work.

I forgot something?

Error when running on ios (ionic)

I am seeing this error using ionic (works fine on the browser but not in iOS)

TypeError: undefined is not a function (evaluating 'window.requestFileSystem(Helpers.getCordovaStorageType(ImgCache.options.usePersistentCache), 0, _gotFS, _fail)')

I have followed the all the steps in the docs but still getting the error.

requestFileSystem problem

hii im using mobile angular ui and getting this log in console and app not works while tring use this script u provide

Uncaught TypeError: Object [object global] has no method 'requestFileSystem'

ionic iOS issue

I get these errors in ionic on my iphone. The image is in an ngRepeat

            <ion-slide ng-repeat="item in sponsorData['ui']" ng-if="item.sid !== 'sponsor_splash'" class="wizard-slide">
                <!-- <div img-cache ic-bg="{{imgUrl}}" ></div>               -->
                <div img-cache class="sponsor bg" ic-bg="{{item['featured_image']}}"></div>
                <div class="bottom sponsor" ng-bind-html="item['content']"></div>
            </ion-slide>

[Log] INFO: LocalFileSystem opened (vendors.min.js, line 852)
[Log] INFO: Local cache folder opened: /imgcache/ (vendors.min.js, line 852)
[Log] INFO: com.apple.MobileBackup metadata set (vendors.min.js, line 852)
[Log] ERROR: Download error source: https://storycorpsme.s3.amazonaws.com/uploads/2015/08/knight.jpg (vendors.min.js, line 852)
[Log] ERROR: Download error target: cdvfile://localhost/root/imgcache/c56f69853d5444c697307b96a1eef89a55a64830.jpg (vendors.min.js, line 852)
[Log] ERROR: Download error code: 1 (vendors.min.js, line 852)
[Log] ERROR: Download error source: https://storycorpsme.s3.amazonaws.com/uploads/2015/08/airbnb_test.jpg (vendors.min.js, line 852)
[Log] ERROR: Download error target: cdvfile://localhost/root/imgcache/be0f1e88a316eb2b049b2bc09fadef9cac2c5e87.jpg (vendors.min.js, line 852)
[Log] ERROR: Download error code: 1 (vendors.min.js, line 852)

"WARN: Your browser does not support the html5 File API"

Hi there!

I am developing an ionic app and mentioned that in my firefox (developer edition) i get this error: "WARN: Your browser does not support the html5 File API".

The images are not displayed.

Any ideas how to fix that?

processMessage failed

Hello jBenes,
i'm stuck at this error messages since weeks:

imgcache.js:44 INFO: LocalFileSystem opened
imgcache.js:44 INFO: Local cache folder opened: file:///storage/emulated/0/imgcache/
imgcache.js:44 INFO: .nomedia file created.
cordova.js:1058 processMessage failed: Error: TypeError: Cannot read property 'resolve' of undefined
cordova.js:1059 processMessage failed: Stack: TypeError: Cannot read property 'resolve' of undefined
    at file:///storage/emulated/0/Android/data/com.intel.html5tools.apppreview/cache/previews/WPIonic/1/lib/angular-imgcache.js:8:31
    at _checkSize (file:///storage/emulated/0/Android/data/com.intel.html5tools.apppreview/cache/previews/WPIonic/1/bower_components/imgcache.js/js/imgcache.js:526:33)
    at file:///storage/emulated/0/Android/data/com.intel.html5tools.apppreview/cache/previews/WPIonic/1/bower_components/imgcache.js/js/imgcache.js:536:5
    at _androidNoMediaFileCreated (file:///storage/emulated/0/Android/data/com.intel.html5tools.apppreview/cache/previews/WPIonic/1/bower_components/imgcache.js/js/imgcache.js:344:45)
    at DirectoryEntry.getFile.win (file:///storage/emulated/0/Android/data/com.intel.html5tools.apppreview/cac…iews/WPIonic/1/plugins/org.apache.cordova.file/www/DirectoryEntry.js:109:9)
    at Object.cordova.callbackFromNative (file:///storage/emulated/0/Android/data/com.intel.html5tools.apppreview/cache/previews/WPIonic/1/cordova.js:292:54)
    at processMessage (file:///storage/emulated/0/Android/data/com.intel.html5tools.apppreview/cache/previews/WPIonic/1/cordova.js:1053:21)
    at Function.androidExec.processMessages (file:///storage/emulated/0/Android/data/com.intel.html5tools.apppreview/cache/previews/WPIonic/1/cordova.js:1090:13)
    at pollOnce (file:///storage/emulated/0/Android/data/com.intel.html5tools.apppreview/cache/previews/WPIonic/1/cordova.js:955:17)
    at pollOnceFromOnlineEvent (file:///storage/emulated/0/Android/data/com.intel.html5tools.apppreview/cache/previews/WPIonic/1/cordova.js:945:5)
cordova.js:1060 processMessage failed: Message: S01 File1568179966 {"fullPath":"\/imgcache\/.nomedia","filesystemName":"persistent","isDirectory":false,"nativeURL":"file:\/\/\/storage\/emulated\/0\/imgcache\/.nomedia","filesystem":1,"isFile":true,"name":".nomedia"}

I can't find a solution.
I'm using IntelXDK for development and it's an Ionic-Applicaiton.

Thank you
mysecondworld

Base64 in ic-src nothing happens

<img img-cache ic-src="{{oImage.src}}" class="fullscreen-image" />

Is something like this not possible? The structure of oImage.src is:

{src: 'data:image/jpg;base64,' + data.Data} where data.Data the base64 image is

Error on $init - Ionic

Hi guys,

Just trying out this directive but I've run into this issue. I'm getting this error in the console:

Error: undefined is not a function (evaluating 'window.requestFileSystem(t.getCordovaStorageType(ImgCache.options.usePersistentCache),0,o,a)')

I'm using ionic and I followed everything stated on the docs.
All imgcache js files on the index.html, ImgCacheProvider on the .config and $init on the .run

.config(function (... , ImgCacheProvider) {
    'use strict';
    ...
    ImgCacheProvider.setOptions({
        debug: true,
        usePersistentCache: true
    });

    // ImgCache library is initialized automatically,
    // but set this option if you are using platform like Ionic -
    // in this case we need init imgcache.js manually after device is ready
    ImgCacheProvider.manualInit = true;

}).run(function (..., ImgCache) {

    'use strict';
...
    $ionicPlatform.ready(function () {
        ...
        ImgCache.$init();
    });
});

Nested Element

I've HTML content in a field. Any idea how i can trigger image replace for this?

<div class="chapter" ng-bind-html="capitolo.cms_body | raw_html"></div>

Incorrect location in readme

<script src="bower_components/angular-imgcache.js/angular-imgcache.js"></script>

should be

<script src="bower_components/angular-imgcache/angular-imgcache.js"></script>

the folder for angular-imgcache doesn't have a .js extension but imgcache does.

Is this maintained anymore?

This seems like it's not being maintained anymore, the latest commit was in October (and it actually broke the api).
Would it be possible for me to take over maintenance?
ping @jBenes @sidferreira

I would be happy to take over the repository, and will at least try to keep my fork updated for now.

For all the current Pull Requests:

  • @icer2000 (#17): I merged your PR already, nice work!
  • @fvicente (#16): I just reverted the original change (af51b2c), which seems to work just fine.
  • @simpixelated (#14): I merged your PR, I guess I should create a npm repository as well?
  • @septembermd (#13): I think angular probably should be a dependency, since it's used within the project.
  • @rbose85 (#8): Using a default image while waiting for the remote is quite nice, but I think it might be better to have an option for it than for it to be default.

Error when I use the cache on android and ios

Hello,

I have the following errors when I do not use connection on android and ios :
- Error on IOS
element.getAttribute(attr) : undefined is not a function
- Error on android
ImgCache not loaded yet! - Have you called ImgCache.Init() first?", source: file:///android_asset/www/lib/imgcache.js/js/imgcache.js

    Failed to mkdirat(/storage/extSdCard/Android): Read-only file system
    W/ContextImpl(30283): Failed to ensure directory: /storage/extSdCard/Android/data/re.linfo.linfoReApp/files
    E/cutils  (  224): Failed to mkdirat(/storage/extSdCard/Android): Read-only file system
    W/ContextImpl(30283): Failed to ensure directory: /storage/extSdCard/Android/data/re.linfo.linfoReApp/cache

Do you have an idea of the problem.

Supplementary Info :
- Cordova CLI 6.0.0
- cordova-ios 4.1.1
- cordova-android 5.1.1
- ionic CLI 1.7.8

Thanks

Failing in iOS using latest Cordova

This is great - thank you. It's working fine in Android, but in iOS using the latest Cordova (4.2.0 cli, iOS 3.7.0) I am stuck - it's attempting to write to a bad path:

2015-01-09 23:49:35.744 GroupAhead[4902:36770] FileTransferError { body = "Could not create path to save downloaded file: The operation couldn\U2019t be completed. (Cocoa error 513.)"; code = 1; "http_status" = 200; source = "http://10.0.0.2:1337/images/uploaded_photos/groupahead/thumbnail/thumbnail-groupahead_79700c48-c6ef-4202-9d3f-b900989cc3ad.jpg?groupkey=groupahead&token=3673f31d3cf0d641bc72fdbb1110f2c4204fa634c1c9a967770a93cbfe17a7af&v=1.0.0"; target = "cdvfile://localhost/root/imgcache/c9c8591092e4085047e99644adc7f8588e869cfe.jpg"; } 2015-01-09 23:49:35.744 GroupAhead[4902:36770] File Transfer Error: Could not create path to save downloaded file: The operation couldn’t be completed. (Cocoa error 513.)

When I put a String.replace call in to change the path from cdvfile://localhost/root/imgcache/c9c85.... to cdvfile://localhost/persistent/imgcache/c9c85... it started working. So I am pretty sure it's attempting to write to the wrong path.

Loading image from 127.0.0.1 works with imgcache.js but not with angular-imgcache.js

I was able to load and cache the image file using ImgCache.cacheFile() from imgcache.js. However, when I switch to using the img-cache directive like <img img-cache ic-src="{{ img_url }}">, I always got the XHR error like the following.

40    705389   log      ERROR: Download error source: http://127.0.0.1:8000/media/post/4137461961516911608/4137461961535552563_thumbnail.jpg
41    705390   log      ERROR: Download error target: /imgcache/ae85743729d59d33e5f2c8b5ec7d1047a906144e.jpg
42    705391   log      ERROR: Download error code: 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.