-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angularjs support #11
Comments
Great feature! Merged! |
Hi @loup-brun , do you mind if I add you as collaborator? |
Sure - no problem ;) Happy to help! |
Let me know if the multiple directives sound confusing. Maybe there could be a better design, but in respect to the Angular scopes, I think this is a relatively robust architecture. |
Using multiple directives is ok to me. Below is how I use swipe in my angular project for several months ago: 'use strict'
###*
# @ngdoc directive
# @name vetServicesApp.directive:common/swipe
# @description
# # common/swipe
###
angular.module('vetServicesApp.directives')
.directive('swipe', [
'$timeout'
($timeout) ->
restrict: 'AE'
link: (scope, element, attrs) ->
initSwipe = () ->
if scope.mySwipe
scope.mySwipe.kill()
scope.mySwipe = null
scope.mySwipe = new Swipe(element[0],
startSlide: 0
speed: 400
auto: parseInt(attrs.auto)
draggable: true
autoRestart: false
continuous: true
disableScroll: false
stopPropagation: false
callback: (index, elem) ->
angular.element(".swipe-num li")
.removeClass("active")
.eq(index)
.addClass("active")
return
transitionEnd: (index, elem) ->
return
)
return
if attrs.usingNgRepeat
scope.$on 'Event:ng-repeat-finish-render', ->
$timeout(initSwipe, 100)
else
$timeout(initSwipe, 100)
scope.$on 'Event:ImagesLoaded', ->
$timeout ->
scope.mySwipe.setup()
, 100
return
]) There are two things may cause problems when using swipe in angular:
So, you can see that I use two additional directives for monitoring It is great If these two problems can be fixed with better solutions ^_^ |
I'll have to make some tests with Since wrapping the Swipe library in Angular brings some compromises, we might (just a quick thought, not yet a serious consideration) port the project to a different repository to better enable Angular support. |
This is a bit out of topic. But do you guys know of any wrapper for this slider in Angular 4? |
I've begun integrating Swipe into Angular.js. The integration works well so far and does not touch the original
swipe.js
file, but there are limitations in simply wrapping the library.There are 3 main directives:
swipe-wrap
: initializes the Swipe controller and thus will contain all the Swipe-related model/logic. Additional components (directives) may added within this wrapper, such as a counter or a controls directive;swipe-slider
: the actual slider;swipe-item
: a slide, which contains the client's html.The
swipe-wrap
must be a parent of theswipe-slider
, because the latter transcludes, thus creating a new, isolated scope that inherits from the$parent
scope. Therefore, in order for the model to propagate correctly, theswipe-wrap
must be parent of the slider.All the Swipe options are supported. However, since the original
swipe.js
is untouched, I must create a new callback function which includes$scope.$apply()
AND the client callback in order for every slide change to be added to the event loop. (otherwise, Angularjs doesn't know about the slide index when auto-playing the slider).My suggestion is to port Swipe to a different core file designed for Angular.js. However, the integration I made works - just include
angular.swipe.js
before your custom app, givenSwipe
is already loaded as a global on the page.Markup
Javascript
The text was updated successfully, but these errors were encountered: