Skip to content

Instantly share code, notes, and snippets.

@Ptico
Forked from e1senh0rn/vacation_sorter.js
Created March 5, 2012 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ptico/1980867 to your computer and use it in GitHub Desktop.
Save Ptico/1980867 to your computer and use it in GitHub Desktop.
App = {};
// Another sandbox functions
/**
* Creates namespace in sandbox by string definition
* If part of namespace already defined - keep it untouchable,
* else - create empty object.
*
* App.namespace("Hello.World");
*
* @property {String} str Dot-separated namespace definition
*/
App.namespace = function(str) {
var pieces = str.split("."),
len = pieces.length,
i = 0,
root = this,
part;
while (i < len) {
part = pieces[i++];
root[part] = root[part] || {};
root = root[part];
}
return root;
};
/**
* @namespace Holds Vacation sorter plugin
*/
App.namespace("Admin.Vacation.Sorter");
/**
* Sorter for vacations
* Sort various shit with motherfucking vacations
*
* new App.Admin.Vacation.Sorter("#sortable");
*
* @class
* @property {jQuery} sortable Container for sortable element
*/
App.Admin.Vacation.Sorter = (function() {
/**
* Initializes sortable element
*
* @constructor
* @param {String} selector CSS-selector for root element
*/
function Sorter(selector) {
this.selector = selector;
this.sortable = $(selector).sortable(this.options).disableSelection();
}
Sorter.prototype = {
/**
* Default options for sorter
*
* @type Object
* @property {String} axis Sort axis
* @property {String} containment WTF?
* @property {String} cursor Cursor icon when under sortable
* @property {Function} update Handler for update event
* @property {Function} helper
*/
options: {
axis: 'y',
containment: 'parent',
cursor: 'move',
update: this.updateHandler,
helper: this.uiHelper
},
/**
* Handle `update` event
*
* @param {jQuery.Event} ev Event object
* @param {Object} ui UI object
*/
updateHandler: function(ev, ui) {
console.log(event);
console.log($(this));
},
/**
* Helper for ui
*
* @param {jQuery.Event} ev Event object
* @param {jQuery.UI} ui UI object
*/
uiHelper: function(ev, ui) {
ui.children().each(function() {
$(this).width($(this).width());
});
return ui;
}
};
return Sorter;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment