Export 0.1.61
[platform/framework/web/web-ui-fw.git] / src / widgets / a_colorwidget / js / colorwidget.js
1 ( function ( $, undefined ) {
2
3         $.widget( "todons.colorwidget", $.mobile.widget, {
4                 options: {
5                         color: "#ff0972"
6                 },
7
8                 _create: function () {
9                         $.extend ( this, {
10                                 isInput: this.element.is( "input" )
11                         } );
12
13                         /* "value", if present, takes precedence over "data-color" */
14                         if ( this.isInput ) {
15                                 if ( this.element.attr( "value" ).match(/#[0-9A-Fa-f]{6}/) ) {
16                                         this.element.attr( "data-color", this.element.attr( "value" ) );
17                                 }
18                         }
19
20                         $.mobile.todons.parseOptions( this, true );
21                 },
22
23                 _setOption: function ( key, value, unconditional ) {
24                         if ( undefined === unconditional ) {
25                                 unconditional = false;
26                         }
27
28                         if ( key === "color" ) {
29                                 this._setColor(value, unconditional);
30                         }
31                 },
32
33                 _setColor: function ( value, unconditional ) {
34                         if ( value.match(/#[0-9A-Fa-f]{6}/) && ( value != this.options.color || unconditional ) ) {
35                                 this.options.color = value;
36                                 this.element.attr( "data-color", value );
37
38                                 if ( this.isInput ) {
39                                         this.element.attr( "value", value );
40                                 }
41
42                                 this.element.triggerHandler( "colorchanged", value );
43                                 return true;
44                         }
45                         return false;
46                 }
47         } );
48
49 }( jQuery ) );