Export 0.2.3
[platform/framework/web/web-ui-fw.git] / libs / patch / 0021-JQM-add-tizen-toggle-switch.patch
1 From d91978cf6366c05780ed223264f65869387bc4a4 Mon Sep 17 00:00:00 2001
2 From: Jun Jinhyuk <jinhyuk.jun@samsung.com>
3 Date: Fri, 7 Dec 2012 10:33:32 +0900
4 Subject: [PATCH] JQM add tizen toggle switch
5
6 Change-Id: Iebd5611d298e67295edfe5ded449e11637be5425
7 ---
8  .../jquery-mobile-1.2.0/js/widgets/forms/slider.js |   44 +++++++++++++++-----
9  1 files changed, 33 insertions(+), 11 deletions(-)
10
11 diff --git a/libs/js/jquery-mobile-1.2.0/js/widgets/forms/slider.js b/libs/js/jquery-mobile-1.2.0/js/widgets/forms/slider.js
12 index e7f5df0..2e682db 100644
13 --- a/libs/js/jquery-mobile-1.2.0/js/widgets/forms/slider.js
14 +++ b/libs/js/jquery-mobile-1.2.0/js/widgets/forms/slider.js
15 @@ -81,6 +81,10 @@ $.widget( "mobile.slider", $.mobile.widget, {
16                 domHandle.className = 'ui-slider-handle';
17                 domSlider.appendChild( domHandle );
18  
19 +               if ( $( control ).find( "option" ).length && $( control ).find( "option" ).text() === "" ) {
20 +                       $( domSlider ).addClass( "ui-toggle-switch" );
21 +               }
22 +
23                 handle.buttonMarkup({ corners: true, theme: theme, shadow: true })
24                                 .attr({
25                                         "role": "slider",
26 @@ -324,7 +328,12 @@ $.widget( "mobile.slider", $.mobile.widget, {
27         },
28  
29         refresh: function( val, isfromControl, preventInputUpdate ) {
30 +               var imgToggle = false,
31 +                       appHandle;
32  
33 +               if ( $( this.handle ).parents().is( ".ui-toggle-switch" ) ) {
34 +                       imgToggle = true;
35 +               }
36                 // NOTE: we don't return here because we want to support programmatic
37                 //       alteration of the input value, which should still update the slider
38                 if ( this.options.disabled || this.element.attr('disabled')) {
39 @@ -397,20 +406,33 @@ $.widget( "mobile.slider", $.mobile.widget, {
40                                 title: cType === "input" ? newval : control.find( "option" ).eq( newval ).getEncodedText()
41                         });
42  
43 -               if ( this.valuebg ) {
44 -                       this.valuebg.css( "width", percent + "%" );
45 +               if ( !imgToggle ) {
46 +                       if ( this.valuebg ) {
47 +                               this.valuebg.css( "width", percent + "%" );
48 +                       }
49                 }
50  
51                 // drag the label widths
52 -               if ( this._labels ) {
53 -                       var handlePercent = this.handle.width() / this.slider.width() * 100,
54 -                               aPercent = percent && handlePercent + ( 100 - handlePercent ) * percent / 100,
55 -                               bPercent = percent === 100 ? 0 : Math.min( handlePercent + 100 - aPercent, 100 );
56 -
57 -                       this._labels.each(function() {
58 -                               var ab = $( this ).is( ".ui-slider-label-a" );
59 -                               $( this ).width( ( ab ? aPercent : bPercent  ) + "%" );
60 -                       });
61 +               if ( imgToggle ) {
62 +                       appHandle = $( this.handle ).parents( ".ui-slider" );
63 +                       if ( $( this.handle ).attr("aria-valuenow") === "on" ) {
64 +                               appHandle.children( "span.ui-slider-label-a" ).show();
65 +                               appHandle.children( "span.ui-slider-label-b" ).hide();
66 +                       } else {
67 +                               appHandle.children( "span.ui-slider-label-b" ).show();
68 +                               appHandle.children( "span.ui-slider-label-a" ).hide();
69 +                       }
70 +               } else {
71 +                       if ( this._labels ) {
72 +                               var handlePercent = this.handle.width() / this.slider.width() * 100,
73 +                                       aPercent = percent && handlePercent + ( 100 - handlePercent ) * percent / 100,
74 +                                       bPercent = percent === 100 ? 0 : Math.min( handlePercent + 100 - aPercent, 100 );
75 +
76 +                               this._labels.each(function() {
77 +                                       var ab = $( this ).is( ".ui-slider-label-a" );
78 +                                       $( this ).width( ( ab ? aPercent : bPercent  ) + "%" );
79 +                               });
80 +                       }
81                 }
82  
83                 if ( !preventInputUpdate ) {
84 -- 
85 1.7.4.1
86