11/*
2- * angular-wurfl-image-tailor v0.9.3
2+ * angular-wurfl-image-tailor
33 * Authors: Luca Corbo (https://github.com/lucor)
44 * (c) 2014 - 2015 ScientiaMobile, Inc.
55 * License: MIT
@@ -24,30 +24,37 @@ angular.module('angular-wurfl-image-tailor', [])
2424 return {
2525 restrict : 'E' ,
2626 replace : false ,
27- scope :{ } ,
28- template : function ( element , attributes ) {
29- if ( 'ngSrc' in attributes ) {
30- return '<div class="wit"><img ng-src="{{wit_link}}"/></div>' ;
31- } else {
32- return '<div class="wit"><img src="{{wit_link}}"/></div>' ;
33- }
27+ scope : {
28+ src : '@' ,
29+ w : '@' ,
30+ h : '@' ,
31+ pc : '@' ,
32+ m : '@' ,
33+ f : '@' ,
34+ r : '@'
35+ } ,
36+ template : function ( element , attributes ) {
37+ return '<div class="wit"><img ng-src="{{wit_link}}"/></div>' ;
3438 } ,
3539 link : function ( scope , element , attributes ) {
36- var srcAName = 'ngSrc' in attributes ? 'ngSrc' : 'src' ;
3740 scope . wit_link = '' ;
3841
39- attributes . $observe ( srcAName , function ( src ) {
40- if ( ! src ) {
41- scope . wit_link = '' ;
42+ var allowedAttributes = [ 'w' , 'h' , 'pc' , 'm' , 'f' , 'r' ] ;
43+
44+ scope . $watchCollection ( '[src, w, h, pc, m, f, r]' , function ( values , oldValues ) {
45+
46+ var src = values . shift ( ) ;
47+ if ( ! src ) {
4248 return ;
4349 }
4450
4551 var wit_link_pieces = [ witUrls . get ( ) ] ;
46- angular . forEach ( attributes [ '$attr' ] , function ( attr ) {
47- if ( attr != 'src' && attr != 'ng-src' ) {
48- wit_link_pieces . push ( attr + '_' + attributes [ attr ] ) ;
52+ angular . forEach ( allowedAttributes , function ( attribute , index ) {
53+ if ( values [ index ] ) {
54+ wit_link_pieces . push ( attribute + '_' + values [ index ] ) ;
4955 }
5056 } ) ;
57+
5158 wit_link_pieces . push ( src ) ;
5259 scope . wit_link = wit_link_pieces . join ( '/' ) ;
5360 } ) ;
0 commit comments