-
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 5 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, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,8 @@ | |
columnWidth: '.packery-sizer', | ||
itemSelector: '.packery-object', | ||
rowHeight: '.packery-sizer', | ||
draggable: true, | ||
handle: '*', | ||
draggable: undefined, | ||
handle: undefined, | ||
timeout: 2000, | ||
acceptedAttributes: [ | ||
'containerStyle', | ||
|
@@ -87,36 +87,94 @@ | |
var self = this; | ||
|
||
self.packeryInstantiated = false; | ||
self.packeryDraggable = false; | ||
self.packeryDraggable = 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. And this. 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. Could we use |
||
self.dragHandle = undefined; | ||
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.querySelectorAll(handleSelector); | ||
try { | ||
|
||
if( !self.packeryDraggable ) { | ||
if( !bindDraggabilly(true) ){ | ||
bindjQueryUI(true); | ||
} | ||
} else if ( self.packeryDraggable === 'draggabilly' ) { | ||
bindDraggabilly(); | ||
} else if ( self.packeryDraggable === 'jqueryui' ) { | ||
bindjQueryUI(); | ||
} else { | ||
window.console.error('ERROR: draggable=\''+ self.packeryDraggable +'\' is not a valid attribute.'); | ||
} | ||
|
||
} catch(e) { | ||
if (window.console) { | ||
window.console.warn(e.name +' '+ e.message); | ||
} | ||
} | ||
|
||
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; | ||
} | ||
} | ||
|
||
// Init Draggabilly events | ||
self.packery.bindDraggabillyEvents(draggabilly); | ||
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; | ||
} | ||
} | ||
|
||
// Bind animate events for touch | ||
handle.on('mouseenter', function(){ | ||
el.addClass('hovered'); | ||
}). | ||
on('mouseleave', function(){ | ||
el.removeClass('hovered'); | ||
}); | ||
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) { | ||
|
@@ -150,17 +208,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; | ||
}; | ||
}; | ||
|
@@ -185,7 +240,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... | ||
|
@@ -204,15 +259,16 @@ | |
|
||
// Quick fix so 'false' strings don't evaluate to true | ||
// @TODO: Check for attribute itself, not value of attribute | ||
if (scope.draggable === 'false') { scope.draggable = false; } | ||
if (scope.isHorizontal === 'false') { scope.isHorizontal = false; } | ||
if (scope.isInitLayout === 'false') { scope.isInitLayout = false; } | ||
if (scope.isOriginLeft === 'false') { scope.isOriginLeft = false; } | ||
if (scope.isOriginTop === 'false') { scope.isOriginTop = false; } | ||
if (scope.isResizeBound === 'false') { scope.isResizeBound = false; } | ||
|
||
// Set global draggability | ||
if (scope.draggable) { controller.setDraggable(scope.handle); } | ||
if (element[0].hasAttribute('draggable')) { | ||
controller.setDraggable(scope.draggable, scope.handle); | ||
} | ||
|
||
// Create object for Packery instantiation | ||
packeryObj = controller.createAttrObj(scope); | ||
|
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,8 +10,8 @@ | |
columnWidth: '.packery-sizer', | ||
itemSelector: '.packery-object', | ||
rowHeight: '.packery-sizer', | ||
draggable: true, | ||
handle: '*', | ||
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: undefined, | ||
timeout: 2000, | ||
acceptedAttributes: [ | ||
'containerStyle', | ||
|
@@ -80,36 +80,94 @@ | |
var self = this; | ||
|
||
self.packeryInstantiated = false; | ||
self.packeryDraggable = false; | ||
self.packeryDraggable = undefined; | ||
self.dragHandle = undefined; | ||
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 ) { | ||
if( !bindDraggabilly(true) ){ | ||
bindjQueryUI(true); | ||
} | ||
} else if ( self.packeryDraggable === 'draggabilly' ) { | ||
bindDraggabilly(); | ||
} else if ( self.packeryDraggable === 'jqueryui' ) { | ||
bindjQueryUI(); | ||
} else { | ||
window.console.error('ERROR: draggable=\''+ self.packeryDraggable +'\' is not a valid attribute.'); | ||
} | ||
|
||
} catch(e) { | ||
if (window.console) { | ||
window.console.warn(e.name +' '+ e.message); | ||
} | ||
} | ||
|
||
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; | ||
} | ||
} | ||
|
||
// Init Draggabilly events | ||
self.packery.bindDraggabillyEvents(draggabilly); | ||
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; | ||
} | ||
} | ||
|
||
// Bind animate events for touch | ||
angular.element(handle).on('mouseenter', function(){ | ||
el.addClass('hovered'); | ||
}). | ||
on('mouseleave', function(){ | ||
el.removeClass('hovered'); | ||
}); | ||
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 +201,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 +233,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... | ||
|
@@ -197,15 +252,16 @@ | |
|
||
// Quick fix so 'false' strings don't evaluate to true | ||
// @TODO: Check for attribute itself, not value of attribute | ||
if (scope.draggable === 'false') { scope.draggable = false; } | ||
if (scope.isHorizontal === 'false') { scope.isHorizontal = false; } | ||
if (scope.isInitLayout === 'false') { scope.isInitLayout = false; } | ||
if (scope.isOriginLeft === 'false') { scope.isOriginLeft = false; } | ||
if (scope.isOriginTop === 'false') { scope.isOriginTop = false; } | ||
if (scope.isResizeBound === 'false') { scope.isResizeBound = false; } | ||
|
||
// Set global draggability | ||
if (scope.draggable) { controller.setDraggable(scope.handle); } | ||
if (element[0].hasAttribute('draggable')) { | ||
controller.setDraggable(scope.draggable, scope.handle); | ||
} | ||
|
||
// 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.
Let's remove these before merge.
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.
Removing these declarations will create a need to revisit the link function in the packeryDirective.