diff --git a/editor/jgraduate/jquery.jgraduate.js b/editor/jgraduate/jquery.jgraduate.js index 4fe55203..653f1d5b 100644 --- a/editor/jgraduate/jquery.jgraduate.js +++ b/editor/jgraduate/jquery.jgraduate.js @@ -18,13 +18,18 @@ where options is an object literal: } - the Paint object is: - { - // object describing the color picked used by jPicker - solidColor: { hex, }, - // DOM node for the linear gradient - linearGradient: { grad, a, + Paint { + type: String, // one of "none", "solidColor", "linearGradient", "radialGradient" + alpha: Number representing opacity (0-100), + solidColor: String representing #RRGGBB hex of color, + linearGradient: object of interface SVGLinearGradientElement, } -- only one of solidColor and linearGradient must be non-null + +$.jGraduate.Paint() -> constructs a 'none' color +$.jGraduate.Paint({copy: o}) -> creates a copy of the paint o +$.jGraduate.Paint({hex: "#rrggbb"}) -> creates a solid color paint with hex = "#rrggbb" +$.jGraduate.Paint({linearGradient: o, a: 50}) -> creates a linear gradient paint with opacity=0.5 +$.jGraduate.Paint({hex: "#rrggbb", linearGradient: o}) -> throws an exception? - picker accepts the following object as input: { @@ -46,21 +51,44 @@ if(!window.console) { } $.jGraduate = { Paint: - function(copy) { - if (copy) { - if (copy.solidColor) - this.solidColor = new $.jPicker.Color({ hex: copy.solidColor.hex, - a: copy.solidColor.a }); - - // FIXME: linearGradient can be an object, but .grad can still be null - if (copy.linearGradient) - // Opera throws NOT_SUPPORTED_ERROR if the cloneNode(null), the other browsers do not - this.linearGradient = { grad: copy.linearGradient.grad ? document.cloneNode(copy.linearGradient.grad, true) : null, - a: copy.linearGradient.a }; + function(opt) { + var options = opt || {}; + this.alpha = options.alpha || 100; + // copy paint object + if (options.copy) { + this.type = options.copy.type; + this.alpha = options.copy.alpha; + switch(this.type) { + case "none": + this.solidColor = null; + this.linearGradient = null; + break; + case "solidColor": + this.solidColor = options.copy.solidColor; + this.linearGradient = null; + break; + case "linearGradient": + this.solidColor = null; + this.linearGradient = options.copy.linearGradient.cloneNode(true); + break; + } } + // create linear gradient paint + else if (options.linearGradient) { + this.type = "linearGradient"; + this.solidColor = null; + this.linearGradient = options.linearGradient.cloneNode(true); + } + // create solid color paint + else if (options.solidColor) { + this.type = "solidColor"; + this.solidColor = options.solidColor; + } + // create empty paint else { - this.solidColor = new $.jPicker.Color({ hex: '000000', a: 100 }); - this.linearGradient = { grad: null, a: 100 }; + this.type = "none"; + this.solidColor = null; + this.linearGradient = null; } } }; @@ -100,31 +128,19 @@ jQuery.fn.jGraduate = $.extend(true, $this, // public properties, methods, and callbacks { - paint: $settings.paint, + // make a copy of the incoming paint + paint: new $.jGraduate.Paint({copy: $settings.paint}), okCallback: $.isFunction($arguments[1]) && $arguments[1] || null, cancelCallback: $.isFunction($arguments[2]) && $arguments[2] || null, }); - var mode = "solidColor", - pos = $this.position(), + var pos = $this.position(), color = null; - - if ($this.paint == null) { - $this.paint = { solidColor: new $.jPicker.Color({ hex: 'ffffff', a: 100 }), - linearGradient: { grad: null, a: 100 } }; + + if ($this.paint.type == "none") { + $this.paint = $.jGraduate.Paint({solidColor: 'ffffff'}); } - if ($this.paint.linearGradient.grad != null) { - mode = "linearGradient"; - $this.paint.solidColor = new $.jPicker.Color({ hex: 'ffffff', a: 100 }); - } - else if ($this.paint.solidColor != null) { - $this.paint.linearGradient = { grad: null, a: 100 }; - } - else { - return null; - } - $this.addClass('jGraduate_Picker'); $this.html('