[ImageRotation] add files required for SDK build
[samples/web/ImageRotation.git] / tizen-web-ui-fw / latest / js / src / widgets / forms / button.js
1 (function( $, undefined ) {
2
3 $.widget( "mobile.button", $.mobile.widget, {
4         options: {
5                 theme: null,
6                 icon: null,
7                 iconpos: null,
8                 corners: true,
9                 shadow: true,
10                 iconshadow: true,
11                 initSelector: "button, [type='button'], [type='submit'], [type='reset']"
12         },
13         _create: function() {
14                 var $el = this.element,
15                         $button,
16                         o = this.options,
17                         type,
18                         name,
19                         inline = o.inline ||  $.mobile.getAttrFixed( $el[0], "data-" + $.mobile.ns + "inline" ),
20                         mini = o.mini || $.mobile.getAttrFixed( $el[0], "data-" + $.mobile.ns + "mini" ),
21                         classes = "",
22                         $buttonPlaceholder;
23
24                 // if this is a link, check if it's been enhanced and, if not, use the right function
25                 if ( $el[ 0 ].tagName === "A" ) {
26                         if ( !$el.hasClass( "ui-btn" ) ) {
27                                 $el.buttonMarkup();
28                         }
29
30                         return;
31                 }
32
33                 // get the inherited theme
34                 // TODO centralize for all widgets
35                 if ( !this.options.theme ) {
36                         this.options.theme = $.mobile.getInheritedTheme( this.element, "c" );
37                 }
38
39                 // TODO: Post 1.1--once we have time to test thoroughly--any classes manually applied to the original element should be carried over to the enhanced element, with an `-enhanced` suffix. See https://github.com/jquery/jquery-mobile/issues/3577
40                 /* if ( $el[0].className.length ) {
41                         classes = $el[0].className;
42                 } */
43                 if ( !!~$el[0].className.indexOf( "ui-btn-left" ) ) {
44                         classes = "ui-btn-left";
45                 }
46
47                 if (  !!~$el[0].className.indexOf( "ui-btn-right" ) ) {
48                         classes = "ui-btn-right";
49                 }
50
51                 if (  $el.attr( "type" ) === "submit" || $el.attr( "type" ) === "reset" ) {
52                         classes ? classes += " ui-submit" :  classes = "ui-submit";
53                 }
54                 $( "label[for='" + $el.attr( "id" ) + "']" ).addClass( "ui-submit" );
55
56                 // Add ARIA role
57                 this.button = $( "<div></div>" )
58                         [ $el.html() ? "html" : "text" ]( $el.html() || $el.val() )
59                         .insertBefore( $el )
60                         .buttonMarkup({
61                                 theme: o.theme,
62                                 icon: o.icon,
63                                 iconpos: o.iconpos,
64                                 inline: inline,
65                                 corners: o.corners,
66                                 shadow: o.shadow,
67                                 iconshadow: o.iconshadow,
68                                 mini: mini
69                         })
70                         .addClass( classes )
71                         .append( $el.addClass( "ui-btn-hidden" ) );
72
73         $button = this.button;
74                 type = $el.attr( "type" );
75                 name = $el.attr( "name" );
76
77                 // Add hidden input during submit if input type="submit" has a name.
78                 if ( type !== "button" && type !== "reset" && name ) {
79                                 $el.bind( "vclick", function() {
80                                         // Add hidden input if it doesn't already exist.
81                                         if ( $buttonPlaceholder === undefined ) {
82                                                 $buttonPlaceholder = $( "<input>", {
83                                                         type: "hidden",
84                                                         name: $el.attr( "name" ),
85                                                         value: $el.attr( "value" )
86                                                 }).insertBefore( $el );
87
88                                                 // Bind to doc to remove after submit handling
89                                                 $.mobile.$document.one( "submit", function() {
90                                                         $buttonPlaceholder.remove();
91
92                                                         // reset the local var so that the hidden input
93                                                         // will be re-added on subsequent clicks
94                                                         $buttonPlaceholder = undefined;
95                                                 });
96                                         }
97                                 });
98                 }
99
100                 $el.bind({
101                         focus: function() {
102                                 $button.addClass( $.mobile.focusClass );
103                         },
104
105                         blur: function() {
106                                 $button.removeClass( $.mobile.focusClass );
107                         }
108                 });
109
110                 this.refresh();
111         },
112
113         enable: function() {
114                 this.element.attr( "disabled", false );
115                 this.button.removeClass( "ui-disabled" ).attr( "aria-disabled", false );
116                 return this._setOption( "disabled", false );
117         },
118
119         disable: function() {
120                 this.element.attr( "disabled", true );
121                 this.button.addClass( "ui-disabled" ).attr( "aria-disabled", true );
122                 return this._setOption( "disabled", true );
123         },
124
125         refresh: function() {
126                 var $el = this.element;
127
128                 if ( $el.prop("disabled") ) {
129                         this.disable();
130                 } else {
131                         this.enable();
132                 }
133
134                 // Grab the button's text element from its implementation-independent data item
135                 $( this.button.data( 'buttonElements' ).text )[ $el.html() ? "html" : "text" ]( $el.html() || $el.val() );
136         }
137 });
138
139 //auto self-init widgets
140 $.mobile.$document.bind( "pagecreate create", function( e ) {
141         $.mobile.button.prototype.enhanceWithin( e.target, true );
142 });
143
144 })( jQuery );