Skip to content

Instantly share code, notes, and snippets.

@e1senh0rn
Created March 5, 2012 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save e1senh0rn/1980508 to your computer and use it in GitHub Desktop.
Save e1senh0rn/1980508 to your computer and use it in GitHub Desktop.
AdminVacationSorter = function(selector) {
var selector = selector;
var sortable = null;
var options = {
axis: 'y',
containment: 'parent',
cursor: 'move',
update: update_handler,
helper: ui_helper
};
var initialize = function() {
sortable = $(selector).sortable(options).disableSelection();
};
var update_handler = function(event, ui) {
console.log(event);
console.log($(this));
};
var ui_helper = function(event, ui) {
ui.children().each(function() {
$(this).width($(this).width());
});
return ui;
};
initialize();
}
@viart
Copy link

viart commented Mar 5, 2012

App = {};
//...

App.Admin = {};
//...

App.Admin.Vacation = {};
//...

App.Admin.Vacation.Sorter = (function($) { 

  // defaults 
  var params = {
    sortable: {
      selector: '#default-selector',
      options: {
        axis: 'y', 
        containment: 'parent', 
        cursor: 'move',
        update: update_handler,
        helper: ui_helper
      }
    }
  };

  function initSortable()
  {
    var sortable = $(params.sortable.selector).sortable(params.sortable.options).disableSelection();
  }

  var update_handler = function(event, ui) 
  {
    console.log(event);
    console.log($(this));
  };

  var ui_helper = function(event, ui) 
  {
    ui.children().each(function() {
      var el = $(this); 
      el.width(el.width());
    });
    return ui;
  };

  var methods = {
    init: function(options)
    {
      // merge options
      $.extend(params, options, true);

      initSortable();
    }
  }

  return methods;
})(jQuery);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment