Skip to content
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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"strict": true,
"undef": true,
"unused": true,
"latedef": "nofunct",

"eqnull": true,

Expand Down
112 changes: 83 additions & 29 deletions dist/packery.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
columnWidth: '.packery-sizer',
itemSelector: '.packery-object',
rowHeight: '.packery-sizer',
draggable: true,
draggable: undefined,
handle: '*',
timeout: 2000,
acceptedAttributes: [
Expand Down Expand Up @@ -87,36 +87,93 @@
var self = this;

self.packeryInstantiated = false;
self.packeryDraggable = false;
self.dragHandle = undefined;
self.packeryDraggable = undefined;
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

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.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);
}
}

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') {

// Bind animate events for touch
handle.on('mouseenter', function(){
el.addClass('hovered');
}).
on('mouseleave', function(){
el.removeClass('hovered');
});
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) {
Expand Down Expand Up @@ -150,17 +207,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;
};
};
Expand All @@ -185,7 +239,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...
Expand All @@ -212,7 +266,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();

// Create object for Packery instantiation
packeryObj = controller.createAttrObj(scope);
Expand Down
2 changes: 1 addition & 1 deletion dist/packery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

111 changes: 82 additions & 29 deletions src/packery.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
columnWidth: '.packery-sizer',
itemSelector: '.packery-object',
rowHeight: '.packery-sizer',
draggable: true,
draggable: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The 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: [
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
};
};
Expand All @@ -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...
Expand All @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would this evaluate to false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When draggable is not an attribute the packery-object I believe. Ill need to test that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically meant scope.draggable = (scope.draggable). Wouldn't that always be true?


// Create object for Packery instantiation
packeryObj = controller.createAttrObj(scope);
Expand Down