Commit 626a29a5 authored by Neil Fraser's avatar Neil Fraser

Allow colour fields to set custom colours.

parent 272b9560
......@@ -49,12 +49,14 @@ handlers:
static_files: favicon.ico
upload: favicon\.ico
secure: always
expiration: "30d"
# Apple icon.
- url: /apple-touch-icon\.png
static_files: apple-touch-icon.png
upload: apple-touch-icon\.png
secure: always
expiration: "30d"
# robot.txt
- url: /robots\.txt
......
......@@ -1150,11 +1150,11 @@ Blockly.FieldCheckbox=function(a,b){Blockly.FieldCheckbox.superClass_.constructo
Blockly.FieldCheckbox.prototype.init=function(a){this.sourceBlock_||(Blockly.FieldCheckbox.superClass_.init.call(this,a),this.checkElement_=Blockly.createSvgElement("text",{"class":"blocklyText",x:-3},this.fieldGroup_),a=document.createTextNode("\u2713"),this.checkElement_.appendChild(a),this.checkElement_.style.display=this.state_?"block":"none")};Blockly.FieldCheckbox.prototype.getValue=function(){return String(this.state_).toUpperCase()};
Blockly.FieldCheckbox.prototype.setValue=function(a){a="TRUE"==a;this.state_!==a&&(this.state_=a,this.checkElement_&&(this.checkElement_.style.display=a?"block":"none"),this.sourceBlock_&&this.sourceBlock_.rendered&&this.sourceBlock_.workspace.fireChangeEvent())};Blockly.FieldCheckbox.prototype.showEditor_=function(){var a=!this.state_;if(this.sourceBlock_&&this.changeHandler_){var b=this.changeHandler_(a);void 0!==b&&(a=b)}null!==a&&this.setValue(String(a).toUpperCase())};
// Copyright 2012 Google Inc. Apache License 2.0
Blockly.FieldColour=function(a,b){Blockly.FieldColour.superClass_.constructor.call(this,"\u00a0\u00a0\u00a0");this.changeHandler_=b;this.setValue(a)};goog.inherits(Blockly.FieldColour,Blockly.Field);Blockly.FieldColour.prototype.init=function(a){Blockly.FieldColour.superClass_.init.call(this,a);this.borderRect_.style.fillOpacity=1;this.setValue(this.getValue())};Blockly.FieldColour.prototype.clone=function(){return new Blockly.FieldColour(this.getValue(),this.changeHandler_)};
Blockly.FieldColour=function(a,b){Blockly.FieldColour.superClass_.constructor.call(this,"\u00a0\u00a0\u00a0");this.changeHandler_=b;this.setValue(a);this.colours_=null;this.columns_=0};goog.inherits(Blockly.FieldColour,Blockly.Field);Blockly.FieldColour.prototype.init=function(a){Blockly.FieldColour.superClass_.init.call(this,a);this.borderRect_.style.fillOpacity=1;this.setValue(this.getValue())};Blockly.FieldColour.prototype.clone=function(){return new Blockly.FieldColour(this.getValue(),this.changeHandler_)};
Blockly.FieldColour.prototype.CURSOR="default";Blockly.FieldColour.prototype.dispose=function(){Blockly.WidgetDiv.hideIfOwner(this);Blockly.FieldColour.superClass_.dispose.call(this)};Blockly.FieldColour.prototype.getValue=function(){return this.colour_};Blockly.FieldColour.prototype.setValue=function(a){this.colour_=a;this.borderRect_&&(this.borderRect_.style.fill=a);this.sourceBlock_&&this.sourceBlock_.rendered&&(Blockly.Realtime.blockChanged(this.sourceBlock_),this.sourceBlock_.workspace.fireChangeEvent())};
Blockly.FieldColour.prototype.getText=function(){var a=this.colour_,b=a.match(/^#(.)\1(.)\2(.)\3$/);b&&(a="#"+b[1]+b[2]+b[3]);return a};Blockly.FieldColour.COLOURS=goog.ui.ColorPicker.SIMPLE_GRID_COLORS;Blockly.FieldColour.COLUMNS=7;
Blockly.FieldColour.prototype.showEditor_=function(){Blockly.WidgetDiv.show(this,Blockly.FieldColour.widgetDispose_);var a=new goog.ui.ColorPicker;a.setSize(Blockly.FieldColour.COLUMNS);a.setColors(Blockly.FieldColour.COLOURS);var b=goog.dom.getViewportSize(),c=goog.style.getViewportPageOffset(document),d=Blockly.getAbsoluteXY_(this.borderRect_),e=this.borderRect_.getBBox();a.render(Blockly.WidgetDiv.DIV);a.setSelectedColor(this.getValue());var f=goog.style.getSize(a.getElement());d.y=d.y+f.height+
e.height>=b.height+c.y?d.y-(f.height-1):d.y+(e.height-1);Blockly.RTL?(d.x+=e.width,d.x-=f.width,d.x<c.x&&(d.x=c.x)):d.x>b.width+c.x-f.width&&(d.x=b.width+c.x-f.width);Blockly.WidgetDiv.position(d.x,d.y,b,c);var g=this;Blockly.FieldColour.changeEventKey_=goog.events.listen(a,goog.ui.ColorPicker.EventType.CHANGE,function(a){a=a.target.getSelectedColor()||"#000000";Blockly.WidgetDiv.hide();if(g.sourceBlock_&&g.changeHandler_){var b=g.changeHandler_(a);void 0!==b&&(a=b)}null!==a&&g.setValue(a)})};
Blockly.FieldColour.prototype.getText=function(){var a=this.colour_,b=a.match(/^#(.)\1(.)\2(.)\3$/);b&&(a="#"+b[1]+b[2]+b[3]);return a};Blockly.FieldColour.COLOURS=goog.ui.ColorPicker.SIMPLE_GRID_COLORS;Blockly.FieldColour.COLUMNS=7;Blockly.FieldColour.prototype.setColours=function(a){this.colours_=a;return this};Blockly.FieldColour.prototype.setColumns=function(a){this.columns_=a;return this};
Blockly.FieldColour.prototype.showEditor_=function(){Blockly.WidgetDiv.show(this,Blockly.FieldColour.widgetDispose_);var a=new goog.ui.ColorPicker;a.setSize(this.columns_||Blockly.FieldColour.COLUMNS);a.setColors(this.colours_||Blockly.FieldColour.COLOURS);var b=goog.dom.getViewportSize(),c=goog.style.getViewportPageOffset(document),d=Blockly.getAbsoluteXY_(this.borderRect_),e=this.borderRect_.getBBox();a.render(Blockly.WidgetDiv.DIV);a.setSelectedColor(this.getValue());var f=goog.style.getSize(a.getElement());
d.y=d.y+f.height+e.height>=b.height+c.y?d.y-(f.height-1):d.y+(e.height-1);Blockly.RTL?(d.x+=e.width,d.x-=f.width,d.x<c.x&&(d.x=c.x)):d.x>b.width+c.x-f.width&&(d.x=b.width+c.x-f.width);Blockly.WidgetDiv.position(d.x,d.y,b,c);var g=this;Blockly.FieldColour.changeEventKey_=goog.events.listen(a,goog.ui.ColorPicker.EventType.CHANGE,function(a){a=a.target.getSelectedColor()||"#000000";Blockly.WidgetDiv.hide();if(g.sourceBlock_&&g.changeHandler_){var b=g.changeHandler_(a);void 0!==b&&(a=b)}null!==a&&g.setValue(a)})};
Blockly.FieldColour.widgetDispose_=function(){Blockly.FieldColour.changeEventKey_&&goog.events.unlistenByKey(Blockly.FieldColour.changeEventKey_)};
// Copyright 2012 Google Inc. Apache License 2.0
Blockly.FieldDropdown=function(a,b){this.menuGenerator_=a;this.changeHandler_=b;this.trimOptions_();var c=this.getOptions_()[0];this.value_=c[1];Blockly.FieldDropdown.superClass_.constructor.call(this,c[0])};goog.inherits(Blockly.FieldDropdown,Blockly.Field);Blockly.FieldDropdown.CHECKMARK_OVERHANG=25;Blockly.FieldDropdown.ARROW_CHAR=goog.userAgent.ANDROID?"\u25bc":"\u25be";Blockly.FieldDropdown.prototype.clone=function(){return new Blockly.FieldDropdown(this.menuGenerator_,this.changeHandler_)};
......
......@@ -50,6 +50,10 @@ Blockly.FieldColour = function(colour, opt_changeHandler) {
this.changeHandler_ = opt_changeHandler;
// Set the initial state.
this.setValue(colour);
// By default use the global constants for colours and columns.
this.colours_ = null;
this.columns_ = 0;
};
goog.inherits(Blockly.FieldColour, Blockly.Field);
......@@ -136,6 +140,28 @@ Blockly.FieldColour.COLOURS = goog.ui.ColorPicker.SIMPLE_GRID_COLORS;
*/
Blockly.FieldColour.COLUMNS = 7;
/**
* Set a custom colour grid for this field.
* @param {Array.<string>} colours Array of colours for this block,
* or null to use default (Blockly.FieldColour.COLOURS).
* @return {!Blockly.FieldColour} Returns itself (for method chaining).
*/
Blockly.FieldColour.prototype.setColours = function(colours) {
this.colours_ = colours;
return this;
};
/**
* Set a custom grid size for this field.
* @param {number} colours Number of columns for this block,
* or 0 to use default (Blockly.FieldColour.COLUMNS).
* @return {!Blockly.FieldColour} Returns itself (for method chaining).
*/
Blockly.FieldColour.prototype.setColumns = function(columns) {
this.columns_ = columns;
return this;
};
/**
* Create a palette under the colour field.
* @private
......@@ -144,8 +170,8 @@ Blockly.FieldColour.prototype.showEditor_ = function() {
Blockly.WidgetDiv.show(this, Blockly.FieldColour.widgetDispose_);
// Create the palette using Closure.
var picker = new goog.ui.ColorPicker();
picker.setSize(Blockly.FieldColour.COLUMNS);
picker.setColors(Blockly.FieldColour.COLOURS);
picker.setSize(this.columns_ || Blockly.FieldColour.COLUMNS);
picker.setColors(this.colours_ || Blockly.FieldColour.COLOURS);
// Position the palette to line up with the field.
// Record windowSize and scrollOffset before adding the palette.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment