Skip to content

Commit

Permalink
Version 1.01
Browse files Browse the repository at this point in the history
  • Loading branch information
saniyusuf committed Mar 1, 2015
1 parent d683fce commit eda45d5
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Created by .ignore support plugin (hsz.mobi)
bower_components
bower_components
.idea
23 changes: 17 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "imagenie",
"main": "imagenie.js",
"main": [
"imagenie.js",
"imagenie.min.js"
],
"version": "0.0.0",
"homepage": "https://github.com/saniyusuf/imagenie",
"authors": [
Expand All @@ -21,17 +24,25 @@
"node_modules",
"bower_components",
"test",
"tests"
"tests",
"karma.conf.js",
"gulpfile.js",
".gitignore"
],
"devDependencies": {
"angular": "1.3.6",
"angular-mocks": "1.3.6"
"angular-mocks": "1.3.6",
"ionic": "1.0.0-beta.14"
},
"dependencies": {
"angular-localforage": "1.2.2",
"localforage": "1.2.2"
"angular-localforage": "~1.2.2",
"localforage": "~1.2.2"
},
"resolutions": {
"localforage": "1.2.0"
"localforage": "1.2.2",
"angular": "1.3.6",
"angular-animate": "1.3.6",
"angular-ui-router": "0.2.13",
"angular-sanitize": "1.3.6"
}
}
22 changes: 22 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Created by Sani on 25/02/2015.
*/

var gulp = require('gulp');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');


gulp.task('minify', function () {
return gulp.src('src/imagenie.js')
.pipe(uglify())
.pipe(rename('imagenie.min.js'))
.pipe(gulp.dest('./'));
});

gulp.task('unMinified', function () {
return gulp.src('src/imagenie.js')
.pipe(gulp.dest('./'));
});

gulp.task('default', ['unMinified', 'minify']);
40 changes: 14 additions & 26 deletions imagenie.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@
canvas.width = img.width;
ctx.drawImage(img, 0, 0);
dataURL = canvas.toDataURL(outputFormat);
imageBase64StringPromise.resolve(dataURL);
canvas = null;
//callback.call(this, dataURL);
imageBase64StringPromise.resolve(dataURL);
};
img.onerror = function () {
imageBase64StringPromise.reject(url);
};
img.src = url;
return imageBase64StringPromise.promise;

};

ImagenieUtil.isUndefined = function (value) {
Expand All @@ -61,13 +59,10 @@

ImagenieUtil.getImageSrc = function (elementAttributes) {
if(!this.isEmpty(elementAttributes.imagenie)){
//console.log('Image SRC Gotten From Imagenie : ' + elementAttributes.imagenie);
return elementAttributes.imagenie;
}else if(!this.isEmpty(elementAttributes.ngSrc)){
//console.log('Image SRC Gotten From NG-SRC : ' + elementAttributes.ngSrc);
return elementAttributes.ngSrc;
}else if (!this.isEmpty(elementAttributes.src)){
//console.log('Image SRC Gotten From SRC : ' + elementAttributes.src);
return elementAttributes.src;
}else{
console.warn('Image Src Undefined');
Expand All @@ -83,6 +78,14 @@
}
};

ImagenieUtil.isUriAbsolute = function (uri) {
//****************
//http://stackoverflow.com/questions/10687099/how-to-test-if-a-url-string-is-absolute-or-relative
//****************
var uriTypeRegex = new RegExp('^(?:[a-z]+:)?//', 'i');
return uriTypeRegex.test(uri);
};

return ImagenieUtil;
}

Expand All @@ -91,7 +94,7 @@
restrict: 'A',
link: function (scope, element, attrs) {

attrs.$observe('imagenie', function (value) {
attrs.$observe('imagenie', function () {
var imageSrc = ImagenieUtil.getImageSrc(attrs);
var imagenieLocalForageInstance = {};

Expand All @@ -107,31 +110,20 @@
}
}

//Check if URI Is Absolute
//
//If URI Is Relative, No Need To Cache It Or Attempt To Retrieve It
//****************
//http://stackoverflow.com/questions/10687099/how-to-test-if-a-url-string-is-absolute-or-relative
//****************

var uriTypeRegex = new RegExp('^(?:[a-z]+:)?//', 'i');
if(uriTypeRegex.test(imageSrc)){
if(ImagenieUtil.isUriAbsolute((imageSrc))){

attrs.ngSrc = '';
imagenieLocalForageInstance.getItem(encodeURIComponent(imageSrc))
.then(function (localImageSuccessData) {
//console.log('This Image Exists In Local Forage: ' + imageSrc);
if(!ImagenieUtil.isEmpty(localImageSuccessData)){

ImagenieUtil.setImageToElement(element, localImageSuccessData);

}else{
//console.log('Image Exist But Is Undefined Or Empty');
var newImage = angular.element('<img />');
newImage.bind('load', function (loadedEvent) {
newImage.bind('load', function () {
ImagenieUtil.getImageBase64String(imageSrc)
.then(function (imageBase64String) {
//console.log('Gotten The Base 64 Image String');
imagenieLocalForageInstance.setItem(encodeURIComponent(imageSrc), imageBase64String);
ImagenieUtil.setImageToElement(element, imageBase64String);

Expand All @@ -141,23 +133,19 @@
newImage.attr('src', imageSrc);
}

}, function (localImageFailureData) {
}, function () {

//console.log('Image Does Not Exist In Local Forage');
var newImage = angular.element('<img />');
newImage.bind('load', function (loadedEvent) {
newImage.bind('load', function () {
ImagenieUtil.getImageBase64String(imageSrc)
.then(function (imageBase64String) {
//console.log('Gotten The Base 64 Image String');
imagenieLocalForageInstance.setItem(encodeURIComponent(imageSrc), imageBase64String);
ImagenieUtil.setImageToElement(element, imageBase64String);
});
});

newImage.attr('src', imageSrc);
});
}else{
//console.log(attrs);
}
});

Expand Down
1 change: 1 addition & 0 deletions imagenie.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Karma configuration
// Generated on Sat Feb 28 2015 18:42:16 GMT+0000 (GMT Standard Time)

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',

main: ['imagenie.js', 'imagenie.min.js'],


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'src/*.js',
'bower_components/angular-localforage/dist/angular-localForage.js',
'tests/*.js'
],

// list of files to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
Loading

0 comments on commit eda45d5

Please sign in to comment.