Remoto - VFS: colorWidget.js Source File
Remoto - VFS
colorWidget.js
Go to the documentation of this file.
1 
2 define( [
3  'remoto!stdlib:js/widgets/widget.js',
4  //'include/modal/chooseColor4f/jscolor4f',
5  'remoto!stdlib:js/modal/chooseColor/jscolor.js',
6  'remoto!stdlib:js/include/utils.js',
7  'remoto!stdlib:js/include/color.js',
8  ],
9  function(widget,jscolor,utils,color)
10  {
11  'use strict';
12 
33  colorWidget.prototype = new widget;
34  function colorWidget( d )
35  {
36  this._color = null;
37  this._colorJq = null;
38 
39  var value = d.value;
40 
41  if (!value || value.toString().startsWith("RANDOM"))
42  { //d.value = color.randomHSV().html;
43  var THIS = this;
44  setTimeout( function() {
45  THIS.value = color.randomHSV().html;
46  //THIS.value = d.value //trigger an update
47  }, 0 );
48  }
49 
50  widget.call( this, d );
51  }
52 
62  colorWidget.prototype.createWidget = function()
63  {
64  if (this._colorJq) return this._colorJq;
65 
66  widget.prototype.createWidget.call(this);
67 
68  this._widgetJq.hide();
69 
70  this._colorJq = $("<div class='widgetInputField' id='"+this._id+"_color' style='height:18px; border:var(--Border1); margin-bottom:2px; box-sizing:border-box; font-size:11px; line-height:18px; min-width:28px;' tabindex='-1' type='text'>&nbsp;</div>");
71 
72  if (this._options.class)
73  this._colorJq.addClass(this._options.class);
74 
75  return this._colorJq;
76  }
77 
86  colorWidget.prototype.activate = function()
87  {
88  widget.prototype.activate.call(this);
89 
90  this._colorJq.css("cursor","pointer");
91 
92  var ops = {
93  valueElement: this._widgetJq[0],
94  styleElement: this._colorJq[0],
95  pickerFace: 5,
96  }
97 
98  this._color = new jscolor.color(this._colorJq[0],ops);
99  }
100 
111  // same as base class
112  colorWidget.prototype.sync = function()
113  {
114  var v = this._widgetJq ? this._widgetJq.val() : null;
115 
116  //this.value = utils.hexDec(v);
117  this.value = v;
118  }
119 
128  colorWidget.prototype.deactivate = function()
129  {
130  widget.prototype.deactivate.call(this);
131 
132  if (this._color)
133  this._color.hidePicker();
134  this._color = null;
135  }
136 
148  colorWidget.prototype.__defineSetter__("value", function(v)
149  {
150  widget.prototype.__lookupSetter__("value").call(this,v);
151 
152  //v = utils.decHex(v);
153 
154  this._widgetJq.val(this._value);
155 
156  this._color.importColor();
157 
158  return this._value;
159  });
160 
167  colorWidget.prototype.__defineGetter__("value", function()
168  {
169  return widget.prototype.__lookupGetter__("value").call(this);
170  } );
171 
178  colorWidget.prototype.__defineGetter__("visibleWidget", function()
179  {
180  return this._colorJq;
181  });
182 
185  return colorWidget;
186  }
187 );
188 
Javascript color object class.
getter html
Get the html color representation of this object.
randomHSV(huecenter, huerange, sat, val)
Create a random HSV color based on a hue range and saturation and value.
A form widget for selecting an RGB color.
setter value
a setter DOCME
setter widget
a setter DOCME
Utility functions for javascript clients.
Base class for GUI form widgets.
deactivate()
Deactivate the widget, which will unbind input events from their callbacks.
activate()
Activate the widget, which will cause changes to propagate to the form, and therefore the submit() me...
createWidget()
Create the widget jQuery object.