-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa38b94
commit d3ce429
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.settings | ||
.project | ||
.buildpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "imageSRC", | ||
"version": "1.0.0", | ||
"title": "jQuery Image SRC", | ||
"author": { | ||
"name": "dwoutsourcing", | ||
"email": "[email protected]", | ||
"url": "https://github.com/dwoutsourcing" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/dwoutsourcing/imageSRC/blob/master/LICENSE" | ||
} | ||
], | ||
"dependencies": { | ||
"jquery": ">=1.5" | ||
}, | ||
"description": "jQuery plugin to set image src attribute from either dataURL strings, File instances or string values and adding progress event.", | ||
"keywords": [ | ||
"image", | ||
"image tag", | ||
"image attributes", | ||
"image tag attribute", | ||
"image src attribute", | ||
"image progress event", | ||
"image source", | ||
"image load from File" | ||
], | ||
"maintainers": [ | ||
{ | ||
"name": "dwoutsourcing", | ||
"email": "[email protected]", | ||
"url": "https://github.com/dwoutsourcing" | ||
} | ||
], | ||
"bugs": "https://github.com/dwoutsourcing/imageSRC/issues", | ||
"homepage": "https://github.com/dwoutsourcing/imageSRC", | ||
"docs": "https://github.com/dwoutsourcing/imageSRC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Author: dwoutsourcing ([email protected]) | ||
* License: MIT | ||
*/ | ||
(function($, undefined) { | ||
function getSourceType(source) { | ||
var type; | ||
|
||
if(/^data:image/.test(source)) | ||
type = 'dataURL'; | ||
else { | ||
if(typeof source == 'string') | ||
type = 'path'; | ||
else if(source.name) | ||
type = 'localFile'; | ||
} | ||
|
||
return type; | ||
} | ||
|
||
function initializeLoader($loader, $scope) { | ||
return $loader | ||
.on('progress', function(event, originalEvent, perc, loaded, total) { | ||
$scope.trigger('progress', [originalEvent, perc, loaded, total]); | ||
}) | ||
.on('loadstart', function(event, originalEvent) { | ||
$scope.trigger('loadstart', [originalEvent]); | ||
}) | ||
.on('loadend', function(event, originalEvent, result) { | ||
$scope.trigger('loadend', [originalEvent, result]); | ||
}) | ||
.on('error', function(event, originalEvent, result) { | ||
$scope.trigger('error'); | ||
}) | ||
; | ||
} | ||
|
||
$.fn.extend({ | ||
src: function(source) { | ||
var sourceType = getSourceType(source); | ||
var $loader; | ||
|
||
this.each(function() { | ||
var $this = $(this); | ||
$this.data('dw-source-type', sourceType); | ||
|
||
switch(sourceType) { | ||
case 'dataURL': | ||
this.src = source; | ||
break; | ||
|
||
case 'path': | ||
if($.canLoadData()) { | ||
$loader = initializeLoader($.dataLoader(), $this) | ||
.on('load', function(event, originalEvent, response) { | ||
var blob = new Blob([response]); | ||
var result = window.URL.createObjectURL(blob); | ||
|
||
$this.attr('src', result); | ||
}) | ||
.loadData(source, null, 'arraybuffer') | ||
; | ||
} | ||
else | ||
this.src = source; | ||
break; | ||
|
||
case 'localFile': | ||
$loader = initializeLoader($.fileReader(), $this) | ||
.on('load', function(event, originalEvent, result) { | ||
$this.attr('src', result); | ||
}) | ||
.readAsDataURL(source) | ||
; | ||
break; | ||
|
||
} | ||
|
||
$this.abort = function() { | ||
if($loader) | ||
$loader.abort(); | ||
}; | ||
}); | ||
} | ||
}); | ||
}( jQuery )); |