2 * jQuery Mobile Widget @VERSION
4 * This software is licensed under the MIT licence (as defined by the OSI at
5 * http://www.opensource.org/licenses/mit-license.php)
7 * ***************************************************************************
8 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
9 * Copyright (C) 2011 by Intel Corporation Ltd.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
28 * ***************************************************************************
30 * Authors: Gabriel Schulhof <gabriel.schulhof@intel.com>
31 * Daehyeon Jung <darrenh.jung@samsung.com>
34 // Displays a simple two-state switch.
36 // To apply, add the attribute data-role="switch" to a <div>
37 // element inside a page. Alternatively, call switch()
38 // on an element, like this :
40 // $("#myswitch").toggleswitch();
41 // where the html might be :
42 // <div id="myswitch"></div>
45 // checked: Boolean; the state of the switch.(default: true)
46 // texton: String; "On";
47 // textoff: String; "Off";
48 // style: String; the style of toggleswitch (default: image)
51 // change: Emitted when the switch is changed.
55 The toggle switch widget shows a 2-state switch on the screen.
57 To add a toggle switch widget to the application, use the following code:
60 <div id="switch-1" data-role="toggleswitch" data-checked="false" data-textoff="Disabled"></div>
62 <div id="switch-2" data-role="toggleswitch" data-texton="Enabled"></div>
64 $("#switch-1").bind("changed", function(e, state)
71 @property {Boolean} data-checked
72 Sets the toggle switch state.
73 The default value is true.
76 @property {String} data-texton
77 Sets the label text value for the toggle switch 'on' state.
78 The default value is On.
81 @property {String} data-textoff
82 Sets the label text value for the toggle switch 'off' state.
83 The default value is Off.
87 The toggle switch can define a callback for the change event, which is fired when the toggle switch state is changed.
89 <div id="switch-1" data-role="toggleswitch"></div>
91 $("#switch-1").bind("change", function(e, state)
98 (function ( $, undefined ) {
100 $.widget( "tizen.toggleswitch", $.tizen.widgetex, {
106 initSelector : ":jqmData(role='toggleswitch')"
111 container: "#container",
118 destroy: function () {
119 this._ui.container.remove();
120 // restore original element
125 attr: "data-" + ($.mobile.ns || "") + "checked",
129 _setTexton: function ( text ) {
130 this._ui.on.text( text );
131 this.options.texton = text;
132 this.element.attr( "data-" + ($.mobile.ns || "") + "texton", text );
135 _setTextoff: function ( text ) {
136 this._ui.off.text( text );
137 this.options.textoff = text;
138 this.element.attr( "data-" + ($.mobile.ns || "") + "textoff", text );
141 _setChecked: function ( checked ) {
142 if ( checked == this.options.checked ) {
146 this.options.checked = checked;
147 this._setValue( checked );
149 this._ui.container.addClass("ui-toggleswitch-state-checked");
151 this._ui.container.removeClass("ui-toggleswitch-state-checked");
155 _setStyle: function ( style ) {
157 this.options.style = style;
161 _setDisabled: function ( value ) {
162 $.tizen.widgetex.prototype._setDisabled.call( this, value );
163 this._ui.container[value ? "addClass" : "removeClass"]( "ui-disabled" );
166 _create: function () {
168 this.element.hide().after( this._ui.container );
169 self._setStyle( this.element.jqmData("style") );
170 if ( this.options.style != "text" ) {
171 this._ui.container.addClass("ui-toggleswitch-image-style");
172 this._ui.container.find(".ui-toggleswitch-text").hide();
173 this._ui.container.find(".ui-toggleswitch-reed").hide();
174 this._ui.container.find(".ui-toggleswitch-img").show();
176 this._ui.container.find(".ui-toggleswitch-img").hide();
179 $( this._ui.mover ).bind( "vclick", function () {
180 self._setChecked( !self.options.checked );
187 $( document ).bind( "pagecreate create", function ( e ) {
188 $( $.tizen.toggleswitch.prototype.options.initSelector, e.target )
189 .not( ":jqmData(role='none'), :jqmData(role='nojs')" )