Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

js now defined as jquery plugins

  • Loading branch information...
commit 5d0bbf6af475aca8cc1b6f3a8b1296cc201ccc60 1 parent 21537f2
@marcofucci marcofucci authored
View
8 inline_orderable/static/inline_orderable.js
@@ -8,13 +8,13 @@ function any(list, iterable) {
return false
}
-function updateOrdering(orderingManager) {
- $(orderingManager.inlineGroupSel).find(orderingManager.inlineItemsSel).each(function(i) {
+function updateOrdering(elements) {
+ $(elements).each(function(i) {
// checking that there's at least one input/textarea with value
// TODO check selects as well
- var $this = $(this),
+ var $this = $(this),
inputs = $this.find('input[type=text], textarea').not('input[id$=order]');
-
+
if (any(inputs, function(input) { return $(input).val() ? true : false })) {
$this.find('input[id$=order]').val(i+1);
} else {
View
43 inline_orderable/static/stackedinline_orderable.js
@@ -1,35 +1,38 @@
(function($) {
- var StackedInlineOrdering = {
- inlineGroupSel: 'div.inline-group',
- inlineItemsSel: 'div.inline-related',
-
- init: function() {
- var that = this;
- $(document).ready(function() {
- var inlineGroup = $(that.inlineGroupSel);
-
+ $.fn.stackedInlineOrder = function(options) {
+ var opts = $.extend({}, $.fn.stackedInlineOrder.defaults, options);
+
+ return this.each(function() {
+ var inlineGroup = $(this);
+
inlineGroup.sortable({
- items: that.inlineItemsSel,
+ items: opts.inlineItemsSel,
handle: 'h3:first',
update: function() {
- updateOrdering(that);
+ updateOrdering(inlineGroup.find(opts.inlineItemsSel));
}
});
-
+
// cursor move
- inlineGroup.find(that.inlineItemsSel).css('cursor', 'move');
-
+ inlineGroup.find(opts.inlineItemsSel).css('cursor', 'move');
+
// hiding stuff
- inlineGroup.find(that.inlineItemsSel).find('input[id$=order]').parents('div.order').hide();
-
+ inlineGroup.find(opts.inlineItemsSel).find('input[id$=order]').parents('div.order').hide();
+
// catching submit event
$('form').submit(function() {
- updateOrdering(that);
+ updateOrdering(inlineGroup.find(opts.inlineItemsSel));
});
});
- }
- }
+ };
- StackedInlineOrdering.init();
+ $.fn.stackedInlineOrder.defaults = {
+ 'inlineItemsSel': 'div.inline-related'
+ };
+
+
+ $(document).ready(function() {
+ $('div.inline-group').stackedInlineOrder();
+ });
})($ || django.jQuery);
View
32 inline_orderable/static/tabularinline_orderable.js
@@ -1,23 +1,20 @@
(function($) {
- var TabularInlineOrdering = {
- inlineGroupSel: 'div.inline-group',
- inlineItemsSel: 'tbody tr',
-
- init: function() {
- var that = this;
- $(document).ready(function() {
- var inlineGroup = $(that.inlineGroupSel);
+ $.fn.tabularInlineOrder = function(options) {
+ var opts = $.extend({}, $.fn.tabularInlineOrder.defaults, options);
+
+ return this.each(function() {
+ var inlineGroup = $(this);
inlineGroup.sortable({
- items: that.inlineItemsSel,
+ items: opts.inlineItemsSel,
handle: 'td',
update: function() {
- updateOrdering(that);
+ updateOrdering(inlineGroup.find(opts.inlineItemsSel));
}
});
// cursor move
- inlineGroup.find(that.inlineItemsSel).css('cursor', 'move');
+ inlineGroup.find(opts.inlineItemsSel).css('cursor', 'move');
// finding header of order
var orderHeaderIndex = inlineGroup.find('td.order:first').index()-1,
@@ -35,12 +32,17 @@
// catching submit event
$('form').submit(function() {
- updateOrdering(that);
+ updateOrdering(inlineGroup.find(opts.inlineItemsSel));
});
});
- }
- }
+ };
+
+ $.fn.tabularInlineOrder.defaults = {
+ 'inlineItemsSel': 'tbody tr'
+ };
- TabularInlineOrdering.init();
+ $(document).ready(function() {
+ $('div.inline-group').tabularInlineOrder();
+ });
})($ || django.jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.