diff --git a/angular-panorama.js b/angular-panorama.js index c558163..63e21c6 100644 --- a/angular-panorama.js +++ b/angular-panorama.js @@ -1,6 +1,6 @@ /** * Angular Panorama - Mimic Windows Phone's Panorama UI control. - * @version v0.1.1 - 2013-12-28 + * @version v0.1.1 - 2013-12-30 * @link http://cnjsstong2.github.com/angular-panorama * @author Tong Shen * @license MIT License, http://www.opensource.org/licenses/MIT @@ -323,10 +323,14 @@ angular.module('angular-panorama') container.css('background-image', 'url('+iAttrs.ngPanoramaBackgroundImage+')'); container.css('background-position','0% 50%'); } - scope.$watch('iAttrs.ngPanoramaBackgroundImage', function(newValue){ + iAttrs.$observe('ngPanoramaBackgroundImage', function(newValue, oldValue){ + console.log(scope); + console.log(oldValue); + console.log(newValue); if(newValue) { + console.log('changing..'); container.css('background-image', 'url('+newValue+')'); - container.css('background-position','0% 50%'); + container.css('background-position',scope.panoramaCollection.position/scope.panoramaCollection.lastIndex*100+'% 50%'); } }); diff --git a/angular-panorama.min.js b/angular-panorama.min.js index e0c83f0..408c8c3 100644 --- a/angular-panorama.min.js +++ b/angular-panorama.min.js @@ -1,8 +1,8 @@ /** * Angular Panorama - Mimic Windows Phone's Panorama UI control. - * @version v0.1.1 - 2013-12-28 + * @version v0.1.1 - 2013-12-30 * @link http://cnjsstong2.github.com/angular-panorama * @author Tong Shen * @license MIT License, http://www.opensource.org/licenses/MIT */ -angular.module("angular-panorama",["ngTouch"]),angular.module("angular-panorama").directive("ngPanoramaIndicators",[function(){return{restrict:"A",replace:!0,scope:{items:"=",index:"="},template:'
'}}]),angular.module("angular-panorama").directive("ngPanoramaInfinite",["$parse","$compile",function(a){return{restrict:"EA",transclude:!0,replace:!0,scope:!0,template:"",compile:function(b,c){var d=c.ngPanoramaCurrent+" in items";return b.children("li").attr("ng-repeat",d),function(b,c,d){b.items=[a(d.ngPanoramaCurrent)(b)],b.$watchCollection("panoramaCollection.position",function(c){a(d.ngPanoramaCurrent).assign(b.$parent,b.items[c])})}}}}]),angular.module("angular-panorama").directive("ngPanorama",["$compile","$parse","$swipe","$document","$window","CollectionManager",function(a,b,c,d,e,f){var g=0;return{restrict:"A",scope:!0,compile:function(h,i){h.addClass("ng-panorama-slides");for(var j,k=h.children("li"),l=0;l1){var b=h.panoramaCollection.getLastIndex(),c=h.panoramaCollection.position,e=D>E?1:-1,f=Math.min(Math.max(0,c+e),b),g=a.x-C;Math.abs(g)<=G*F&&(f=c);var i=c!==f;i?h.$apply(function(){angular.isDefined(j.ngPanoramaCycle)&&(h.panoramaCollection.position=f,w()),console.log(f),console.log(b);var a=f/b*100;J.css("background-position",a+"% 50%"),h.panoramaCollection.goTo(f,!0)}):h.$apply(function(){w()})}B=0}function y(a){var b=J[0].getBoundingClientRect(),c=a.x>b.left&&a.xb.top&&a.y"),J=I.parent();n&&(h.fakeArray=n),h.$watch("originalCollection");var K=b(m),L={},M=0;if(j.ngPanoramaIndex){var N=b(j.ngPanoramaIndex);angular.isFunction(N.assign)?(h.$watch("panoramaCollection.index",function(a){N.assign(h.$parent,a)}),M=N(h),h.$parent.$watch(N,function(a){void 0!==a&&h.panoramaCollection.goToIndex(a,!0)})):isNaN(j.ngPanoramaIndex)||(M=parseInt(j.ngPanoramaIndex,10))}angular.isDefined(j.ngPanoramaCycle)&&(L.cycle=!0),L.index=M,q&&(L.bufferSize=3,L.buffered=!0),h.panoramaCollection=f.create(L),h.$watch("panoramaCollection.updated",function(a){a&&w()});var O=!1;h.$watch(K,function(a){h.panoramaCollection.setItems(a,O),O=!0,0===G&&v(),w()}),angular.isDefined(j.ngPanoramaWatch)&&h.$watch(m,function(a){h.panoramaCollection.setItems(a,!1),O=!0,0===G&&v(),w()},!0);var P=["webkit","moz"];if(I[0].addEventListener("webkitTransitionEnd",l,!1),I[0].addEventListener("transitionend",l,!1),window.addEventListener("orientationchange",u),window.addEventListener("resize",u),angular.isDefined(j.ngPanoramaBackgroundImage)&&(J.css("background-image","url("+j.ngPanoramaBackgroundImage+")"),J.css("background-position","0% 50%")),h.$watch("iAttrs.ngPanoramaBackgroundImage",function(a){a&&(J.css("background-image","url("+a+")"),J.css("background-position","0% 50%"))}),angular.isDefined(j.ngPanoramaIndicator)){var Q=a("
")(h);J.append(Q)}var R=null,S=e.jasmine||"iPad"==e.navigator.platform?0:50;c.bind(I,{start:function(a){0===B&&(B=1,C=a.x),d.bind("mouseup",z)},move:function(a){if(!y(a))return x(a),void 0;if(0!==B){var b=a.x-C;if(1===B&&0!==b)B=2,D=E;else if(2===B){var c=(new Date).getTime();if(R&&S>c-R)return;R=c;var d=h.panoramaCollection.getLastIndex(),e=h.panoramaCollection.position,f=1;(0===e&&a.x>C||e===d&&a.x0?Math.max(0,(this.position-1)%this.length()):0;this.goTo(a)}},a.prototype.setBufferSize=function(a){this.log("setBufferSize",a),this.bufferSize=a,this.adjustBuffer()},a.prototype.isBuffered=function(){return this.buffered},a.prototype.getRelativeIndex=function(){var a=Math.max(0,Math.min(this.getLastIndex(),this.position-this.bufferStart));return a},a.prototype.adjustBuffer=function(){var a=(this.getLastIndex()+1-this.bufferSize)%this.length();this.log("maxBufferStart",a),this.bufferStart=Math.max(0,Math.min(a,this.position-1)),this.cards=this.items.slice(this.bufferStart,this.bufferStart+this.bufferSize),this.log("adjustBuffer from",this.bufferStart,"to",this.bufferStart+this.bufferSize)},a.prototype.length=function(){return this.items.length},a.prototype.getLastIndex=function(){var a=Math.max(0,this.length()-1);return a},a.prototype.init=function(){this.setBufferSize(this.isBuffered()?this.bufferSize:this.length()),this.length()>0&&this.goToIndex(this.index)},a.prototype.setItems=function(a,b){this.log("setItems",a,b),b&&(this.index=0,this.position=0),this.items=a||[],this.init()},a.prototype.cycleAtEnd=function(){this.push(this.items.shift())},a.prototype.push=function(a,b){this.log("push item(s)",a,b),this.items.push(a),b&&(this.adjustBuffer(),this.updated=new Date),this.buffered||this.bufferSize++},a.prototype.unshift=function(a,b){this.log("unshift item(s)",a,b),this.items.unshift(a),this.buffered||this.bufferSize++,b&&(this.position++,this.adjustBuffer(),this.updated=new Date)},a.prototype.cycleAtBeginning=function(){this.unshift(this.items.pop())},a.prototype.getOffsetWithWidth=function(a){if(this.items[0].width){var b=0,c=this.index;if(0==c)return 0;for(var d in this.cards.slice(0,a))b+=this.cards[d].width;return b-=c'}}]),angular.module("angular-panorama").directive("ngPanoramaInfinite",["$parse","$compile",function(a){return{restrict:"EA",transclude:!0,replace:!0,scope:!0,template:"
",compile:function(b,c){var d=c.ngPanoramaCurrent+" in items";return b.children("li").attr("ng-repeat",d),function(b,c,d){b.items=[a(d.ngPanoramaCurrent)(b)],b.$watchCollection("panoramaCollection.position",function(c){a(d.ngPanoramaCurrent).assign(b.$parent,b.items[c])})}}}}]),angular.module("angular-panorama").directive("ngPanorama",["$compile","$parse","$swipe","$document","$window","CollectionManager",function(a,b,c,d,e,f){var g=0;return{restrict:"A",scope:!0,compile:function(h,i){h.addClass("ng-panorama-slides");for(var j,k=h.children("li"),l=0;l1){var b=h.panoramaCollection.getLastIndex(),c=h.panoramaCollection.position,e=D>E?1:-1,f=Math.min(Math.max(0,c+e),b),g=a.x-C;Math.abs(g)<=G*F&&(f=c);var i=c!==f;i?h.$apply(function(){angular.isDefined(j.ngPanoramaCycle)&&(h.panoramaCollection.position=f,w()),console.log(f),console.log(b);var a=f/b*100;J.css("background-position",a+"% 50%"),h.panoramaCollection.goTo(f,!0)}):h.$apply(function(){w()})}B=0}function y(a){var b=J[0].getBoundingClientRect(),c=a.x>b.left&&a.xb.top&&a.y"),J=I.parent();n&&(h.fakeArray=n),h.$watch("originalCollection");var K=b(m),L={},M=0;if(j.ngPanoramaIndex){var N=b(j.ngPanoramaIndex);angular.isFunction(N.assign)?(h.$watch("panoramaCollection.index",function(a){N.assign(h.$parent,a)}),M=N(h),h.$parent.$watch(N,function(a){void 0!==a&&h.panoramaCollection.goToIndex(a,!0)})):isNaN(j.ngPanoramaIndex)||(M=parseInt(j.ngPanoramaIndex,10))}angular.isDefined(j.ngPanoramaCycle)&&(L.cycle=!0),L.index=M,q&&(L.bufferSize=3,L.buffered=!0),h.panoramaCollection=f.create(L),h.$watch("panoramaCollection.updated",function(a){a&&w()});var O=!1;h.$watch(K,function(a){h.panoramaCollection.setItems(a,O),O=!0,0===G&&v(),w()}),angular.isDefined(j.ngPanoramaWatch)&&h.$watch(m,function(a){h.panoramaCollection.setItems(a,!1),O=!0,0===G&&v(),w()},!0);var P=["webkit","moz"];if(I[0].addEventListener("webkitTransitionEnd",l,!1),I[0].addEventListener("transitionend",l,!1),window.addEventListener("orientationchange",u),window.addEventListener("resize",u),angular.isDefined(j.ngPanoramaBackgroundImage)&&(J.css("background-image","url("+j.ngPanoramaBackgroundImage+")"),J.css("background-position","0% 50%")),j.$observe("ngPanoramaBackgroundImage",function(a,b){console.log(h),console.log(b),console.log(a),a&&(console.log("changing.."),J.css("background-image","url("+a+")"),J.css("background-position",h.panoramaCollection.position/h.panoramaCollection.lastIndex*100+"% 50%"))}),angular.isDefined(j.ngPanoramaIndicator)){var Q=a("
")(h);J.append(Q)}var R=null,S=e.jasmine||"iPad"==e.navigator.platform?0:50;c.bind(I,{start:function(a){0===B&&(B=1,C=a.x),d.bind("mouseup",z)},move:function(a){if(!y(a))return x(a),void 0;if(0!==B){var b=a.x-C;if(1===B&&0!==b)B=2,D=E;else if(2===B){var c=(new Date).getTime();if(R&&S>c-R)return;R=c;var d=h.panoramaCollection.getLastIndex(),e=h.panoramaCollection.position,f=1;(0===e&&a.x>C||e===d&&a.x0?Math.max(0,(this.position-1)%this.length()):0;this.goTo(a)}},a.prototype.setBufferSize=function(a){this.log("setBufferSize",a),this.bufferSize=a,this.adjustBuffer()},a.prototype.isBuffered=function(){return this.buffered},a.prototype.getRelativeIndex=function(){var a=Math.max(0,Math.min(this.getLastIndex(),this.position-this.bufferStart));return a},a.prototype.adjustBuffer=function(){var a=(this.getLastIndex()+1-this.bufferSize)%this.length();this.log("maxBufferStart",a),this.bufferStart=Math.max(0,Math.min(a,this.position-1)),this.cards=this.items.slice(this.bufferStart,this.bufferStart+this.bufferSize),this.log("adjustBuffer from",this.bufferStart,"to",this.bufferStart+this.bufferSize)},a.prototype.length=function(){return this.items.length},a.prototype.getLastIndex=function(){var a=Math.max(0,this.length()-1);return a},a.prototype.init=function(){this.setBufferSize(this.isBuffered()?this.bufferSize:this.length()),this.length()>0&&this.goToIndex(this.index)},a.prototype.setItems=function(a,b){this.log("setItems",a,b),b&&(this.index=0,this.position=0),this.items=a||[],this.init()},a.prototype.cycleAtEnd=function(){this.push(this.items.shift())},a.prototype.push=function(a,b){this.log("push item(s)",a,b),this.items.push(a),b&&(this.adjustBuffer(),this.updated=new Date),this.buffered||this.bufferSize++},a.prototype.unshift=function(a,b){this.log("unshift item(s)",a,b),this.items.unshift(a),this.buffered||this.bufferSize++,b&&(this.position++,this.adjustBuffer(),this.updated=new Date)},a.prototype.cycleAtBeginning=function(){this.unshift(this.items.pop())},a.prototype.getOffsetWithWidth=function(a){if(this.items[0].width){var b=0,c=this.index;if(0==c)return 0;for(var d in this.cards.slice(0,a))b+=this.cards[d].width;return b-=c