|
| 1 | +(function(root, factory) { |
| 2 | + if (typeof define === 'function' && define.amd) { |
| 3 | + define(['jquery'], factory); |
| 4 | + } else if (typeof exports === 'object') { |
| 5 | + module.exports = factory(require('jquery')); |
| 6 | + } else { |
| 7 | + root.sortable = factory(root.$); |
| 8 | + } |
| 9 | +}(this, function(jquery) { |
1 | 10 | /*
|
2 | 11 | * HTML5 Sortable jQuery Plugin
|
3 | 12 | * https://github.com/voidberg/html5sortable
|
|
9 | 18 | *
|
10 | 19 | * Released under the MIT license.
|
11 | 20 | */
|
12 |
| -(function($) { |
13 |
| - 'use strict'; |
14 |
| - |
15 | 21 | var dragging;
|
16 | 22 | var draggingHeight;
|
17 | 23 | var placeholders = $();
|
18 |
| - $.fn.sortable = function(options) { |
| 24 | + var sortable = function(options) { |
| 25 | + 'use strict'; |
19 | 26 | var method = String(options);
|
20 | 27 |
|
21 | 28 | options = $.extend({
|
22 | 29 | connectWith: false,
|
23 | 30 | placeholder: null,
|
24 |
| - dragImage: null |
| 31 | + dragImage: null, |
| 32 | + placeholderClass: 'sortable-placeholder', |
| 33 | + draggingClass: 'sortable-dragging' |
25 | 34 | }, options);
|
26 | 35 |
|
27 | 36 | return this.each(function() {
|
|
60 | 69 |
|
61 | 70 | var startParent;
|
62 | 71 | var newParent;
|
63 |
| - var placeholder = (options.placeholder === null) ? $('<' + (/^ul|ol$/i.test(this.tagName) ? 'li' : 'div') + ' class="sortable-placeholder"/>') : $(options.placeholder).addClass('sortable-placeholder'); |
| 72 | + var placeholder = (options.placeholder === null) ? $('<' + (/^ul|ol$/i.test(this.tagName) ? 'li' : 'div') + ' class="'+options.placeholderClass+'"/>') : $(options.placeholder).addClass(options.placeholderClass); |
64 | 73 |
|
65 | 74 | $(this).data('items', options.items);
|
66 | 75 | placeholders = placeholders.add(placeholder);
|
|
90 | 99 | dt.setDragImage(options.dragImage, 0, 0);
|
91 | 100 | }
|
92 | 101 |
|
93 |
| - index = (dragging = $(this)).addClass('sortable-dragging').attr('aria-grabbed', 'true').index(); |
| 102 | + index = (dragging = $(this)).addClass(options.draggingClass).attr('aria-grabbed', 'true').index(); |
94 | 103 | draggingHeight = dragging.height();
|
95 | 104 | startParent = $(this).parent();
|
96 | 105 | dragging.parent().triggerHandler('sortstart', {
|
|
101 | 110 | if (!dragging) {
|
102 | 111 | return;
|
103 | 112 | }
|
104 |
| - dragging.removeClass('sortable-dragging').attr('aria-grabbed', 'false').show(); |
| 113 | + dragging.removeClass(options.draggingClass).attr('aria-grabbed', 'false').show(); |
105 | 114 | placeholders.detach();
|
106 | 115 | newParent = $(this).parent();
|
107 | 116 | if (index !== dragging.index() || startParent.get(0) !== newParent.get(0)) {
|
|
156 | 165 | });
|
157 | 166 | });
|
158 | 167 | };
|
159 |
| -})(jQuery); |
| 168 | + |
| 169 | +$.fn.sortable = sortable; |
| 170 | + |
| 171 | +return sortable; |
| 172 | +})); |
0 commit comments