|
5 | 5 | var changed;
|
6 | 6 | var options_width;
|
7 | 7 |
|
8 |
| - jQuery.fn.toggle_select = function(options) { |
| 8 | + $.fn.toggle_select = function(options) { |
9 | 9 | // Extend out default options with those provided
|
10 |
| - opts = jQuery.extend({}, jQuery.fn.toggle_select.defaults, options); |
| 10 | + opts = $.extend({}, $.fn.toggle_select.defaults, options); |
11 | 11 | selects = this;
|
12 | 12 | options_width = parseInt(opts.width - opts.switch_width);
|
13 | 13 |
|
14 | 14 | // Iterate over each matched element
|
15 | 15 | selects.each(function( ) {
|
16 |
| - $this = jQuery(this); |
| 16 | + $this = $(this); |
17 | 17 |
|
18 | 18 | // Make sure the select has at least two options
|
19 | 19 | if ($this.children('option').length < 2)
|
|
41 | 41 | });
|
42 | 42 |
|
43 | 43 | // Setup events
|
44 |
| - jQuery(".toggle_switch .toggle_button").click(function() { |
| 44 | + $(".toggle_switch .toggle_button").click(function() { |
45 | 45 | // Don't toggle on the same mouseup as a user drag
|
46 | 46 | if(!changed)
|
47 |
| - toggle_switch(jQuery(this).parents(".toggle_switch")); |
| 47 | + toggle_switch($(this).parents(".toggle_switch")); |
48 | 48 | });
|
49 |
| - jQuery(".toggle_switch .toggle_button").mousedown(function() { |
| 49 | + $(".toggle_switch .toggle_button").mousedown(function() { |
50 | 50 | // Reset changed on every mousedown
|
51 | 51 | changed = false;
|
52 | 52 | })
|
53 | 53 |
|
54 | 54 | // Make center switch draggable
|
55 |
| - jQuery(".toggle_switch .switch").draggable({ axis:'x', handle: jQuery(this).find('.toggle_button'), |
| 55 | + $(".toggle_switch .switch").draggable({ axis:'x', handle: $(this).find('.toggle_button'), |
56 | 56 | start: function(e, ui) {
|
57 | 57 | // Called only when the mouse has started dragging, disable toggles
|
58 | 58 | changed = true;
|
|
69 | 69 | stop: function(e, ui) {
|
70 | 70 | // If the button is in the middle, move to one position or the other
|
71 | 71 | if (ui['position'].left > -options_width / 2)
|
72 |
| - switch_on(jQuery(this).parent()); |
| 72 | + switch_on($(this).parent()); |
73 | 73 | else
|
74 |
| - switch_off(jQuery(this).parent()); |
| 74 | + switch_off($(this).parent()); |
75 | 75 | }
|
76 | 76 | });
|
77 | 77 | };
|
78 | 78 |
|
79 | 79 | // Set default options for the toggle
|
80 |
| - jQuery.fn.toggle_select.defaults = { |
| 80 | + $.fn.toggle_select.defaults = { |
81 | 81 | width : 80, // Width of entire toggle
|
82 | 82 | height : 27, // Height of entire toggle
|
83 | 83 | switch_width : 39, // Width of the switch between the two options
|
|
98 | 98 | toggle_switch.children(".switch").animate({left: -options_width}, opts.speed);
|
99 | 99 | var target = toggle_switch.children("select.toggle");
|
100 | 100 | target.val(toggle_switch.find(".switch .toggle_off").attr('value'));
|
101 |
| - jQuery(target).change(); |
| 101 | + $(target).change(); |
102 | 102 | }
|
103 | 103 | function switch_on(toggle_switch) {
|
104 | 104 | toggle_switch.children(".switch").animate({left: '0px'}, opts.speed);
|
105 | 105 | var target = toggle_switch.children("select.toggle");
|
106 | 106 | target.val(toggle_switch.find(".switch .toggle_on").attr('value'));
|
107 |
| - jQuery(target).change(); |
| 107 | + $(target).change(); |
108 | 108 | }
|
109 | 109 | function is_on(toggle_switch) {
|
110 | 110 | return toggle_switch.children(".switch").css('left') == '0px';
|
|
0 commit comments