1 From 51799bf3c58cd972217fed6fb5453b7ca85cfb65 Mon Sep 17 00:00:00 2001
2 From: Koeun Choi <koeun.choi@samsung.com>
3 Date: Thu, 16 Feb 2012 16:37:08 +0900
4 Subject: [PATCH] JQM : Change button design to meet Tizen GUI, Button Event bug fixed
7 .../js/jquery.mobile.buttonMarkup.js | 164 +++++++++++++++-----
8 1 files changed, 123 insertions(+), 41 deletions(-)
10 diff --git a/libs/js/jquery-mobile-1.0.1pre/js/jquery.mobile.buttonMarkup.js b/libs/js/jquery-mobile-1.0.1pre/js/jquery.mobile.buttonMarkup.js
11 index a08e611..d676ad8 100644
12 --- a/libs/js/jquery-mobile-1.0.1pre/js/jquery.mobile.buttonMarkup.js
13 +++ b/libs/js/jquery-mobile-1.0.1pre/js/jquery.mobile.buttonMarkup.js
15 * "buttons" plugin - for making button-like links
19 + * Button Markup modified for TIZEN style.
24 + * data-style : circle, nobg, edit
29 + * <div data-role="button" data-inline="true" data-icon="send" data-style="circle"></div>
30 + * <div data-role="button" data-inline="true" data-icon="favorite" data-style="nobg">
31 + * <div data-role="button" data-inline="true" data-icon="editminus" data-style="edit"></div>
34 ( function( $, undefined ) {
36 $.fn.buttonMarkup = function( options ) {
37 @@ -13,6 +29,7 @@ $.fn.buttonMarkup = function( options ) {
38 o = $.extend( {}, $.fn.buttonMarkup.defaults, {
39 icon: options.icon !== undefined ? options.icon : el.jqmData( "icon" ),
40 iconpos: options.iconpos !== undefined ? options.iconpos : el.jqmData( "iconpos" ),
41 + style: el.jqmData( "style"), /* style : default : block. Added "circle", "edit" and "nobg" */
42 theme: options.theme !== undefined ? options.theme : el.jqmData( "theme" ),
43 inline: options.inline !== undefined ? options.inline : el.jqmData( "inline" ),
44 shadow: options.shadow !== undefined ? options.shadow : el.jqmData( "shadow" ),
45 @@ -30,8 +47,9 @@ $.fn.buttonMarkup = function( options ) {
46 buttonText = document.createElement( o.wrapperEls ),
47 buttonIcon = o.icon ? document.createElement( "span" ) : null;
49 - if ( attachEvents ) {
51 + // Bug fix for jQM : When moving finger out of button after touching down button, button color MUST be returned.
52 + if ( attachTIZENEvents ) {
53 + attachTIZENEvents();
56 // if not, try to find closest theme container
57 @@ -54,6 +72,10 @@ $.fn.buttonMarkup = function( options ) {
59 iconClass += " ui-icon-shadow";
62 + if ( $(el).text().length == 0 ) { /* No text */
63 + buttonClass += " ui-btn-icon_only";
68 @@ -73,8 +95,51 @@ $.fn.buttonMarkup = function( options ) {
69 buttonClass += " ui-shadow";
72 - e.setAttribute( "data-" + $.mobile.ns + "theme", o.theme );
73 - el.addClass( buttonClass );
74 + /* Set Button class for Icon BG */
75 + if ( o.style == "circle" ) { /* Circle BG Button. */
76 + /* style : no text, Icon only */
77 + buttonClass += " ui-btn-corner-circle";
78 + buttonClass += " ui-btn-icon_only";
80 + else if ( o.style == "nobg" ){
81 + /* style : no text, Icon only, no bg */
82 + buttonClass += " ui-btn-icon-nobg";
83 + buttonClass += " ui-btn-icon_only";
85 + else if ( o.style == "edit" ){ /* Contact Edit style */
86 + buttonClass += " ui-btn-edit";
89 + el.attr( "data-" + $.mobile.ns + "theme", o.theme )
90 + .addClass( buttonClass );
92 + /* Text Class for text positioning with icon. */
93 + textClass = "ui-btn-text";
96 + if ( $(el).text().length > 0 ) {
97 + ( o.iconpos == "right" ? textClass += " ui-btn-text-padding-right" : textClass += " ui-btn-text-padding-left" );
98 + innerClass += " ui-btn-hastxt";
101 + if ( o.style == "circle" ) { /* Circle BG Button. */
102 + /* style : no text, Icon only */
103 + innerClass += " ui-btn-corner-circle";
105 + else if ( o.style == "nobg" ) {
106 + /* style : no text, Icon only, no bg */
107 + innerClass += " ui-btn-icon-nobg";
110 + /* Icon Only : No padding on button-inner. */
111 + innerClass += " ui-btn-icon-only";
114 + else { /* Text Only */
115 + if ( $(el).text().length > 0 ) {
116 + innerClass += " ui-btn-hastxt";
120 buttonInner.className = innerClass;
121 buttonInner.setAttribute("aria-hidden", "true");
122 @@ -96,7 +161,7 @@ $.fn.buttonMarkup = function( options ) {
123 // TODO obviously it would be nice to pull this element out instead of
124 // retrieving it from the DOM again, but this change is much less obtrusive
125 // and 1.0 draws nigh
126 - $.data( e, 'textWrapper', $( buttonText ) );
127 + el.data( 'textWrapper', $( buttonText ) );
131 @@ -114,13 +179,7 @@ function closestEnabledButton( element ) {
135 - // Note that we check for typeof className below because the element we
136 - // handed could be in an SVG DOM where className on SVG elements is defined to
137 - // be of a different type (SVGAnimatedString). We only operate on HTML DOM
138 - // elements, so we look for plain "string".
140 - cname = ( typeof element.className === 'string' ) && element.className.split(' ');
142 + cname = element.className && element.className.split(' ');
143 if ( cname && $.inArray( "ui-btn", cname ) > -1 && $.inArray( "ui-disabled", cname ) < 0 ) {
146 @@ -130,51 +189,74 @@ function closestEnabledButton( element ) {
150 -var attachEvents = function() {
151 +// Attach tizen events...
152 +var selectedButton = null;
153 +var useScrollview = false;
154 +var attachTIZENEvents = function() {
155 $( document ).bind( {
156 - "vmousedown": function( event ) {
157 - var btn = closestEnabledButton( event.target ),
162 + // button click event comes this order : vmouseover -> vmousedown -> vmouseup -> vmouseout
163 + "vmouseover focus": function( event ) {
164 + // console.log( event.type );
166 + // check if there is selected button... if so, make it to "btn-up" state.
167 + if ( selectedButton ) {
168 + $btn = $( selectedButton );
169 theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
170 - $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
171 + $btn.removeClass( "ui-btn-down-" + theme ).removeClass( "ui-btn-hover-" + theme )
172 + .addClass( "ui-btn-up-" + theme );
175 - "vmousecancel vmouseup": function( event ) {
176 - var btn = closestEnabledButton( event.target ),
182 + selectedButton = closestEnabledButton( event.target );
183 + if ( selectedButton ) {
184 + $btn = $( selectedButton );
185 theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
186 - $btn.removeClass( "ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
187 + $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
190 - "vmouseover focus": function( event ) {
191 - var btn = closestEnabledButton( event.target ),
196 + "vmouseout blur": function( event ) {
197 + // console.log( event.type );
199 + if ( selectedButton ) {
200 + $btn = $( selectedButton );
201 theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
202 - $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
203 + $btn.removeClass( "ui-btn-hover-" + theme ).removeClass( "ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
206 - "vmouseout blur": function( event ) {
207 - var btn = closestEnabledButton( event.target ),
209 + "vmousedown": function( event ) {
214 + if ( !selectedButton ) {
215 + selectedButton = closestEnabledButton( event.target );
218 + $btn = $( selectedButton );
219 + theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
220 + $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
222 + "vmousecancel vmouseup": function( event ) {
223 + // console.log( event.type );
225 + if ( selectedButton ) {
226 + $btn = $( selectedButton );
227 theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
228 - $btn.removeClass( "ui-btn-hover-" + theme + " ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
229 + $btn.removeClass( "ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
231 + if ( event.type === "vmousecancel" && useScrollview ) {
232 + event.preventDefault();
234 + selectedButton = null;
237 + "scrollstart scrollview_scroll": function( event ) {
238 + // console.log( event.type );
239 + if ( event.type === "scrollview_scroll" )
240 + useScrollview = true;
241 + $(this).trigger("vmousecancel");
245 - attachEvents = null;
246 + attachTIZENEvents = null;
249 //links in bars, or those with data-role become buttons