-
Notifications
You must be signed in to change notification settings - Fork 17
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
Added drag support for jQueryUI. #17
Changes from 2 commits
2db6386
1099ff0
a6e6917
a33a545
a10413a
89397b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"strict": true, | ||
"undef": true, | ||
"unused": true, | ||
"latedef": "nofunct", | ||
|
||
"eqnull": true, | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
columnWidth: '.packery-sizer', | ||
itemSelector: '.packery-object', | ||
rowHeight: '.packery-sizer', | ||
draggable: true, | ||
draggable: undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redundant. The config is for changing defaults, but undefined is already Packery's default as well as JS's default. It can be removed here. (Yes, you are getting this email again... I realized I commented in the dist file when I wanted to keep comments in the src one) |
||
handle: '*', | ||
timeout: 2000, | ||
acceptedAttributes: [ | ||
|
@@ -80,36 +80,92 @@ | |
var self = this; | ||
|
||
self.packeryInstantiated = false; | ||
self.packeryDraggable = false; | ||
self.dragHandle = undefined; | ||
self.packeryDraggable = undefined; | ||
self.dragHandle = '*'; | ||
self.uniqueId = new Date().getTime(); | ||
self.packery = {}; | ||
|
||
this.bindDragEvents = function(el) { | ||
var handleSelector, handle, draggabilly; | ||
var handleSelector, handle, draggableItem; | ||
|
||
handleSelector = self.dragHandle; | ||
|
||
if (handleSelector === '*') { | ||
draggabilly = new Draggabilly(el[0]); | ||
handle = el; | ||
} else { | ||
draggabilly = new Draggabilly(el[0], { | ||
handle: handleSelector | ||
}); | ||
handle = el[0].querySelectorAll(handleSelector); | ||
try { | ||
|
||
if ( self.packeryDraggable === 'draggabilly' ) { | ||
bindDraggabilly(); | ||
} else if ( self.packeryDraggable === 'jqueryui' ) { | ||
bindjQueryUI(); | ||
} else if ( self.packeryDraggable !== 'unsupported' ){ | ||
if( !bindDraggabilly(true) ){ | ||
bindjQueryUI(true); | ||
} | ||
} | ||
|
||
} catch(e) { | ||
if (window.console) { | ||
window.console.warn(e.name +' '+ e.message); | ||
} | ||
} | ||
|
||
// Init Draggabilly events | ||
self.packery.bindDraggabillyEvents(draggabilly); | ||
function bindDraggabilly (next) { | ||
next = ( typeof next === 'boolean' ) ? next : false; | ||
if (typeof window.Draggabilly !== 'undefined') { | ||
|
||
if (handleSelector === '*') { | ||
draggableItem = new window.Draggabilly(el[0]); | ||
handle = el; | ||
} else { | ||
draggableItem = new window.Draggabilly(el[0], { | ||
handle: handleSelector | ||
}); | ||
handle = el[0].querySelectorAll(handleSelector); | ||
} | ||
|
||
// Init Draggabilly events | ||
self.packery.bindDraggabillyEvents(draggableItem); | ||
animateEvents(); | ||
return true; | ||
} else if ( !next ) { | ||
throw { name: 'Warning: ', message: 'Draggabilly is undefined.' }; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
// Bind animate events for touch | ||
angular.element(handle).on('mouseenter', function(){ | ||
el.addClass('hovered'); | ||
}). | ||
on('mouseleave', function(){ | ||
el.removeClass('hovered'); | ||
}); | ||
function bindjQueryUI (next) { | ||
next = ( typeof next === 'boolean' ) ? next : false; | ||
if (typeof window.jQuery !== 'undefined' && typeof window.jQuery.ui !== 'undefined') { | ||
|
||
if (handleSelector === '*') { | ||
draggableItem = angular.element(el[0]).draggable(); | ||
handle = el; | ||
} else { | ||
draggableItem = angular.element(el[0]).draggable({ | ||
handle: handleSelector | ||
}); | ||
handle = el[0].querySelectorAll(handleSelector); | ||
} | ||
|
||
self.packery.bindUIDraggableEvents(draggableItem); | ||
animateEvents(); | ||
return true; | ||
} else if ( !next ) { | ||
throw { name: 'Warning: ', message: 'jQuery.ui is undefined.' }; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
function animateEvents () { | ||
// Bind animate events for touch | ||
angular.element(handle).on('mouseenter', function(){ | ||
el.addClass('hovered'); | ||
}). | ||
on('mouseleave', function(){ | ||
el.removeClass('hovered'); | ||
}); | ||
} | ||
}; | ||
|
||
this.createAttrObj = function (scope) { | ||
|
@@ -143,17 +199,14 @@ | |
self.packery.appended(el[0]); | ||
} | ||
|
||
if (self.packeryDraggable === true) { | ||
self.bindDragEvents(el); | ||
} | ||
|
||
self.bindDragEvents(el); | ||
el.css('visibility','visible'); | ||
$rootScope.$emit('packeryObjectPacked', el[0]); | ||
}); | ||
}; | ||
|
||
this.setDraggable = function (handle) { | ||
self.packeryDraggable = true; | ||
this.setDraggable = function (dragLib, handle) { | ||
self.packeryDraggable = dragLib; | ||
self.dragHandle = handle; | ||
}; | ||
}; | ||
|
@@ -178,7 +231,7 @@ | |
rowHeight: '@?', // Type: Number, Selector String | ||
transitionDuration: '@?', // Type: String | ||
|
||
draggable: '@?', // Type: Boolean | ||
draggable: '@?', // Type: String | ||
handle: '@?' // Type: Boolean | ||
|
||
// Let's come back to this one... | ||
|
@@ -205,7 +258,7 @@ | |
if (scope.isResizeBound === 'false') { scope.isResizeBound = false; } | ||
|
||
// Set global draggability | ||
if (scope.draggable) { controller.setDraggable(scope.handle); } | ||
scope.draggable = (scope.draggable) ? controller.setDraggable(scope.draggable, scope.handle) : angular.noop(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When would this evaluate to false? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I specifically meant |
||
|
||
// Create object for Packery instantiation | ||
packeryObj = controller.createAttrObj(scope); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this.
undefined
doesn't need to be explicitly set.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use
null
? I wanted to instantiate the variable in the parent scope because it will be first used/set in a child scope (setDraggable()
).I know it will naturally be 'undefined' but I wanted an explicitly set value to expect for debugging before and after its manipulation.