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";
50 // change: Emitted when the switch is changed.
52 (function ( $, undefined ) {
54 $.widget( "tizen.toggleswitch", $.tizen.widgetex, {
59 initSelector : ":jqmData(role='toggleswitch')"
64 container: "#container",
71 destroy: function () {
72 this._ui.container.remove();
73 // restore original element
78 attr: "data-" + ($.mobile.ns || "") + "checked",
82 _setTexton: function ( text ) {
83 this._ui.on.text( text );
84 this.options.texton = text;
85 this.element.attr( "data-" + ($.mobile.ns || "") + "texton", text );
88 _setTextoff: function ( text ) {
89 this._ui.off.text( text );
90 this.options.textoff = text;
91 this.element.attr( "data-" + ($.mobile.ns || "") + "textoff", text );
94 _setChecked: function ( checked ) {
95 if ( checked == this.options.checked ) {
99 this.options.checked = checked;
100 this._setValue( checked );
102 this._ui.container.addClass("ui-toggleswitch-state-checked");
104 this._ui.container.removeClass("ui-toggleswitch-state-checked");
108 _setDisabled: function ( value ) {
109 $.tizen.widgetex.prototype._setDisabled.call( this, value );
110 this._ui.container[value ? "addClass" : "removeClass"]( "ui-disabled" );
113 _create: function () {
115 this.element.hide().after( this._ui.container );
116 if ( this.element.jqmData("icon") ) {
117 this._ui.container.find(".ui-toggleswitch-text").hide();
118 this._ui.container.find(".ui-toggleswitch-img").show();
120 this._ui.container.find(".ui-toggleswitch-img").hide();
123 $( this._ui.mover ).bind( "vclick", function () {
124 self._setChecked( !self.options.checked );
131 $( document ).bind( "pagecreate create", function ( e ) {
132 $( $.tizen.toggleswitch.prototype.options.initSelector, e.target )
133 .not( ":jqmData(role='none'), :jqmData(role='nojs')" )