From 6b9efd55fed7586d118eae2c55be226e70306ac1 Mon Sep 17 00:00:00 2001 From: Mike Nikles Date: Wed, 22 Jan 2014 23:15:19 -0800 Subject: [PATCH 01/10] Fix to enable javascript minification. --- angular-flexslider.coffee | 3 ++- angular-flexslider.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/angular-flexslider.coffee b/angular-flexslider.coffee index 9edd0f8..a943143 100644 --- a/angular-flexslider.coffee +++ b/angular-flexslider.coffee @@ -1,7 +1,7 @@ 'use strict' angular.module('angular-flexslider', []) - .directive 'flexSlider', ($parse, $timeout) -> + .directive 'flexSlider', ['$parse', '$timeout', ($parse, $timeout) -> restrict: 'AE' scope: no replace: yes @@ -112,3 +112,4 @@ angular.module('angular-flexslider', []) # Running flexslider $timeout (-> flexsliderDiv.flexslider options), 0 + ] diff --git a/angular-flexslider.js b/angular-flexslider.js index e0adcad..50b6ff3 100644 --- a/angular-flexslider.js +++ b/angular-flexslider.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.6.2 (function() { - 'use strict'; angular.module('angular-flexslider', []).directive('flexSlider', function($parse, $timeout) { + 'use strict'; angular.module('angular-flexslider', []).directive('flexSlider', ['$parse', '$timeout', function($parse, $timeout) { return { restrict: 'AE', scope: false, @@ -172,6 +172,6 @@ }; } }; - }); + }]); }).call(this); From d64646e75cd8802f49198ae81284b180d760805e Mon Sep 17 00:00:00 2001 From: Nicola Peduzzi Date: Sun, 4 May 2014 11:17:27 +0200 Subject: [PATCH 02/10] Fix bug in slide collection removal (thanks @jmallison) Fix #17 --- angular-flexslider.coffee | 4 ++-- angular-flexslider.js | 4 ++-- bower.json | 30 ++++++++++++++---------------- examples/add-remove-slides.html | 15 ++++++++------- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/angular-flexslider.coffee b/angular-flexslider.coffee index a943143..1bf9af9 100644 --- a/angular-flexslider.coffee +++ b/angular-flexslider.coffee @@ -61,9 +61,9 @@ angular.module('angular-flexslider', []) collection ?= [] trackCollection = {} for c in collection - trackCollection[c] = getTrackFromItem c + trackCollection[getTrackFromItem(c)] = c # Generates arrays of collection items to add and remvoe - toAdd = (c for c in collection when not slidesItems[trackCollection[c]]?) + toAdd = (c for c in collection when not slidesItems[getTrackFromItem(c)]?) toRemove = (i.collectionItem for t, i of slidesItems when not trackCollection[t]?) # Workaround to a still unresolved problem in using flexslider.addSlide if (toAdd.length == 1 and toRemove.length == 0) or toAdd.length == 0 diff --git a/angular-flexslider.js b/angular-flexslider.js index 50b6ff3..788d541 100644 --- a/angular-flexslider.js +++ b/angular-flexslider.js @@ -75,7 +75,7 @@ trackCollection = {}; for (_i = 0, _len = collection.length; _i < _len; _i++) { c = collection[_i]; - trackCollection[c] = getTrackFromItem(c); + trackCollection[getTrackFromItem(c)] = c; } toAdd = (function() { var _j, _len1, _results; @@ -83,7 +83,7 @@ _results = []; for (_j = 0, _len1 = collection.length; _j < _len1; _j++) { c = collection[_j]; - if (slidesItems[trackCollection[c]] == null) { + if (slidesItems[getTrackFromItem(c)] == null) { _results.push(c); } } diff --git a/bower.json b/bower.json index 782db69..fe14d36 100644 --- a/bower.json +++ b/bower.json @@ -1,18 +1,16 @@ { - "name": "angular-flexslider", - "version": "1.2.4", - "main": "./angular-flexslider.js", - "dependencies": { - "angular": "~1.2.4", - "jquery": "2.0.2", - "flexslider": "latest" - }, - "readme": "angular-flexslider\n======================\n\nbower repo for angular-flexslider.js", - "readmeFilename": "README.md", - "_id": "angular-flexslider@1.2.4", - "description": "bower-angular-flexslider ======================", - "repository": { - "type": "git", - "url": "git://github.com/EnthusiasticCode/angular-flexslider.git" - } + "name": "angular-flexslider", + "version": "1.2.6", + "main": "./angular-flexslider.js", + "dependencies": { + "angular": "~1.2.16", + "jquery": "2.0.2", + "flexslider": "latest" + }, + "readmeFilename": "README.md", + "description": "AngularJS wrapper for Flexslider", + "repository": { + "type": "git", + "url": "git://github.com/EnthusiasticCode/angular-flexslider.git" + } } \ No newline at end of file diff --git a/examples/add-remove-slides.html b/examples/add-remove-slides.html index 0939184..710df32 100644 --- a/examples/add-remove-slides.html +++ b/examples/add-remove-slides.html @@ -12,10 +12,10 @@
  • - +
  • @@ -31,13 +31,14 @@ .controller('BasicSliderCtrl', function($scope) { $scope.slideshow = {}; $scope.slideshow.slides = [ - 'http://flexslider.woothemes.com/images/kitchen_adventurer_cheesecake_brownie.jpg', - 'http://flexslider.woothemes.com/images/kitchen_adventurer_lemon.jpg', - 'http://flexslider.woothemes.com/images/kitchen_adventurer_donut.jpg', - 'http://flexslider.woothemes.com/images/kitchen_adventurer_caramel.jpg' + { id: 1, url: 'http://flexslider.woothemes.com/images/kitchen_adventurer_cheesecake_brownie.jpg' }, + { id: 2, url: 'http://flexslider.woothemes.com/images/kitchen_adventurer_lemon.jpg' }, + { id: 3, url: 'http://flexslider.woothemes.com/images/kitchen_adventurer_donut.jpg' }, + { id: 4, url: 'http://flexslider.woothemes.com/images/kitchen_adventurer_caramel.jpg' } ]; + var nextId = 5; $scope.addRandomSlide = function () { - $scope.slideshow.slides.push('http://lorempixel.com/704/444/cats'); + $scope.slideshow.slides.push({ id: nextId++, url: 'http://lorempixel.com/704/444/cats' }); }; $scope.removeRandomSlide = function () { $scope.slideshow.slides.shift(); From 64bcf11cd986e65e21d4fba471554c094181d3a4 Mon Sep 17 00:00:00 2001 From: Nicola Peduzzi Date: Thu, 22 May 2014 10:04:36 +0200 Subject: [PATCH 03/10] Add `$slider` local to callbacks --- angular-flexslider.coffee | 4 +- angular-flexslider.js | 312 +++++++++++++++++++------------------- examples/callbacks.html | 5 +- 3 files changed, 163 insertions(+), 158 deletions(-) diff --git a/angular-flexslider.coffee b/angular-flexslider.coffee index 1bf9af9..bd2d0bf 100644 --- a/angular-flexslider.coffee +++ b/angular-flexslider.coffee @@ -106,10 +106,10 @@ angular.module('angular-flexslider', []) if attrKey in ['start', 'before', 'after', 'end', 'added', 'removed'] options[attrKey] = do (attrVal) -> f = $parse(attrVal) - -> $scope.$apply -> f($scope, {}) + (slider) -> $scope.$apply -> f($scope, { '$slider': slider }) continue options[attrKey] = attrVal # Running flexslider $timeout (-> flexsliderDiv.flexslider options), 0 - ] + ] diff --git a/angular-flexslider.js b/angular-flexslider.js index 788d541..bcff3a6 100644 --- a/angular-flexslider.js +++ b/angular-flexslider.js @@ -1,177 +1,181 @@ // Generated by CoffeeScript 1.6.2 (function() { - 'use strict'; angular.module('angular-flexslider', []).directive('flexSlider', ['$parse', '$timeout', function($parse, $timeout) { - return { - restrict: 'AE', - scope: false, - replace: true, - transclude: true, - template: '
    ', - compile: function(element, attr, linker) { - var collectionString, flexsliderDiv, indexString, match, slidesItems, trackBy; + 'use strict'; angular.module('angular-flexslider', []).directive('flexSlider', [ + '$parse', '$timeout', function($parse, $timeout) { + return { + restrict: 'AE', + scope: false, + replace: true, + transclude: true, + template: '
    ', + compile: function(element, attr, linker) { + var collectionString, flexsliderDiv, indexString, match, slidesItems, trackBy; - match = attr.slide.match(/^\s*(.+)\s+in\s+(.*?)(?:\s+track\s+by\s+(.+?))?\s*$/); - indexString = match[1]; - collectionString = match[2]; - trackBy = angular.isDefined(match[3]) ? $parse(match[3]) : $parse("" + indexString); - flexsliderDiv = null; - slidesItems = {}; - return function($scope, $element) { - var addSlide, getTrackFromItem, removeSlide; + match = attr.slide.match(/^\s*(.+)\s+in\s+(.*?)(?:\s+track\s+by\s+(.+?))?\s*$/); + indexString = match[1]; + collectionString = match[2]; + trackBy = angular.isDefined(match[3]) ? $parse(match[3]) : $parse("" + indexString); + flexsliderDiv = null; + slidesItems = {}; + return function($scope, $element) { + var addSlide, getTrackFromItem, removeSlide; - getTrackFromItem = function(collectionItem) { - var locals; + getTrackFromItem = function(collectionItem) { + var locals; - locals = {}; - locals[indexString] = collectionItem; - return trackBy($scope, locals); - }; - addSlide = function(collectionItem, index, callback) { - var childScope, track; - - track = getTrackFromItem(collectionItem); - if (slidesItems[track] != null) { - throw "Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys."; - } - childScope = $scope.$new(); - childScope[indexString] = collectionItem; - childScope['$index'] = index; - return linker(childScope, function(clone) { - var slideItem; + locals = {}; + locals[indexString] = collectionItem; + return trackBy($scope, locals); + }; + addSlide = function(collectionItem, index, callback) { + var childScope, track; - slideItem = { - collectionItem: collectionItem, - childScope: childScope, - element: clone - }; - slidesItems[track] = slideItem; - return typeof callback === "function" ? callback(slideItem) : void 0; - }); - }; - removeSlide = function(collectionItem) { - var slideItem, track; + track = getTrackFromItem(collectionItem); + if (slidesItems[track] != null) { + throw "Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys."; + } + childScope = $scope.$new(); + childScope[indexString] = collectionItem; + childScope['$index'] = index; + return linker(childScope, function(clone) { + var slideItem; - track = getTrackFromItem(collectionItem); - slideItem = slidesItems[track]; - if (slideItem == null) { - return; - } - delete slidesItems[track]; - slideItem.childScope.$destroy(); - return slideItem; - }; - return $scope.$watchCollection(collectionString, function(collection) { - var attrKey, attrVal, c, currentSlidesLength, e, i, idx, n, options, slider, slides, t, toAdd, toRemove, trackCollection, _i, _j, _k, _l, _len, _len1, _len2, _len3; + slideItem = { + collectionItem: collectionItem, + childScope: childScope, + element: clone + }; + slidesItems[track] = slideItem; + return typeof callback === "function" ? callback(slideItem) : void 0; + }); + }; + removeSlide = function(collectionItem) { + var slideItem, track; - if (!(collection != null ? collection.length : void 0)) { - return; - } - if (flexsliderDiv != null) { - slider = flexsliderDiv.data('flexslider'); - currentSlidesLength = Object.keys(slidesItems).length; - if (collection == null) { - collection = []; - } - trackCollection = {}; - for (_i = 0, _len = collection.length; _i < _len; _i++) { - c = collection[_i]; - trackCollection[getTrackFromItem(c)] = c; + track = getTrackFromItem(collectionItem); + slideItem = slidesItems[track]; + if (slideItem == null) { + return; } - toAdd = (function() { - var _j, _len1, _results; + delete slidesItems[track]; + slideItem.childScope.$destroy(); + return slideItem; + }; + return $scope.$watchCollection(collectionString, function(collection) { + var attrKey, attrVal, c, currentSlidesLength, e, i, idx, n, options, slider, slides, t, toAdd, toRemove, trackCollection, _i, _j, _k, _l, _len, _len1, _len2, _len3; - _results = []; - for (_j = 0, _len1 = collection.length; _j < _len1; _j++) { - c = collection[_j]; - if (slidesItems[getTrackFromItem(c)] == null) { - _results.push(c); - } + if (!(collection != null ? collection.length : void 0)) { + return; + } + if (flexsliderDiv != null) { + slider = flexsliderDiv.data('flexslider'); + currentSlidesLength = Object.keys(slidesItems).length; + if (collection == null) { + collection = []; } - return _results; - })(); - toRemove = (function() { - var _results; + trackCollection = {}; + for (_i = 0, _len = collection.length; _i < _len; _i++) { + c = collection[_i]; + trackCollection[getTrackFromItem(c)] = c; + } + toAdd = (function() { + var _j, _len1, _results; - _results = []; - for (t in slidesItems) { - i = slidesItems[t]; - if (trackCollection[t] == null) { - _results.push(i.collectionItem); + _results = []; + for (_j = 0, _len1 = collection.length; _j < _len1; _j++) { + c = collection[_j]; + if (slidesItems[getTrackFromItem(c)] == null) { + _results.push(c); + } } - } - return _results; - })(); - if ((toAdd.length === 1 && toRemove.length === 0) || toAdd.length === 0) { - for (_j = 0, _len1 = toRemove.length; _j < _len1; _j++) { - e = toRemove[_j]; - e = removeSlide(e); - slider.removeSlide(e.element); - } - for (_k = 0, _len2 = toAdd.length; _k < _len2; _k++) { - e = toAdd[_k]; - idx = collection.indexOf(e); - addSlide(e, idx, function(item) { - if (idx === currentSlidesLength) { - idx = void 0; + return _results; + })(); + toRemove = (function() { + var _results; + + _results = []; + for (t in slidesItems) { + i = slidesItems[t]; + if (trackCollection[t] == null) { + _results.push(i.collectionItem); } - return $scope.$evalAsync(function() { - return slider.addSlide(item.element, idx); + } + return _results; + })(); + if ((toAdd.length === 1 && toRemove.length === 0) || toAdd.length === 0) { + for (_j = 0, _len1 = toRemove.length; _j < _len1; _j++) { + e = toRemove[_j]; + e = removeSlide(e); + slider.removeSlide(e.element); + } + for (_k = 0, _len2 = toAdd.length; _k < _len2; _k++) { + e = toAdd[_k]; + idx = collection.indexOf(e); + addSlide(e, idx, function(item) { + if (idx === currentSlidesLength) { + idx = void 0; + } + return $scope.$evalAsync(function() { + return slider.addSlide(item.element, idx); + }); }); - }); + } + return; } - return; - } - } - slidesItems = {}; - if (flexsliderDiv != null) { - flexsliderDiv.remove(); - } - slides = angular.element('
      '); - flexsliderDiv = angular.element('
      '); - flexsliderDiv.append(slides); - $element.append(flexsliderDiv); - for (i = _l = 0, _len3 = collection.length; _l < _len3; i = ++_l) { - c = collection[i]; - addSlide(c, i, function(item) { - return slides.append(item.element); - }); - } - options = {}; - for (attrKey in attr) { - attrVal = attr[attrKey]; - if (attrKey.indexOf('$') === 0) { - continue; } - if (!isNaN(n = parseInt(attrVal))) { - options[attrKey] = n; - continue; + slidesItems = {}; + if (flexsliderDiv != null) { + flexsliderDiv.remove(); } - if (attrVal === 'false' || attrVal === 'true') { - options[attrKey] = attrVal === 'true'; - continue; + slides = angular.element('
        '); + flexsliderDiv = angular.element('
        '); + flexsliderDiv.append(slides); + $element.append(flexsliderDiv); + for (i = _l = 0, _len3 = collection.length; _l < _len3; i = ++_l) { + c = collection[i]; + addSlide(c, i, function(item) { + return slides.append(item.element); + }); } - if (attrKey === 'start' || attrKey === 'before' || attrKey === 'after' || attrKey === 'end' || attrKey === 'added' || attrKey === 'removed') { - options[attrKey] = (function(attrVal) { - var f; + options = {}; + for (attrKey in attr) { + attrVal = attr[attrKey]; + if (attrKey.indexOf('$') === 0) { + continue; + } + if (!isNaN(n = parseInt(attrVal))) { + options[attrKey] = n; + continue; + } + if (attrVal === 'false' || attrVal === 'true') { + options[attrKey] = attrVal === 'true'; + continue; + } + if (attrKey === 'start' || attrKey === 'before' || attrKey === 'after' || attrKey === 'end' || attrKey === 'added' || attrKey === 'removed') { + options[attrKey] = (function(attrVal) { + var f; - f = $parse(attrVal); - return function() { - return $scope.$apply(function() { - return f($scope, {}); - }); - }; - })(attrVal); - continue; + f = $parse(attrVal); + return function(slider) { + return $scope.$apply(function() { + return f($scope, { + '$slider': slider + }); + }); + }; + })(attrVal); + continue; + } + options[attrKey] = attrVal; } - options[attrKey] = attrVal; - } - return $timeout((function() { - return flexsliderDiv.flexslider(options); - }), 0); - }); - }; - } - }; - }]); + return $timeout((function() { + return flexsliderDiv.flexslider(options); + }), 0); + }); + }; + } + }; + } + ]); }).call(this); diff --git a/examples/callbacks.html b/examples/callbacks.html index d7e7bc1..544d93a 100644 --- a/examples/callbacks.html +++ b/examples/callbacks.html @@ -14,7 +14,7 @@ @@ -46,7 +46,8 @@ ]; var logId = 0; $scope.slideshow.log = [] - $scope.slideshow.start = function(){ + $scope.slideshow.start = function(slider){ + console.log(slider); $scope.slideshow.log.push({ id: ++logId, message: 'start' }); } $scope.slideshow.before = function(){ From cd3f671a81a78de2aebb71a530aadff4800efcf3 Mon Sep 17 00:00:00 2001 From: Nicola Peduzzi Date: Thu, 22 May 2014 10:06:00 +0200 Subject: [PATCH 04/10] Reflect repo ownership change --- bower.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index fe14d36..d023b02 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-flexslider", - "version": "1.2.6", + "version": "1.2.8", "main": "./angular-flexslider.js", "dependencies": { "angular": "~1.2.16", @@ -11,6 +11,6 @@ "description": "AngularJS wrapper for Flexslider", "repository": { "type": "git", - "url": "git://github.com/EnthusiasticCode/angular-flexslider.git" + "url": "git://github.com/thenikso/angular-flexslider.git" } } \ No newline at end of file From 54cc02f16f6153e9c3bffb6b1bb41c8c8cc26bcc Mon Sep 17 00:00:00 2001 From: Nicola Peduzzi Date: Tue, 24 Jun 2014 23:57:27 +0200 Subject: [PATCH 05/10] Fixes 'track by' adding the ability to track by `$index` variable. Fix #21 --- angular-flexslider.coffee | 22 +++++++++++----------- angular-flexslider.js | 32 ++++++++++++++++++-------------- examples/add-remove-slides.html | 15 +++++++-------- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/angular-flexslider.coffee b/angular-flexslider.coffee index bd2d0bf..070e7ff 100644 --- a/angular-flexslider.coffee +++ b/angular-flexslider.coffee @@ -17,14 +17,15 @@ angular.module('angular-flexslider', []) slidesItems = {} ($scope, $element) -> - getTrackFromItem = (collectionItem) -> + getTrackFromItem = (collectionItem, index) -> locals = {} locals[indexString] = collectionItem + locals['$index'] = index trackBy($scope, locals) addSlide = (collectionItem, index, callback) -> # Generating tracking element - track = getTrackFromItem collectionItem + track = getTrackFromItem collectionItem, index # See if it's unique if slidesItems[track]? throw "Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys." @@ -40,8 +41,8 @@ angular.module('angular-flexslider', []) slidesItems[track] = slideItem callback?(slideItem) - removeSlide = (collectionItem) -> - track = getTrackFromItem collectionItem + removeSlide = (collectionItem, index) -> + track = getTrackFromItem collectionItem, index slideItem = slidesItems[track] return unless slideItem? delete slidesItems[track] @@ -49,7 +50,6 @@ angular.module('angular-flexslider', []) slideItem $scope.$watchCollection collectionString, (collection) -> - # Early exit if no collection return unless collection?.length @@ -60,21 +60,21 @@ angular.module('angular-flexslider', []) # Get an associative array of track to collection item collection ?= [] trackCollection = {} - for c in collection - trackCollection[getTrackFromItem(c)] = c + for c, i in collection + trackCollection[getTrackFromItem(c, i)] = c # Generates arrays of collection items to add and remvoe - toAdd = (c for c in collection when not slidesItems[getTrackFromItem(c)]?) + toAdd = ({ value: c, index: i } for c, i in collection when not slidesItems[getTrackFromItem(c, i)]?) toRemove = (i.collectionItem for t, i of slidesItems when not trackCollection[t]?) # Workaround to a still unresolved problem in using flexslider.addSlide if (toAdd.length == 1 and toRemove.length == 0) or toAdd.length == 0 # Remove items for e in toRemove - e = removeSlide e + e = removeSlide e, collection.indexOf(e) slider.removeSlide e.element # Add items for e in toAdd - idx = collection.indexOf(e) - addSlide e, idx, (item) -> + idx = e.index + addSlide e.value, idx, (item) -> idx = undefined if idx == currentSlidesLength $scope.$evalAsync -> slider.addSlide(item.element, idx) diff --git a/angular-flexslider.js b/angular-flexslider.js index bcff3a6..518c246 100644 --- a/angular-flexslider.js +++ b/angular-flexslider.js @@ -20,17 +20,18 @@ return function($scope, $element) { var addSlide, getTrackFromItem, removeSlide; - getTrackFromItem = function(collectionItem) { + getTrackFromItem = function(collectionItem, index) { var locals; locals = {}; locals[indexString] = collectionItem; + locals['$index'] = index; return trackBy($scope, locals); }; addSlide = function(collectionItem, index, callback) { var childScope, track; - track = getTrackFromItem(collectionItem); + track = getTrackFromItem(collectionItem, index); if (slidesItems[track] != null) { throw "Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys."; } @@ -49,10 +50,10 @@ return typeof callback === "function" ? callback(slideItem) : void 0; }); }; - removeSlide = function(collectionItem) { + removeSlide = function(collectionItem, index) { var slideItem, track; - track = getTrackFromItem(collectionItem); + track = getTrackFromItem(collectionItem, index); slideItem = slidesItems[track]; if (slideItem == null) { return; @@ -74,18 +75,21 @@ collection = []; } trackCollection = {}; - for (_i = 0, _len = collection.length; _i < _len; _i++) { - c = collection[_i]; - trackCollection[getTrackFromItem(c)] = c; + for (i = _i = 0, _len = collection.length; _i < _len; i = ++_i) { + c = collection[i]; + trackCollection[getTrackFromItem(c, i)] = c; } toAdd = (function() { var _j, _len1, _results; _results = []; - for (_j = 0, _len1 = collection.length; _j < _len1; _j++) { - c = collection[_j]; - if (slidesItems[getTrackFromItem(c)] == null) { - _results.push(c); + for (i = _j = 0, _len1 = collection.length; _j < _len1; i = ++_j) { + c = collection[i]; + if (slidesItems[getTrackFromItem(c, i)] == null) { + _results.push({ + value: c, + index: i + }); } } return _results; @@ -105,13 +109,13 @@ if ((toAdd.length === 1 && toRemove.length === 0) || toAdd.length === 0) { for (_j = 0, _len1 = toRemove.length; _j < _len1; _j++) { e = toRemove[_j]; - e = removeSlide(e); + e = removeSlide(e, collection.indexOf(e)); slider.removeSlide(e.element); } for (_k = 0, _len2 = toAdd.length; _k < _len2; _k++) { e = toAdd[_k]; - idx = collection.indexOf(e); - addSlide(e, idx, function(item) { + idx = e.index; + addSlide(e.value, idx, function(item) { if (idx === currentSlidesLength) { idx = void 0; } diff --git a/examples/add-remove-slides.html b/examples/add-remove-slides.html index 710df32..f69db34 100644 --- a/examples/add-remove-slides.html +++ b/examples/add-remove-slides.html @@ -12,10 +12,10 @@
      • - +
      • @@ -31,14 +31,13 @@ .controller('BasicSliderCtrl', function($scope) { $scope.slideshow = {}; $scope.slideshow.slides = [ - { id: 1, url: 'http://flexslider.woothemes.com/images/kitchen_adventurer_cheesecake_brownie.jpg' }, - { id: 2, url: 'http://flexslider.woothemes.com/images/kitchen_adventurer_lemon.jpg' }, - { id: 3, url: 'http://flexslider.woothemes.com/images/kitchen_adventurer_donut.jpg' }, - { id: 4, url: 'http://flexslider.woothemes.com/images/kitchen_adventurer_caramel.jpg' } + 'http://flexslider.woothemes.com/images/kitchen_adventurer_cheesecake_brownie.jpg', + 'http://flexslider.woothemes.com/images/kitchen_adventurer_lemon.jpg', + 'http://flexslider.woothemes.com/images/kitchen_adventurer_donut.jpg', + 'http://flexslider.woothemes.com/images/kitchen_adventurer_caramel.jpg' ]; - var nextId = 5; $scope.addRandomSlide = function () { - $scope.slideshow.slides.push({ id: nextId++, url: 'http://lorempixel.com/704/444/cats' }); + $scope.slideshow.slides.push('http://lorempixel.com/704/444/cats'); }; $scope.removeRandomSlide = function () { $scope.slideshow.slides.shift(); From f51578f43d665b7677dbcbe4dcd8f7a6bef3fe80 Mon Sep 17 00:00:00 2001 From: Nicola Peduzzi Date: Wed, 25 Jun 2014 00:13:05 +0200 Subject: [PATCH 06/10] Fixes a bug that was showing only one slider when multiple were generated with an `ng-repeat`. Fix #20 --- angular-flexslider.coffee | 14 +++++----- angular-flexslider.js | 16 +++++------ examples/multiple-sliders.html | 51 ++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 examples/multiple-sliders.html diff --git a/angular-flexslider.coffee b/angular-flexslider.coffee index 070e7ff..b8f4964 100644 --- a/angular-flexslider.coffee +++ b/angular-flexslider.coffee @@ -8,15 +8,15 @@ angular.module('angular-flexslider', []) transclude: yes template: '
        ' compile: (element, attr, linker) -> - match = attr.slide.match /^\s*(.+)\s+in\s+(.*?)(?:\s+track\s+by\s+(.+?))?\s*$/ - indexString = match[1] - collectionString = match[2] - trackBy = if angular.isDefined(match[3]) then $parse(match[3]) else $parse("#{indexString}") + ($scope, $element) -> + match = attr.slide.match /^\s*(.+)\s+in\s+(.*?)(?:\s+track\s+by\s+(.+?))?\s*$/ + indexString = match[1] + collectionString = match[2] + trackBy = if angular.isDefined(match[3]) then $parse(match[3]) else $parse("#{indexString}") - flexsliderDiv = null - slidesItems = {} + flexsliderDiv = null + slidesItems = {} - ($scope, $element) -> getTrackFromItem = (collectionItem, index) -> locals = {} locals[indexString] = collectionItem diff --git a/angular-flexslider.js b/angular-flexslider.js index 518c246..42dc086 100644 --- a/angular-flexslider.js +++ b/angular-flexslider.js @@ -9,17 +9,15 @@ transclude: true, template: '
        ', compile: function(element, attr, linker) { - var collectionString, flexsliderDiv, indexString, match, slidesItems, trackBy; - - match = attr.slide.match(/^\s*(.+)\s+in\s+(.*?)(?:\s+track\s+by\s+(.+?))?\s*$/); - indexString = match[1]; - collectionString = match[2]; - trackBy = angular.isDefined(match[3]) ? $parse(match[3]) : $parse("" + indexString); - flexsliderDiv = null; - slidesItems = {}; return function($scope, $element) { - var addSlide, getTrackFromItem, removeSlide; + var addSlide, collectionString, flexsliderDiv, getTrackFromItem, indexString, match, removeSlide, slidesItems, trackBy; + match = attr.slide.match(/^\s*(.+)\s+in\s+(.*?)(?:\s+track\s+by\s+(.+?))?\s*$/); + indexString = match[1]; + collectionString = match[2]; + trackBy = angular.isDefined(match[3]) ? $parse(match[3]) : $parse("" + indexString); + flexsliderDiv = null; + slidesItems = {}; getTrackFromItem = function(collectionItem, index) { var locals; diff --git a/examples/multiple-sliders.html b/examples/multiple-sliders.html new file mode 100644 index 0000000..63513a3 --- /dev/null +++ b/examples/multiple-sliders.html @@ -0,0 +1,51 @@ + + + + + Angular FlexSlider Example - Multiple Sliders + + + + + + +
        + +
      • + +
      • +
        +
        + + + + + + + + + From 87338db5b1c5399df686e93f8ee78d499a3e7b82 Mon Sep 17 00:00:00 2001 From: Nicola Peduzzi Date: Wed, 25 Jun 2014 00:19:55 +0200 Subject: [PATCH 07/10] Bump version --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index d023b02..c0d090b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-flexslider", - "version": "1.2.8", + "version": "1.2.10", "main": "./angular-flexslider.js", "dependencies": { "angular": "~1.2.16", From 0b43a84d30f827b75b5f7ce0573ffa87e169d7e2 Mon Sep 17 00:00:00 2001 From: dsem Date: Fri, 27 Jun 2014 18:47:11 -0400 Subject: [PATCH 08/10] Small fix for missing character --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 802802d..f03a044 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ angular.module('myModule', ['angular-flexslider']); This module will define a single directive `flex-slider` that can be used either as an element or attribute. -Assuming a `mySlide` variable is present in the current scope, a FlexSlider instance +Assuming a `mySlides` variable is present in the current scope, a FlexSlider instance can be declared like so: ``` From c1331c7293a261f3f56bb06d82417204a3f29325 Mon Sep 17 00:00:00 2001 From: Ross Wilson Date: Fri, 8 Aug 2014 10:58:48 -0600 Subject: [PATCH 09/10] Fix for adding multiple slides --- angular-flexslider.coffee | 4 ++-- angular-flexslider.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/angular-flexslider.coffee b/angular-flexslider.coffee index b8f4964..7050f36 100644 --- a/angular-flexslider.coffee +++ b/angular-flexslider.coffee @@ -66,7 +66,7 @@ angular.module('angular-flexslider', []) toAdd = ({ value: c, index: i } for c, i in collection when not slidesItems[getTrackFromItem(c, i)]?) toRemove = (i.collectionItem for t, i of slidesItems when not trackCollection[t]?) # Workaround to a still unresolved problem in using flexslider.addSlide - if (toAdd.length == 1 and toRemove.length == 0) or toAdd.length == 0 + if (toAdd.length >= 1 and toRemove.length == 0) or toAdd.length == 0 # Remove items for e in toRemove e = removeSlide e, collection.indexOf(e) @@ -75,7 +75,7 @@ angular.module('angular-flexslider', []) for e in toAdd idx = e.index addSlide e.value, idx, (item) -> - idx = undefined if idx == currentSlidesLength + idx = undefined if idx >= currentSlidesLength $scope.$evalAsync -> slider.addSlide(item.element, idx) # Early exit diff --git a/angular-flexslider.js b/angular-flexslider.js index 42dc086..e8c6767 100644 --- a/angular-flexslider.js +++ b/angular-flexslider.js @@ -104,7 +104,7 @@ } return _results; })(); - if ((toAdd.length === 1 && toRemove.length === 0) || toAdd.length === 0) { + if ((toAdd.length >= 1 && toRemove.length === 0) || toAdd.length === 0) { for (_j = 0, _len1 = toRemove.length; _j < _len1; _j++) { e = toRemove[_j]; e = removeSlide(e, collection.indexOf(e)); @@ -114,7 +114,7 @@ e = toAdd[_k]; idx = e.index; addSlide(e.value, idx, function(item) { - if (idx === currentSlidesLength) { + if (idx >= currentSlidesLength) { idx = void 0; } return $scope.$evalAsync(function() { From 0da221de16685a2bd417204e4c0ff3ccac3e4018 Mon Sep 17 00:00:00 2001 From: Ross Wilson Date: Wed, 12 Aug 2015 15:13:43 -0600 Subject: [PATCH 10/10] compiling js from cs, cleanup merge --- angular-flexslider.js | 13 +++++-------- bower.json | 2 -- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/angular-flexslider.js b/angular-flexslider.js index a780845..0ef5899 100644 --- a/angular-flexslider.js +++ b/angular-flexslider.js @@ -56,17 +56,11 @@ slideItem.childScope.$destroy(); return slideItem; }; - return $scope.$watchCollection(collectionString, function(collection) { - var attrKey, attrVal, c, currentSlidesLength, e, i, idx, n, options, slider, slides, t, toAdd, toRemove, trackCollection, _i, _j, _k, _l, _len, _len1, _len2, _len3; - } - delete slidesItems[track]; - slideItem.childScope.$destroy(); - return slideItem; - }; return $scope.$watchCollection(collectionString, function(collection, oldCollection) { var attrKey, attrVal, c, currentSlidesLength, e, i, idx, n, options, slider, slides, t, toAdd, toRemove, trackCollection, _i, _j, _k, _l, _len, _len1, _len2, _len3; if (!((collection != null ? collection.length : void 0) || (oldCollection != null ? oldCollection.length : void 0))) { return; + } if (flexsliderDiv != null) { slider = flexsliderDiv.data('flexslider'); currentSlidesLength = Object.keys(slidesItems).length; @@ -107,7 +101,9 @@ for (_j = 0, _len1 = toRemove.length; _j < _len1; _j++) { e = toRemove[_j]; e = removeSlide(e, collection.indexOf(e)); - slider.removeSlide(e.element); + if (e) { + slider.removeSlide(e.element); + } } for (_k = 0, _len2 = toAdd.length; _k < _len2; _k++) { e = toAdd[_k]; @@ -176,6 +172,7 @@ } if (!options.sliderId && attr.id) { options.sliderId = "" + attr.id + "-slider"; + } if (options.sliderId) { flexsliderDiv.attr('id', options.sliderId); } diff --git a/bower.json b/bower.json index ac261f4..f10441b 100644 --- a/bower.json +++ b/bower.json @@ -3,8 +3,6 @@ "version": "1.3.2", "main": "./angular-flexslider.js", "dependencies": { - "angular": "~1.2.16", - "jquery": "2.0.2", "angular": "~1.3", "jquery": "~2", "flexslider": "latest"