2018-05-13 10:47:00 +00:00
|
|
|
/* eslint-disable no-var, no-redeclare */
|
|
|
|
/* globals $, jQuery */
|
|
|
|
/*
|
2010-11-05 16:15:56 +00:00
|
|
|
* jGraduate 0.4
|
2009-07-30 22:45:59 +00:00
|
|
|
*
|
|
|
|
* jQuery Plugin for a gradient picker
|
|
|
|
*
|
2010-03-10 18:17:48 +00:00
|
|
|
* Copyright (c) 2010 Jeff Schiller
|
2009-07-30 22:45:59 +00:00
|
|
|
* http://blog.codedread.com/
|
2010-03-10 18:17:48 +00:00
|
|
|
* Copyright (c) 2010 Alexis Deveria
|
|
|
|
* http://a.deveria.com/
|
2009-07-30 22:45:59 +00:00
|
|
|
*
|
|
|
|
* Apache 2 License
|
|
|
|
|
|
|
|
jGraduate( options, okCallback, cancelCallback )
|
|
|
|
|
|
|
|
where options is an object literal:
|
|
|
|
{
|
|
|
|
window: { title: "Pick the start color and opacity for the gradient" },
|
|
|
|
images: { clientPath: "images/" },
|
2011-01-07 17:35:05 +00:00
|
|
|
paint: a Paint object,
|
2018-05-13 10:47:00 +00:00
|
|
|
newstop: String of value "same", "inverse", "black" or "white"
|
2011-01-07 17:35:05 +00:00
|
|
|
OR object with one or both values {color: #Hex color, opac: number 0-1}
|
2009-07-30 22:45:59 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2009-07-30 22:45:59 +00:00
|
|
|
- the Paint object is:
|
2009-08-01 05:03:51 +00:00
|
|
|
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,
|
2010-03-10 18:17:48 +00:00
|
|
|
radialGradient: object of interface SVGRadialGradientElement,
|
2009-07-30 22:45:59 +00:00
|
|
|
}
|
2009-08-01 05:03:51 +00:00
|
|
|
|
|
|
|
$.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
|
2010-03-10 18:17:48 +00:00
|
|
|
$.jGraduate.Paint({radialGradient: o, a: 7}) -> creates a radial gradient paint with opacity=0.07
|
2009-08-01 05:03:51 +00:00
|
|
|
$.jGraduate.Paint({hex: "#rrggbb", linearGradient: o}) -> throws an exception?
|
2009-07-30 22:45:59 +00:00
|
|
|
|
|
|
|
- picker accepts the following object as input:
|
|
|
|
{
|
|
|
|
okCallback: function to call when Ok is pressed
|
|
|
|
cancelCallback: function to call when Cancel is pressed
|
|
|
|
paint: object describing the paint to display initially, if not set, then default to opaque white
|
|
|
|
}
|
|
|
|
|
|
|
|
- okCallback receives a Paint object
|
|
|
|
|
|
|
|
*
|
2018-05-13 10:47:00 +00:00
|
|
|
*/
|
|
|
|
(function () {
|
2009-07-30 22:45:59 +00:00
|
|
|
var ns = { svg: 'http://www.w3.org/2000/svg', xlink: 'http://www.w3.org/1999/xlink' };
|
2018-05-13 10:47:00 +00:00
|
|
|
if (!window.console) {
|
|
|
|
window.console = new function () {
|
|
|
|
this.log = function (str) {};
|
|
|
|
this.dir = function (str) {};
|
|
|
|
}();
|
2009-07-30 22:45:59 +00:00
|
|
|
}
|
2009-11-13 20:45:18 +00:00
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
$.jGraduate = {
|
2009-07-30 22:45:59 +00:00
|
|
|
Paint:
|
2018-05-13 10:47:00 +00:00
|
|
|
function (opt) {
|
2009-08-01 05:03:51 +00:00
|
|
|
var options = opt || {};
|
2010-10-14 17:35:34 +00:00
|
|
|
this.alpha = isNaN(options.alpha) ? 100 : options.alpha;
|
2009-08-01 05:03:51 +00:00
|
|
|
// copy paint object
|
2018-05-13 10:47:00 +00:00
|
|
|
if (options.copy) {
|
|
|
|
this.type = options.copy.type;
|
|
|
|
this.alpha = options.copy.alpha;
|
2010-03-10 18:17:48 +00:00
|
|
|
this.solidColor = null;
|
|
|
|
this.linearGradient = null;
|
|
|
|
this.radialGradient = null;
|
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
switch (this.type) {
|
|
|
|
case 'none':
|
|
|
|
break;
|
|
|
|
case 'solidColor':
|
|
|
|
this.solidColor = options.copy.solidColor;
|
|
|
|
break;
|
|
|
|
case 'linearGradient':
|
|
|
|
this.linearGradient = options.copy.linearGradient.cloneNode(true);
|
|
|
|
break;
|
|
|
|
case 'radialGradient':
|
|
|
|
this.radialGradient = options.copy.radialGradient.cloneNode(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// create linear gradient paint
|
|
|
|
} else if (options.linearGradient) {
|
|
|
|
this.type = 'linearGradient';
|
|
|
|
this.solidColor = null;
|
|
|
|
this.radialGradient = null;
|
|
|
|
this.linearGradient = options.linearGradient.cloneNode(true);
|
|
|
|
// create linear gradient paint
|
|
|
|
} else if (options.radialGradient) {
|
|
|
|
this.type = 'radialGradient';
|
|
|
|
this.solidColor = null;
|
|
|
|
this.linearGradient = null;
|
|
|
|
this.radialGradient = options.radialGradient.cloneNode(true);
|
|
|
|
// create solid color paint
|
|
|
|
} else if (options.solidColor) {
|
|
|
|
this.type = 'solidColor';
|
|
|
|
this.solidColor = options.solidColor;
|
|
|
|
// create empty paint
|
|
|
|
} else {
|
|
|
|
this.type = 'none';
|
|
|
|
this.solidColor = null;
|
|
|
|
this.linearGradient = null;
|
|
|
|
this.radialGradient = null;
|
|
|
|
}
|
2009-07-30 22:45:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
jQuery.fn.jGraduateDefaults = {
|
|
|
|
paint: new $.jGraduate.Paint(),
|
|
|
|
window: {
|
2018-05-13 10:47:00 +00:00
|
|
|
pickerTitle: 'Drag markers to pick a paint'
|
2009-07-30 22:45:59 +00:00
|
|
|
},
|
|
|
|
images: {
|
2018-05-13 10:47:00 +00:00
|
|
|
clientPath: 'images/'
|
2011-01-07 17:35:05 +00:00
|
|
|
},
|
|
|
|
newstop: 'inverse' // same, inverse, black, white
|
2009-07-30 22:45:59 +00:00
|
|
|
};
|
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var isGecko = navigator.userAgent.indexOf('Gecko/') >= 0;
|
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
function setAttrs (elem, attrs) {
|
|
|
|
if (isGecko) {
|
2010-11-05 16:15:56 +00:00
|
|
|
for (var aname in attrs) elem.setAttribute(aname, attrs[aname]);
|
|
|
|
} else {
|
|
|
|
for (var aname in attrs) {
|
|
|
|
var val = attrs[aname], prop = elem[aname];
|
2018-05-13 10:47:00 +00:00
|
|
|
if (prop && prop.constructor === 'SVGLength') {
|
2010-11-05 16:15:56 +00:00
|
|
|
prop.baseVal.value = val;
|
|
|
|
} else {
|
|
|
|
elem.setAttribute(aname, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
function mkElem (name, attrs, newparent) {
|
2010-11-05 16:15:56 +00:00
|
|
|
var elem = document.createElementNS(ns.svg, name);
|
|
|
|
setAttrs(elem, attrs);
|
2018-05-13 10:47:00 +00:00
|
|
|
if (newparent) newparent.appendChild(elem);
|
2010-11-05 16:15:56 +00:00
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
|
2009-07-30 22:45:59 +00:00
|
|
|
jQuery.fn.jGraduate =
|
2018-05-13 10:47:00 +00:00
|
|
|
function (options) {
|
|
|
|
var $arguments = arguments;
|
|
|
|
return this.each(function () {
|
2009-07-30 22:45:59 +00:00
|
|
|
var $this = $(this), $settings = $.extend(true, {}, jQuery.fn.jGraduateDefaults, options),
|
|
|
|
id = $this.attr('id'),
|
2018-05-13 10:47:00 +00:00
|
|
|
idref = '#' + $this.attr('id') + ' ';
|
|
|
|
|
|
|
|
if (!idref) {
|
|
|
|
alert('Container element must have an id attribute to maintain unique id strings for sub-elements.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var okClicked = function () {
|
|
|
|
switch ($this.paint.type) {
|
|
|
|
case 'radialGradient':
|
|
|
|
$this.paint.linearGradient = null;
|
|
|
|
break;
|
|
|
|
case 'linearGradient':
|
|
|
|
$this.paint.radialGradient = null;
|
|
|
|
break;
|
|
|
|
case 'solidColor':
|
|
|
|
$this.paint.radialGradient = $this.paint.linearGradient = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$.isFunction($this.okCallback) && $this.okCallback($this.paint);
|
|
|
|
$this.hide();
|
|
|
|
};
|
|
|
|
var cancelClicked = function () {
|
|
|
|
$.isFunction($this.cancelCallback) && $this.cancelCallback();
|
|
|
|
$this.hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend(true, $this, { // public properties, methods, and callbacks
|
|
|
|
// make a copy of the incoming paint
|
|
|
|
paint: new $.jGraduate.Paint({copy: $settings.paint}),
|
2018-05-17 09:42:46 +00:00
|
|
|
okCallback: ($.isFunction($arguments[1]) && $arguments[1]) || null,
|
|
|
|
cancelCallback: ($.isFunction($arguments[2]) && $arguments[2]) || null
|
2018-05-13 10:47:00 +00:00
|
|
|
});
|
2009-07-30 22:45:59 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var // pos = $this.position(),
|
2009-07-30 22:45:59 +00:00
|
|
|
color = null;
|
2010-11-05 16:15:56 +00:00
|
|
|
var $win = $(window);
|
2009-07-30 22:45:59 +00:00
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
if ($this.paint.type === 'none') {
|
2009-08-01 05:03:51 +00:00
|
|
|
$this.paint = $.jGraduate.Paint({solidColor: 'ffffff'});
|
2009-07-30 22:45:59 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
$this.addClass('jGraduate_Picker');
|
|
|
|
$this.html('<ul class="jGraduate_tabs">' +
|
|
|
|
'<li class="jGraduate_tab_color jGraduate_tab_current" data-type="col">Solid Color</li>' +
|
|
|
|
'<li class="jGraduate_tab_lingrad" data-type="lg">Linear Gradient</li>' +
|
|
|
|
'<li class="jGraduate_tab_radgrad" data-type="rg">Radial Gradient</li>' +
|
|
|
|
'</ul>' +
|
|
|
|
'<div class="jGraduate_colPick"></div>' +
|
|
|
|
'<div class="jGraduate_gradPick"></div>' +
|
2010-11-05 16:15:56 +00:00
|
|
|
'<div class="jGraduate_LightBox"></div>' +
|
|
|
|
'<div id="' + id + '_jGraduate_stopPicker" class="jGraduate_stopPicker"></div>'
|
2018-05-13 10:47:00 +00:00
|
|
|
);
|
2009-07-30 22:45:59 +00:00
|
|
|
var colPicker = $(idref + '> .jGraduate_colPick');
|
2010-11-05 16:15:56 +00:00
|
|
|
var gradPicker = $(idref + '> .jGraduate_gradPick');
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
gradPicker.html(
|
|
|
|
'<div id="' + id + '_jGraduate_Swatch" class="jGraduate_Swatch">' +
|
|
|
|
'<h2 class="jGraduate_Title">' + $settings.window.pickerTitle + '</h2>' +
|
|
|
|
'<div id="' + id + '_jGraduate_GradContainer" class="jGraduate_GradContainer"></div>' +
|
|
|
|
'<div id="' + id + '_jGraduate_StopSlider" class="jGraduate_StopSlider"></div>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div class="jGraduate_Form jGraduate_Points jGraduate_lg_field">' +
|
|
|
|
'<div class="jGraduate_StopSection">' +
|
|
|
|
'<label class="jGraduate_Form_Heading">Begin Point</label>' +
|
|
|
|
'<div class="jGraduate_Form_Section">' +
|
|
|
|
'<label>x:</label>' +
|
|
|
|
'<input type="text" id="' + id + '_jGraduate_x1" size="3" title="Enter starting x value between 0.0 and 1.0"/>' +
|
|
|
|
'<label>y:</label>' +
|
|
|
|
'<input type="text" id="' + id + '_jGraduate_y1" size="3" title="Enter starting y value between 0.0 and 1.0"/>' +
|
|
|
|
'</div>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div class="jGraduate_StopSection">' +
|
|
|
|
'<label class="jGraduate_Form_Heading">End Point</label>' +
|
|
|
|
'<div class="jGraduate_Form_Section">' +
|
|
|
|
'<label>x:</label>' +
|
|
|
|
'<input type="text" id="' + id + '_jGraduate_x2" size="3" title="Enter ending x value between 0.0 and 1.0"/>' +
|
|
|
|
'<label>y:</label>' +
|
|
|
|
'<input type="text" id="' + id + '_jGraduate_y2" size="3" title="Enter ending y value between 0.0 and 1.0"/>' +
|
|
|
|
'</div>' +
|
|
|
|
'</div>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div class="jGraduate_Form jGraduate_Points jGraduate_rg_field">' +
|
2010-11-05 16:15:56 +00:00
|
|
|
'<div class="jGraduate_StopSection">' +
|
|
|
|
'<label class="jGraduate_Form_Heading">Center Point</label>' +
|
|
|
|
'<div class="jGraduate_Form_Section">' +
|
|
|
|
'<label>x:</label>' +
|
|
|
|
'<input type="text" id="' + id + '_jGraduate_cx" size="3" title="Enter x value between 0.0 and 1.0"/>' +
|
2013-02-23 21:32:09 +00:00
|
|
|
'<label>y:</label>' +
|
2010-11-05 16:15:56 +00:00
|
|
|
'<input type="text" id="' + id + '_jGraduate_cy" size="3" title="Enter y value between 0.0 and 1.0"/>' +
|
|
|
|
'</div>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div class="jGraduate_StopSection">' +
|
|
|
|
'<label class="jGraduate_Form_Heading">Focal Point</label>' +
|
|
|
|
'<div class="jGraduate_Form_Section">' +
|
|
|
|
'<label>Match center: <input type="checkbox" checked="checked" id="' + id + '_jGraduate_match_ctr"/></label><br/>' +
|
|
|
|
'<label>x:</label>' +
|
|
|
|
'<input type="text" id="' + id + '_jGraduate_fx" size="3" title="Enter x value between 0.0 and 1.0"/>' +
|
2013-02-23 21:32:09 +00:00
|
|
|
'<label>y:</label>' +
|
2010-11-05 16:15:56 +00:00
|
|
|
'<input type="text" id="' + id + '_jGraduate_fy" size="3" title="Enter y value between 0.0 and 1.0"/>' +
|
|
|
|
'</div>' +
|
|
|
|
'</div>' +
|
2018-05-13 10:47:00 +00:00
|
|
|
'</div>' +
|
2010-11-05 16:15:56 +00:00
|
|
|
'<div class="jGraduate_StopSection jGraduate_SpreadMethod">' +
|
|
|
|
'<label class="jGraduate_Form_Heading">Spread method</label>' +
|
|
|
|
'<div class="jGraduate_Form_Section">' +
|
|
|
|
'<select class="jGraduate_spreadMethod">' +
|
|
|
|
'<option value=pad selected>Pad</option>' +
|
|
|
|
'<option value=reflect>Reflect</option>' +
|
|
|
|
'<option value=repeat>Repeat</option>' +
|
2018-05-13 10:47:00 +00:00
|
|
|
'</select>' +
|
2010-03-10 18:17:48 +00:00
|
|
|
'</div>' +
|
|
|
|
'</div>' +
|
2018-05-13 10:47:00 +00:00
|
|
|
'<div class="jGraduate_Form">' +
|
|
|
|
'<div class="jGraduate_Slider jGraduate_RadiusField jGraduate_rg_field">' +
|
2010-11-05 16:15:56 +00:00
|
|
|
'<label class="prelabel">Radius:</label>' +
|
|
|
|
'<div id="' + id + '_jGraduate_Radius" class="jGraduate_SliderBar jGraduate_Radius" title="Click to set radius">' +
|
|
|
|
'<img id="' + id + '_jGraduate_RadiusArrows" class="jGraduate_RadiusArrows" src="' + $settings.images.clientPath + 'rangearrows2.gif">' +
|
|
|
|
'</div>' +
|
2018-05-13 10:47:00 +00:00
|
|
|
'<label><input type="text" id="' + id + '_jGraduate_RadiusInput" size="3" value="100"/>%</label>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div class="jGraduate_Slider jGraduate_EllipField jGraduate_rg_field">' +
|
2010-11-05 16:15:56 +00:00
|
|
|
'<label class="prelabel">Ellip:</label>' +
|
|
|
|
'<div id="' + id + '_jGraduate_Ellip" class="jGraduate_SliderBar jGraduate_Ellip" title="Click to set Ellip">' +
|
|
|
|
'<img id="' + id + '_jGraduate_EllipArrows" class="jGraduate_EllipArrows" src="' + $settings.images.clientPath + 'rangearrows2.gif">' +
|
|
|
|
'</div>' +
|
2018-05-13 10:47:00 +00:00
|
|
|
'<label><input type="text" id="' + id + '_jGraduate_EllipInput" size="3" value="0"/>%</label>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div class="jGraduate_Slider jGraduate_AngleField jGraduate_rg_field">' +
|
2010-11-05 16:15:56 +00:00
|
|
|
'<label class="prelabel">Angle:</label>' +
|
|
|
|
'<div id="' + id + '_jGraduate_Angle" class="jGraduate_SliderBar jGraduate_Angle" title="Click to set Angle">' +
|
|
|
|
'<img id="' + id + '_jGraduate_AngleArrows" class="jGraduate_AngleArrows" src="' + $settings.images.clientPath + 'rangearrows2.gif">' +
|
|
|
|
'</div>' +
|
2018-05-13 10:47:00 +00:00
|
|
|
'<label><input type="text" id="' + id + '_jGraduate_AngleInput" size="3" value="0"/>deg</label>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div class="jGraduate_Slider jGraduate_OpacField">' +
|
2010-11-05 16:15:56 +00:00
|
|
|
'<label class="prelabel">Opac:</label>' +
|
|
|
|
'<div id="' + id + '_jGraduate_Opac" class="jGraduate_SliderBar jGraduate_Opac" title="Click to set Opac">' +
|
|
|
|
'<img id="' + id + '_jGraduate_OpacArrows" class="jGraduate_OpacArrows" src="' + $settings.images.clientPath + 'rangearrows2.gif">' +
|
|
|
|
'</div>' +
|
2018-05-13 10:47:00 +00:00
|
|
|
'<label><input type="text" id="' + id + '_jGraduate_OpacInput" size="3" value="100"/>%</label>' +
|
|
|
|
'</div>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div class="jGraduate_OkCancel">' +
|
|
|
|
'<input type="button" id="' + id + '_jGraduate_Ok" class="jGraduate_Ok" value="OK"/>' +
|
|
|
|
'<input type="button" id="' + id + '_jGraduate_Cancel" class="jGraduate_Cancel" value="Cancel"/>' +
|
|
|
|
'</div>');
|
|
|
|
|
2009-07-30 22:45:59 +00:00
|
|
|
// --------------
|
2018-05-13 10:47:00 +00:00
|
|
|
// Set up all the SVG elements (the gradient, stops and rectangle)
|
|
|
|
var MAX = 256, MARGINX = 0, MARGINY = 0,
|
|
|
|
// STOP_RADIUS = 15 / 2,
|
|
|
|
SIZEX = MAX - 2 * MARGINX, SIZEY = MAX - 2 * MARGINY;
|
|
|
|
|
|
|
|
var curType, curGradient, previewRect;
|
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var attrInput = {};
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
var SLIDERW = 145;
|
|
|
|
$('.jGraduate_SliderBar').width(SLIDERW);
|
|
|
|
|
|
|
|
var container = $('#' + id + '_jGraduate_GradContainer')[0];
|
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var svg = mkElem('svg', {
|
|
|
|
id: id + '_jgraduate_svg',
|
|
|
|
width: MAX,
|
|
|
|
height: MAX,
|
|
|
|
xmlns: ns.svg
|
|
|
|
}, container);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
// if we are sent a gradient, import it
|
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
curType = curType || $this.paint.type;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var grad = curGradient = $this.paint[curType];
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var gradalpha = $this.paint.alpha;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var isSolid = curType === 'solidColor';
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
// Make any missing gradients
|
2018-05-13 10:47:00 +00:00
|
|
|
switch (curType) {
|
|
|
|
case 'solidColor':
|
|
|
|
// fall through
|
|
|
|
case 'linearGradient':
|
|
|
|
if (!isSolid) {
|
|
|
|
curGradient.id = id + '_lg_jgraduate_grad';
|
|
|
|
grad = curGradient = svg.appendChild(curGradient); // .cloneNode(true));
|
|
|
|
}
|
|
|
|
mkElem('radialGradient', {
|
|
|
|
id: id + '_rg_jgraduate_grad'
|
|
|
|
}, svg);
|
|
|
|
if (curType === 'linearGradient') break;
|
|
|
|
// fall through
|
|
|
|
case 'radialGradient':
|
|
|
|
if (!isSolid) {
|
|
|
|
curGradient.id = id + '_rg_jgraduate_grad';
|
|
|
|
grad = curGradient = svg.appendChild(curGradient); // .cloneNode(true));
|
|
|
|
}
|
|
|
|
mkElem('linearGradient', {
|
|
|
|
id: id + '_lg_jgraduate_grad'
|
|
|
|
}, svg);
|
2010-11-05 16:15:56 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
if (isSolid) {
|
2010-11-05 16:15:56 +00:00
|
|
|
grad = curGradient = $('#' + id + '_lg_jgraduate_grad')[0];
|
|
|
|
var color = $this.paint[curType];
|
|
|
|
mkStop(0, '#' + color, 1);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2011-01-07 17:35:05 +00:00
|
|
|
var type = typeof $settings.newstop;
|
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
if (type === 'string') {
|
|
|
|
switch ($settings.newstop) {
|
|
|
|
case 'same':
|
|
|
|
mkStop(1, '#' + color, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'inverse':
|
|
|
|
// Invert current color for second stop
|
|
|
|
var inverted = '';
|
|
|
|
|
|
|
|
for (var i = 0; i < 6; i += 2) {
|
2018-05-15 15:10:20 +00:00
|
|
|
// var ch = color.substr(i, 2);
|
2018-05-13 10:47:00 +00:00
|
|
|
var inv = (255 - parseInt(color.substr(i, 2), 16)).toString(16);
|
|
|
|
if (inv.length < 2) inv = 0 + inv;
|
|
|
|
inverted += inv;
|
|
|
|
}
|
|
|
|
mkStop(1, '#' + inverted, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'white':
|
|
|
|
mkStop(1, '#ffffff', 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'black':
|
|
|
|
mkStop(1, '#000000', 1);
|
|
|
|
break;
|
2011-01-07 17:35:05 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
} else if (type === 'object') {
|
2011-01-07 17:35:05 +00:00
|
|
|
var opac = ('opac' in $settings.newstop) ? $settings.newstop.opac : 1;
|
|
|
|
mkStop(1, ($settings.newstop.color || '#' + color), opac);
|
|
|
|
}
|
2010-11-05 16:15:56 +00:00
|
|
|
}
|
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
var x1 = parseFloat(grad.getAttribute('x1') || 0.0),
|
|
|
|
y1 = parseFloat(grad.getAttribute('y1') || 0.0),
|
|
|
|
x2 = parseFloat(grad.getAttribute('x2') || 1.0),
|
|
|
|
y2 = parseFloat(grad.getAttribute('y2') || 0.0);
|
|
|
|
|
|
|
|
var cx = parseFloat(grad.getAttribute('cx') || 0.5),
|
|
|
|
cy = parseFloat(grad.getAttribute('cy') || 0.5),
|
|
|
|
fx = parseFloat(grad.getAttribute('fx') || cx),
|
|
|
|
fy = parseFloat(grad.getAttribute('fy') || cy);
|
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var previewRect = mkElem('rect', {
|
|
|
|
id: id + '_jgraduate_rect',
|
|
|
|
x: MARGINX,
|
|
|
|
y: MARGINY,
|
|
|
|
width: SIZEX,
|
|
|
|
height: SIZEY,
|
2018-05-13 10:47:00 +00:00
|
|
|
fill: 'url(#' + id + '_jgraduate_grad)',
|
|
|
|
'fill-opacity': gradalpha / 100
|
2010-11-05 16:15:56 +00:00
|
|
|
}, svg);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
// stop visuals created here
|
|
|
|
var beginCoord = $('<div/>').attr({
|
|
|
|
'class': 'grad_coord jGraduate_lg_field',
|
|
|
|
title: 'Begin Stop'
|
|
|
|
}).text(1).css({
|
|
|
|
top: y1 * MAX,
|
|
|
|
left: x1 * MAX
|
|
|
|
}).data('coord', 'start').appendTo(container);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var endCoord = beginCoord.clone().text(2).css({
|
|
|
|
top: y2 * MAX,
|
|
|
|
left: x2 * MAX
|
|
|
|
}).attr('title', 'End stop').data('coord', 'end').appendTo(container);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var centerCoord = $('<div/>').attr({
|
|
|
|
'class': 'grad_coord jGraduate_rg_field',
|
|
|
|
title: 'Center stop'
|
|
|
|
}).text('C').css({
|
|
|
|
top: cy * MAX,
|
|
|
|
left: cx * MAX
|
|
|
|
}).data('coord', 'center').appendTo(container);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var focusCoord = centerCoord.clone().text('F').css({
|
|
|
|
top: fy * MAX,
|
|
|
|
left: fx * MAX,
|
|
|
|
display: 'none'
|
|
|
|
}).attr('title', 'Focus point').data('coord', 'focus').appendTo(container);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
focusCoord[0].id = id + '_jGraduate_focusCoord';
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
// var coords = $(idref + ' .grad_coord');
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
// $(container).hover(function () {
|
|
|
|
// coords.animate({
|
|
|
|
// opacity: 1
|
|
|
|
// }, 500);
|
|
|
|
// }, function () {
|
|
|
|
// coords.animate({
|
|
|
|
// opacity: .2
|
|
|
|
// }, 500);
|
|
|
|
// });
|
|
|
|
|
|
|
|
$.each(['x1', 'y1', 'x2', 'y2', 'cx', 'cy', 'fx', 'fy'], function (i, attr) {
|
2010-11-05 16:15:56 +00:00
|
|
|
var attrval = curGradient.getAttribute(attr);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var isRadial = isNaN(attr[1]);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
if (!attrval) {
|
2010-11-05 16:15:56 +00:00
|
|
|
// Set defaults
|
2018-05-13 10:47:00 +00:00
|
|
|
if (isRadial) {
|
2010-11-05 16:15:56 +00:00
|
|
|
// For radial points
|
2018-05-13 10:47:00 +00:00
|
|
|
attrval = '0.5';
|
2010-11-05 16:15:56 +00:00
|
|
|
} else {
|
|
|
|
// Only x2 is 1
|
2018-05-13 10:47:00 +00:00
|
|
|
attrval = attr === 'x2' ? '1.0' : '0.0';
|
2010-03-10 18:17:48 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-05 16:15:56 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
attrInput[attr] = $('#' + id + '_jGraduate_' + attr)
|
2010-11-05 16:15:56 +00:00
|
|
|
.val(attrval)
|
2018-05-13 10:47:00 +00:00
|
|
|
.change(function () {
|
2010-11-05 16:15:56 +00:00
|
|
|
// TODO: Support values < 0 and > 1 (zoomable preview?)
|
|
|
|
if (isNaN(parseFloat(this.value)) || this.value < 0) {
|
2018-05-13 10:47:00 +00:00
|
|
|
this.value = 0.0;
|
|
|
|
} else if (this.value > 1) {
|
2010-11-05 16:15:56 +00:00
|
|
|
this.value = 1.0;
|
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
if (!(attr[0] === 'f' && !showFocus)) {
|
2018-05-15 15:10:20 +00:00
|
|
|
if ((isRadial && curType === 'radialGradient') || (!isRadial && curType === 'linearGradient')) {
|
2010-11-05 16:15:56 +00:00
|
|
|
curGradient.setAttribute(attr, this.value);
|
|
|
|
}
|
2010-03-10 18:17:48 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
if (isRadial) {
|
|
|
|
var $elem = attr[0] === 'c' ? centerCoord : focusCoord;
|
2010-11-05 16:15:56 +00:00
|
|
|
} else {
|
2018-05-13 10:47:00 +00:00
|
|
|
var $elem = attr[1] === '1' ? beginCoord : endCoord;
|
2010-03-10 18:17:48 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var cssName = attr.indexOf('x') >= 0 ? 'left' : 'top';
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
$elem.css(cssName, this.value * MAX);
|
2018-05-13 10:47:00 +00:00
|
|
|
}).change();
|
2010-11-05 16:15:56 +00:00
|
|
|
});
|
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
function mkStop (n, color, opac, sel, stopElem) {
|
|
|
|
var stop = stopElem || mkElem('stop', {'stop-color': color, 'stop-opacity': opac, offset: n}, curGradient);
|
|
|
|
if (stopElem) {
|
|
|
|
color = stopElem.getAttribute('stop-color');
|
|
|
|
opac = stopElem.getAttribute('stop-opacity');
|
|
|
|
n = stopElem.getAttribute('offset');
|
2010-11-05 16:15:56 +00:00
|
|
|
} else {
|
|
|
|
curGradient.appendChild(stop);
|
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
if (opac === null) opac = 1;
|
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var pickerD = 'M-6.2,0.9c3.6-4,6.7-4.3,6.7-12.4c-0.2,7.9,3.1,8.8,6.5,12.4c3.5,3.8,2.9,9.6,0,12.3c-3.1,2.8-10.4,2.7-13.2,0C-9.6,9.9-9.4,4.4-6.2,0.9z';
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
var pathbg = mkElem('path', {
|
2018-05-15 15:10:20 +00:00
|
|
|
d: pickerD,
|
2010-11-05 16:15:56 +00:00
|
|
|
fill: 'url(#jGraduate_trans)',
|
|
|
|
transform: 'translate(' + (10 + n * MAX) + ', 26)'
|
|
|
|
}, stopGroup);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
var path = mkElem('path', {
|
2018-05-15 15:10:20 +00:00
|
|
|
d: pickerD,
|
2010-11-05 16:15:56 +00:00
|
|
|
fill: color,
|
|
|
|
'fill-opacity': opac,
|
|
|
|
transform: 'translate(' + (10 + n * MAX) + ', 26)',
|
|
|
|
stroke: '#000',
|
|
|
|
'stroke-width': 1.5
|
|
|
|
}, stopGroup);
|
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
$(path).mousedown(function (e) {
|
2010-11-05 16:15:56 +00:00
|
|
|
selectStop(this);
|
2018-05-15 15:10:20 +00:00
|
|
|
drag = curStop;
|
2010-11-05 16:15:56 +00:00
|
|
|
$win.mousemove(dragColor).mouseup(remDrags);
|
2018-05-15 15:10:20 +00:00
|
|
|
stopOffset = stopMakerDiv.offset();
|
2010-11-05 16:15:56 +00:00
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
2018-05-13 10:47:00 +00:00
|
|
|
}).data('stop', stop).data('bg', pathbg).dblclick(function () {
|
|
|
|
$('div.jGraduate_LightBox').show();
|
2010-11-05 16:15:56 +00:00
|
|
|
var colorhandle = this;
|
|
|
|
var stopOpacity = +stop.getAttribute('stop-opacity') || 1;
|
|
|
|
var stopColor = stop.getAttribute('stop-color') || 1;
|
2018-05-13 10:47:00 +00:00
|
|
|
var thisAlpha = (parseFloat(stopOpacity) * 255).toString(16);
|
|
|
|
while (thisAlpha.length < 2) { thisAlpha = '0' + thisAlpha; }
|
2010-11-05 16:15:56 +00:00
|
|
|
color = stopColor.substr(1) + thisAlpha;
|
2018-05-13 10:47:00 +00:00
|
|
|
$('#' + id + '_jGraduate_stopPicker').css({'left': 100, 'bottom': 15}).jPicker({
|
|
|
|
window: { title: 'Pick the start color and opacity for the gradient' },
|
|
|
|
images: { clientPath: $settings.images.clientPath },
|
|
|
|
color: { active: color, alphaSupport: true }
|
|
|
|
}, function (color, arg2) {
|
|
|
|
stopColor = color.val('hex') ? ('#' + color.val('hex')) : 'none';
|
|
|
|
stopOpacity = color.val('a') !== null ? color.val('a') / 256 : 1;
|
|
|
|
colorhandle.setAttribute('fill', stopColor);
|
|
|
|
colorhandle.setAttribute('fill-opacity', stopOpacity);
|
|
|
|
stop.setAttribute('stop-color', stopColor);
|
|
|
|
stop.setAttribute('stop-opacity', stopOpacity);
|
|
|
|
$('div.jGraduate_LightBox').hide();
|
|
|
|
$('#' + id + '_jGraduate_stopPicker').hide();
|
|
|
|
}, null, function () {
|
|
|
|
$('div.jGraduate_LightBox').hide();
|
|
|
|
$('#' + id + '_jGraduate_stopPicker').hide();
|
|
|
|
});
|
2010-03-10 18:17:48 +00:00
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
$(curGradient).find('stop').each(function () {
|
2018-05-15 15:10:20 +00:00
|
|
|
var curS = $(this);
|
2018-05-13 10:47:00 +00:00
|
|
|
if (+this.getAttribute('offset') > n) {
|
|
|
|
if (!color) {
|
2010-11-05 16:15:56 +00:00
|
|
|
var newcolor = this.getAttribute('stop-color');
|
|
|
|
var newopac = this.getAttribute('stop-opacity');
|
|
|
|
stop.setAttribute('stop-color', newcolor);
|
|
|
|
path.setAttribute('fill', newcolor);
|
|
|
|
stop.setAttribute('stop-opacity', newopac === null ? 1 : newopac);
|
|
|
|
path.setAttribute('fill-opacity', newopac === null ? 1 : newopac);
|
|
|
|
}
|
2018-05-15 15:10:20 +00:00
|
|
|
curS.before(stop);
|
2010-11-05 16:15:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
if (sel) selectStop(path);
|
2010-11-05 16:15:56 +00:00
|
|
|
return stop;
|
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
function remStop () {
|
2010-11-05 16:15:56 +00:00
|
|
|
delStop.setAttribute('display', 'none');
|
2018-05-15 15:10:20 +00:00
|
|
|
var path = $(curStop);
|
2010-11-05 16:15:56 +00:00
|
|
|
var stop = path.data('stop');
|
|
|
|
var bg = path.data('bg');
|
2018-05-15 15:10:20 +00:00
|
|
|
$([curStop, stop, bg]).remove();
|
2010-11-05 16:15:56 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var stops, stopGroup;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var stopMakerDiv = $('#' + id + '_jGraduate_StopSlider');
|
2009-07-30 22:45:59 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var curStop, stopGroup, stopMakerSVG, drag;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
var delStop = mkElem('path', {
|
|
|
|
d: 'm9.75,-6l-19.5,19.5m0,-19.5l19.5,19.5',
|
|
|
|
fill: 'none',
|
|
|
|
stroke: '#D00',
|
|
|
|
'stroke-width': 5,
|
|
|
|
display: 'none'
|
2010-11-05 16:15:56 +00:00
|
|
|
}, stopMakerSVG);
|
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
function selectStop (item) {
|
2018-05-15 15:10:20 +00:00
|
|
|
if (curStop) curStop.setAttribute('stroke', '#000');
|
2010-11-05 16:15:56 +00:00
|
|
|
item.setAttribute('stroke', 'blue');
|
2018-05-15 15:10:20 +00:00
|
|
|
curStop = item;
|
|
|
|
curStop.parentNode.appendChild(curStop);
|
2018-05-13 10:47:00 +00:00
|
|
|
// stops = $('stop');
|
2018-05-15 15:10:20 +00:00
|
|
|
// opac_select.val(curStop.attr('fill-opacity') || 1);
|
2018-05-13 10:47:00 +00:00
|
|
|
// root.append(delStop);
|
2010-11-05 16:15:56 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var stopOffset;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
function remDrags () {
|
2010-11-05 16:15:56 +00:00
|
|
|
$win.unbind('mousemove', dragColor);
|
2018-05-13 10:47:00 +00:00
|
|
|
if (delStop.getAttribute('display') !== 'none') {
|
2010-11-05 16:15:56 +00:00
|
|
|
remStop();
|
|
|
|
}
|
|
|
|
drag = null;
|
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var scaleX = 1, scaleY = 1, angle = 0;
|
|
|
|
var cX = cx;
|
|
|
|
var cY = cy;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
function xform () {
|
2018-05-15 15:10:20 +00:00
|
|
|
var rot = angle ? 'rotate(' + angle + ',' + cX + ',' + cY + ') ' : '';
|
|
|
|
if (scaleX === 1 && scaleY === 1) {
|
2010-11-05 16:15:56 +00:00
|
|
|
curGradient.removeAttribute('gradientTransform');
|
2018-05-13 10:47:00 +00:00
|
|
|
// $('#ang').addClass('dis');
|
2010-11-05 16:15:56 +00:00
|
|
|
} else {
|
2018-05-15 15:10:20 +00:00
|
|
|
var x = -cX * (scaleX - 1);
|
|
|
|
var y = -cY * (scaleY - 1);
|
|
|
|
curGradient.setAttribute('gradientTransform', rot + 'translate(' + x + ',' + y + ') scale(' + scaleX + ',' + scaleY + ')');
|
2018-05-13 10:47:00 +00:00
|
|
|
// $('#ang').removeClass('dis');
|
2010-11-05 16:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-30 22:45:59 +00:00
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
function dragColor (evt) {
|
2018-05-15 15:10:20 +00:00
|
|
|
var x = evt.pageX - stopOffset.left;
|
|
|
|
var y = evt.pageY - stopOffset.top;
|
2018-05-13 10:47:00 +00:00
|
|
|
x = x < 10 ? 10 : x > MAX + 10 ? MAX + 10 : x;
|
2009-07-30 22:45:59 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var xfStr = 'translate(' + x + ', 26)';
|
2018-05-13 10:47:00 +00:00
|
|
|
if (y < -60 || y > 130) {
|
|
|
|
delStop.setAttribute('display', 'block');
|
2018-05-15 15:10:20 +00:00
|
|
|
delStop.setAttribute('transform', xfStr);
|
2018-05-13 10:47:00 +00:00
|
|
|
} else {
|
|
|
|
delStop.setAttribute('display', 'none');
|
|
|
|
}
|
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
drag.setAttribute('transform', xfStr);
|
|
|
|
$.data(drag, 'bg').setAttribute('transform', xfStr);
|
2010-11-05 16:15:56 +00:00
|
|
|
var stop = $.data(drag, 'stop');
|
2018-05-15 15:10:20 +00:00
|
|
|
var sX = (x - 10) / MAX;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
stop.setAttribute('offset', sX);
|
2010-11-05 16:15:56 +00:00
|
|
|
var last = 0;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
$(curGradient).find('stop').each(function (i) {
|
2010-11-05 16:15:56 +00:00
|
|
|
var cur = this.getAttribute('offset');
|
|
|
|
var t = $(this);
|
2018-05-13 10:47:00 +00:00
|
|
|
if (cur < last) {
|
2010-11-05 16:15:56 +00:00
|
|
|
t.prev().before(t);
|
|
|
|
stops = $(curGradient).find('stop');
|
2010-03-10 18:17:48 +00:00
|
|
|
}
|
2010-11-05 16:15:56 +00:00
|
|
|
last = cur;
|
2010-03-10 18:17:48 +00:00
|
|
|
});
|
2010-11-05 16:15:56 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
stopMakerSVG = mkElem('svg', {
|
|
|
|
width: '100%',
|
2011-01-18 18:54:50 +00:00
|
|
|
height: 45
|
2010-11-05 16:15:56 +00:00
|
|
|
}, stopMakerDiv[0]);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var transPattern = mkElem('pattern', {
|
2010-11-05 16:15:56 +00:00
|
|
|
width: 16,
|
|
|
|
height: 16,
|
|
|
|
patternUnits: 'userSpaceOnUse',
|
|
|
|
id: 'jGraduate_trans'
|
|
|
|
}, stopMakerSVG);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var transImg = mkElem('image', {
|
2010-11-05 16:15:56 +00:00
|
|
|
width: 16,
|
|
|
|
height: 16
|
2018-05-15 15:10:20 +00:00
|
|
|
}, transPattern);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var bgImage = $settings.images.clientPath + 'map-opacity.png';
|
2010-11-05 16:15:56 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
transImg.setAttributeNS(ns.xlink, 'xlink:href', bgImage);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
$(stopMakerSVG).click(function (evt) {
|
2018-05-15 15:10:20 +00:00
|
|
|
stopOffset = stopMakerDiv.offset();
|
2010-11-05 16:15:56 +00:00
|
|
|
var target = evt.target;
|
2018-05-13 10:47:00 +00:00
|
|
|
if (target.tagName === 'path') return;
|
2018-05-15 15:10:20 +00:00
|
|
|
var x = evt.pageX - stopOffset.left - 8;
|
2018-05-13 10:47:00 +00:00
|
|
|
x = x < 10 ? 10 : x > MAX + 10 ? MAX + 10 : x;
|
2010-11-05 16:15:56 +00:00
|
|
|
mkStop(x / MAX, 0, 0, true);
|
|
|
|
evt.stopPropagation();
|
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
$(stopMakerSVG).mouseover(function () {
|
2010-11-05 16:15:56 +00:00
|
|
|
stopMakerSVG.appendChild(delStop);
|
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
stopGroup = mkElem('g', {}, stopMakerSVG);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
mkElem('line', {
|
|
|
|
x1: 10,
|
|
|
|
y1: 15,
|
|
|
|
x2: MAX + 10,
|
|
|
|
y2: 15,
|
|
|
|
'stroke-width': 2,
|
|
|
|
stroke: '#000'
|
|
|
|
}, stopMakerSVG);
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
var spreadMethodOpt = gradPicker.find('.jGraduate_spreadMethod').change(function () {
|
2010-11-05 16:15:56 +00:00
|
|
|
curGradient.setAttribute('spreadMethod', $(this).val());
|
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
// handle dragging the stop around the swatch
|
|
|
|
var draggingCoord = null;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
var onCoordDrag = function (evt) {
|
2010-11-05 16:15:56 +00:00
|
|
|
var x = evt.pageX - offset.left;
|
|
|
|
var y = evt.pageY - offset.top;
|
2009-07-30 22:45:59 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
// clamp stop to the swatch
|
|
|
|
x = x < 0 ? 0 : x > MAX ? MAX : x;
|
|
|
|
y = y < 0 ? 0 : y > MAX ? MAX : y;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
draggingCoord.css('left', x).css('top', y);
|
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
// calculate stop offset
|
2010-11-05 16:15:56 +00:00
|
|
|
var fracx = x / SIZEX;
|
|
|
|
var fracy = y / SIZEY;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var type = draggingCoord.data('coord');
|
|
|
|
var grad = curGradient;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 'start':
|
2018-05-15 15:10:20 +00:00
|
|
|
attrInput.x1.val(fracx);
|
|
|
|
attrInput.y1.val(fracy);
|
2018-05-13 10:47:00 +00:00
|
|
|
grad.setAttribute('x1', fracx);
|
|
|
|
grad.setAttribute('y1', fracy);
|
|
|
|
break;
|
|
|
|
case 'end':
|
2018-05-15 15:10:20 +00:00
|
|
|
attrInput.x2.val(fracx);
|
|
|
|
attrInput.y2.val(fracy);
|
2018-05-13 10:47:00 +00:00
|
|
|
grad.setAttribute('x2', fracx);
|
|
|
|
grad.setAttribute('y2', fracy);
|
|
|
|
break;
|
|
|
|
case 'center':
|
2018-05-15 15:10:20 +00:00
|
|
|
attrInput.cx.val(fracx);
|
|
|
|
attrInput.cy.val(fracy);
|
2018-05-13 10:47:00 +00:00
|
|
|
grad.setAttribute('cx', fracx);
|
|
|
|
grad.setAttribute('cy', fracy);
|
2018-05-15 15:10:20 +00:00
|
|
|
cX = fracx;
|
|
|
|
cY = fracy;
|
2018-05-13 10:47:00 +00:00
|
|
|
xform();
|
|
|
|
break;
|
|
|
|
case 'focus':
|
2018-05-15 15:10:20 +00:00
|
|
|
attrInput.fx.val(fracx);
|
|
|
|
attrInput.fy.val(fracy);
|
2018-05-13 10:47:00 +00:00
|
|
|
grad.setAttribute('fx', fracx);
|
|
|
|
grad.setAttribute('fy', fracy);
|
|
|
|
xform();
|
2010-03-10 18:17:48 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
evt.preventDefault();
|
2018-05-13 10:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var onCoordUp = function () {
|
2010-11-05 16:15:56 +00:00
|
|
|
draggingCoord = null;
|
|
|
|
$win.unbind('mousemove', onCoordDrag).unbind('mouseup', onCoordUp);
|
2018-05-13 10:47:00 +00:00
|
|
|
};
|
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
// Linear gradient
|
2018-05-13 10:47:00 +00:00
|
|
|
// (function () {
|
2010-11-05 16:15:56 +00:00
|
|
|
|
|
|
|
stops = curGradient.getElementsByTagNameNS(ns.svg, 'stop');
|
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var numstops = stops.length;
|
2018-05-17 09:42:46 +00:00
|
|
|
// if there are not at least two stops, then
|
2010-11-05 16:15:56 +00:00
|
|
|
if (numstops < 2) {
|
|
|
|
while (numstops < 2) {
|
2018-05-13 10:47:00 +00:00
|
|
|
curGradient.appendChild(document.createElementNS(ns.svg, 'stop'));
|
2010-11-05 16:15:56 +00:00
|
|
|
++numstops;
|
|
|
|
}
|
|
|
|
stops = curGradient.getElementsByTagNameNS(ns.svg, 'stop');
|
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < numstops; i++) {
|
2010-11-05 16:15:56 +00:00
|
|
|
mkStop(0, 0, 0, 0, stops[i]);
|
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
spreadMethodOpt.val(curGradient.getAttribute('spreadMethod') || 'pad');
|
|
|
|
|
|
|
|
var offset;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
// No match, so show focus point
|
2018-05-13 10:47:00 +00:00
|
|
|
var showFocus = false;
|
|
|
|
|
|
|
|
previewRect.setAttribute('fill-opacity', gradalpha / 100);
|
2010-11-05 16:15:56 +00:00
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
$('#' + id + ' div.grad_coord').mousedown(function (evt) {
|
2010-11-05 18:29:39 +00:00
|
|
|
evt.preventDefault();
|
2010-11-05 16:15:56 +00:00
|
|
|
draggingCoord = $(this);
|
2018-05-17 09:42:46 +00:00
|
|
|
// var sPos = draggingCoord.offset();
|
2010-11-05 16:15:56 +00:00
|
|
|
offset = draggingCoord.parent().offset();
|
|
|
|
$win.mousemove(onCoordDrag).mouseup(onCoordUp);
|
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
// bind GUI elements
|
2018-05-13 10:47:00 +00:00
|
|
|
$('#' + id + '_jGraduate_Ok').bind('click', function () {
|
2010-11-05 16:15:56 +00:00
|
|
|
$this.paint.type = curType;
|
2018-05-13 10:47:00 +00:00
|
|
|
$this.paint[curType] = curGradient.cloneNode(true);
|
2010-11-05 16:15:56 +00:00
|
|
|
$this.paint.solidColor = null;
|
|
|
|
okClicked();
|
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
$('#' + id + '_jGraduate_Cancel').bind('click', function (paint) {
|
2010-11-05 16:15:56 +00:00
|
|
|
cancelClicked();
|
|
|
|
});
|
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
if (curType === 'radialGradient') {
|
|
|
|
if (showFocus) {
|
|
|
|
focusCoord.show();
|
2010-11-05 16:15:56 +00:00
|
|
|
} else {
|
|
|
|
focusCoord.hide();
|
2018-05-15 15:10:20 +00:00
|
|
|
attrInput.fx.val('');
|
|
|
|
attrInput.fy.val('');
|
2010-11-05 16:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
$('#' + id + '_jGraduate_match_ctr')[0].checked = !showFocus;
|
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var lastfx, lastfy;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
$('#' + id + '_jGraduate_match_ctr').change(function () {
|
2010-11-05 16:15:56 +00:00
|
|
|
showFocus = !this.checked;
|
|
|
|
focusCoord.toggle(showFocus);
|
2018-05-15 15:10:20 +00:00
|
|
|
attrInput.fx.val('');
|
|
|
|
attrInput.fy.val('');
|
2010-11-05 16:15:56 +00:00
|
|
|
var grad = curGradient;
|
2018-05-13 10:47:00 +00:00
|
|
|
if (!showFocus) {
|
2010-11-05 16:15:56 +00:00
|
|
|
lastfx = grad.getAttribute('fx');
|
|
|
|
lastfy = grad.getAttribute('fy');
|
|
|
|
grad.removeAttribute('fx');
|
|
|
|
grad.removeAttribute('fy');
|
|
|
|
} else {
|
2018-05-13 10:47:00 +00:00
|
|
|
var fx = lastfx || 0.5;
|
|
|
|
var fy = lastfy || 0.5;
|
2010-11-05 16:15:56 +00:00
|
|
|
grad.setAttribute('fx', fx);
|
|
|
|
grad.setAttribute('fy', fy);
|
2018-05-15 15:10:20 +00:00
|
|
|
attrInput.fx.val(fx);
|
|
|
|
attrInput.fy.val(fy);
|
2010-11-05 16:15:56 +00:00
|
|
|
}
|
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var stops = curGradient.getElementsByTagNameNS(ns.svg, 'stop');
|
|
|
|
var numstops = stops.length;
|
2018-05-13 10:47:00 +00:00
|
|
|
// if there are not at least two stops, then
|
2010-11-05 16:15:56 +00:00
|
|
|
if (numstops < 2) {
|
|
|
|
while (numstops < 2) {
|
2018-05-13 10:47:00 +00:00
|
|
|
curGradient.appendChild(document.createElementNS(ns.svg, 'stop'));
|
2010-11-05 16:15:56 +00:00
|
|
|
++numstops;
|
|
|
|
}
|
|
|
|
stops = curGradient.getElementsByTagNameNS(ns.svg, 'stop');
|
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var slider;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
var setSlider = function (e) {
|
2010-11-05 16:15:56 +00:00
|
|
|
var offset = slider.offset;
|
|
|
|
var div = slider.parent;
|
|
|
|
var x = (e.pageX - offset.left - parseInt(div.css('border-left-width')));
|
|
|
|
if (x > SLIDERW) x = SLIDERW;
|
|
|
|
if (x <= 0) x = 0;
|
|
|
|
var posx = x - 5;
|
|
|
|
x /= SLIDERW;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
switch (slider.type) {
|
|
|
|
case 'radius':
|
|
|
|
x = Math.pow(x * 2, 2.5);
|
|
|
|
if (x > 0.98 && x < 1.02) x = 1;
|
|
|
|
if (x <= 0.01) x = 0.01;
|
|
|
|
curGradient.setAttribute('r', x);
|
|
|
|
break;
|
|
|
|
case 'opacity':
|
|
|
|
$this.paint.alpha = parseInt(x * 100);
|
|
|
|
previewRect.setAttribute('fill-opacity', x);
|
|
|
|
break;
|
|
|
|
case 'ellip':
|
2018-05-15 15:10:20 +00:00
|
|
|
scaleX = 1;
|
|
|
|
scaleY = 1;
|
2018-05-13 10:47:00 +00:00
|
|
|
if (x < 0.5) {
|
|
|
|
x /= 0.5; // 0.001
|
2018-05-15 15:10:20 +00:00
|
|
|
scaleX = x <= 0 ? 0.01 : x;
|
2018-05-13 10:47:00 +00:00
|
|
|
} else if (x > 0.5) {
|
|
|
|
x /= 0.5; // 2
|
|
|
|
x = 2 - x;
|
2018-05-15 15:10:20 +00:00
|
|
|
scaleY = x <= 0 ? 0.01 : x;
|
2018-05-13 10:47:00 +00:00
|
|
|
}
|
|
|
|
xform();
|
|
|
|
x -= 1;
|
2018-05-15 15:10:20 +00:00
|
|
|
if (scaleY === x + 1) {
|
2018-05-13 10:47:00 +00:00
|
|
|
x = Math.abs(x);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'angle':
|
|
|
|
x = x - 0.5;
|
|
|
|
angle = x *= 180;
|
|
|
|
xform();
|
|
|
|
x /= 100;
|
|
|
|
break;
|
2010-11-05 16:15:56 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
slider.elem.css({'margin-left': posx});
|
|
|
|
x = Math.round(x * 100);
|
2010-11-05 16:15:56 +00:00
|
|
|
slider.input.val(x);
|
|
|
|
};
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2018-05-15 15:10:20 +00:00
|
|
|
var ellipVal = 0, angleVal = 0;
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
if (curType === 'radialGradient') {
|
2010-11-05 16:15:56 +00:00
|
|
|
var tlist = curGradient.gradientTransform.baseVal;
|
2018-05-13 10:47:00 +00:00
|
|
|
if (tlist.numberOfItems === 2) {
|
2010-11-05 16:15:56 +00:00
|
|
|
var t = tlist.getItem(0);
|
|
|
|
var s = tlist.getItem(1);
|
2018-05-13 10:47:00 +00:00
|
|
|
if (t.type === 2 && s.type === 3) {
|
2010-11-05 16:15:56 +00:00
|
|
|
var m = s.matrix;
|
2018-05-13 10:47:00 +00:00
|
|
|
if (m.a !== 1) {
|
2018-05-15 15:10:20 +00:00
|
|
|
ellipVal = Math.round(-(1 - m.a) * 100);
|
2018-05-13 10:47:00 +00:00
|
|
|
} else if (m.d !== 1) {
|
2018-05-15 15:10:20 +00:00
|
|
|
ellipVal = Math.round((1 - m.d) * 100);
|
2018-05-13 10:47:00 +00:00
|
|
|
}
|
2010-03-10 18:17:48 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
} else if (tlist.numberOfItems === 3) {
|
2010-11-05 16:15:56 +00:00
|
|
|
// Assume [R][T][S]
|
|
|
|
var r = tlist.getItem(0);
|
|
|
|
var t = tlist.getItem(1);
|
|
|
|
var s = tlist.getItem(2);
|
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
if (r.type === 4 &&
|
|
|
|
t.type === 2 &&
|
|
|
|
s.type === 3
|
|
|
|
) {
|
2018-05-15 15:10:20 +00:00
|
|
|
angleVal = Math.round(r.angle);
|
2010-11-05 16:15:56 +00:00
|
|
|
var m = s.matrix;
|
2018-05-13 10:47:00 +00:00
|
|
|
if (m.a !== 1) {
|
2018-05-15 15:10:20 +00:00
|
|
|
ellipVal = Math.round(-(1 - m.a) * 100);
|
|
|
|
} else if (m.d !== 1) {
|
|
|
|
ellipVal = Math.round((1 - m.d) * 100);
|
2018-05-13 10:47:00 +00:00
|
|
|
}
|
2010-03-10 18:17:48 +00:00
|
|
|
}
|
2010-11-05 16:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var sliders = {
|
|
|
|
radius: {
|
|
|
|
handle: '#' + id + '_jGraduate_RadiusArrows',
|
|
|
|
input: '#' + id + '_jGraduate_RadiusInput',
|
2018-05-13 10:47:00 +00:00
|
|
|
val: (curGradient.getAttribute('r') || 0.5) * 100
|
2010-11-05 16:15:56 +00:00
|
|
|
},
|
|
|
|
opacity: {
|
|
|
|
handle: '#' + id + '_jGraduate_OpacArrows',
|
|
|
|
input: '#' + id + '_jGraduate_OpacInput',
|
|
|
|
val: $this.paint.alpha || 100
|
|
|
|
},
|
|
|
|
ellip: {
|
|
|
|
handle: '#' + id + '_jGraduate_EllipArrows',
|
|
|
|
input: '#' + id + '_jGraduate_EllipInput',
|
2018-05-15 15:10:20 +00:00
|
|
|
val: ellipVal
|
2010-11-05 16:15:56 +00:00
|
|
|
},
|
|
|
|
angle: {
|
|
|
|
handle: '#' + id + '_jGraduate_AngleArrows',
|
|
|
|
input: '#' + id + '_jGraduate_AngleInput',
|
2018-05-15 15:10:20 +00:00
|
|
|
val: angleVal
|
2010-11-05 16:15:56 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.each(sliders, function (type, data) {
|
2010-11-05 16:15:56 +00:00
|
|
|
var handle = $(data.handle);
|
2018-05-13 10:47:00 +00:00
|
|
|
handle.mousedown(function (evt) {
|
2010-11-05 16:15:56 +00:00
|
|
|
var parent = handle.parent();
|
|
|
|
slider = {
|
|
|
|
type: type,
|
|
|
|
elem: handle,
|
|
|
|
input: $(data.input),
|
|
|
|
parent: parent,
|
2011-01-18 18:54:50 +00:00
|
|
|
offset: parent.offset()
|
2010-11-05 16:15:56 +00:00
|
|
|
};
|
|
|
|
$win.mousemove(dragSlider).mouseup(stopSlider);
|
2010-03-10 18:17:48 +00:00
|
|
|
evt.preventDefault();
|
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
$(data.input).val(data.val).change(function () {
|
2010-11-05 16:15:56 +00:00
|
|
|
var val = +this.value;
|
|
|
|
var xpos = 0;
|
|
|
|
var isRad = curType === 'radialGradient';
|
2018-05-13 10:47:00 +00:00
|
|
|
switch (type) {
|
|
|
|
case 'radius':
|
|
|
|
if (isRad) curGradient.setAttribute('r', val / 100);
|
|
|
|
xpos = (Math.pow(val / 100, 1 / 2.5) / 2) * SLIDERW;
|
|
|
|
break;
|
2010-11-05 16:15:56 +00:00
|
|
|
|
2018-05-13 10:47:00 +00:00
|
|
|
case 'opacity':
|
|
|
|
$this.paint.alpha = val;
|
|
|
|
previewRect.setAttribute('fill-opacity', val / 100);
|
|
|
|
xpos = val * (SLIDERW / 100);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ellip':
|
2018-05-15 15:10:20 +00:00
|
|
|
scaleX = scaleY = 1;
|
2018-05-13 10:47:00 +00:00
|
|
|
if (val === 0) {
|
|
|
|
xpos = SLIDERW * 0.5;
|
2010-11-05 16:15:56 +00:00
|
|
|
break;
|
2018-05-13 10:47:00 +00:00
|
|
|
}
|
|
|
|
if (val > 99.5) val = 99.5;
|
|
|
|
if (val > 0) {
|
2018-05-15 15:10:20 +00:00
|
|
|
scaleY = 1 - (val / 100);
|
2018-05-13 10:47:00 +00:00
|
|
|
} else {
|
2018-05-15 15:10:20 +00:00
|
|
|
scaleX = -(val / 100) - 1;
|
2018-05-13 10:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xpos = SLIDERW * ((val + 100) / 2) / 100;
|
|
|
|
if (isRad) xform();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'angle':
|
|
|
|
angle = val;
|
|
|
|
xpos = angle / 180;
|
|
|
|
xpos += 0.5;
|
|
|
|
xpos *= SLIDERW;
|
|
|
|
if (isRad) xform();
|
2010-03-10 18:17:48 +00:00
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
if (xpos > SLIDERW) {
|
2010-11-05 16:15:56 +00:00
|
|
|
xpos = SLIDERW;
|
2018-05-13 10:47:00 +00:00
|
|
|
} else if (xpos < 0) {
|
2010-11-05 16:15:56 +00:00
|
|
|
xpos = 0;
|
|
|
|
}
|
|
|
|
handle.css({'margin-left': xpos - 5});
|
|
|
|
}).change();
|
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
var dragSlider = function (evt) {
|
2010-11-05 16:15:56 +00:00
|
|
|
setSlider(evt);
|
|
|
|
evt.preventDefault();
|
|
|
|
};
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
var stopSlider = function (evt) {
|
2010-11-05 16:15:56 +00:00
|
|
|
$win.unbind('mousemove', dragSlider).unbind('mouseup', stopSlider);
|
|
|
|
slider = null;
|
|
|
|
};
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
// --------------
|
2018-05-13 10:47:00 +00:00
|
|
|
var thisAlpha = ($this.paint.alpha * 255 / 100).toString(16);
|
|
|
|
while (thisAlpha.length < 2) { thisAlpha = '0' + thisAlpha; }
|
|
|
|
thisAlpha = thisAlpha.split('.')[0];
|
|
|
|
color = $this.paint.solidColor === 'none' ? '' : $this.paint.solidColor + thisAlpha;
|
|
|
|
|
|
|
|
if (!isSolid) {
|
2010-11-05 16:15:56 +00:00
|
|
|
color = stops[0].getAttribute('stop-color');
|
|
|
|
}
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
// This should be done somewhere else, probably
|
|
|
|
$.extend($.fn.jPicker.defaults.window, {
|
2018-05-13 10:47:00 +00:00
|
|
|
alphaSupport: true, effects: {type: 'show', speed: 0}
|
2010-11-05 16:15:56 +00:00
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
colPicker.jPicker(
|
|
|
|
{
|
|
|
|
window: { title: $settings.window.pickerTitle },
|
|
|
|
images: { clientPath: $settings.images.clientPath },
|
|
|
|
color: { active: color, alphaSupport: true }
|
|
|
|
},
|
2018-05-13 10:47:00 +00:00
|
|
|
function (color) {
|
|
|
|
$this.paint.type = 'solidColor';
|
2010-11-05 16:15:56 +00:00
|
|
|
$this.paint.alpha = color.val('ahex') ? Math.round((color.val('a') / 255) * 100) : 100;
|
2018-05-13 10:47:00 +00:00
|
|
|
$this.paint.solidColor = color.val('hex') ? color.val('hex') : 'none';
|
2010-11-05 16:15:56 +00:00
|
|
|
$this.paint.radialGradient = null;
|
2018-05-13 10:47:00 +00:00
|
|
|
okClicked();
|
2010-11-05 16:15:56 +00:00
|
|
|
},
|
|
|
|
null,
|
2018-05-13 10:47:00 +00:00
|
|
|
function () { cancelClicked(); }
|
|
|
|
);
|
2010-11-05 16:15:56 +00:00
|
|
|
|
2010-03-10 18:17:48 +00:00
|
|
|
var tabs = $(idref + ' .jGraduate_tabs li');
|
2018-05-13 10:47:00 +00:00
|
|
|
tabs.click(function () {
|
2010-03-10 18:17:48 +00:00
|
|
|
tabs.removeClass('jGraduate_tab_current');
|
|
|
|
$(this).addClass('jGraduate_tab_current');
|
2018-05-13 10:47:00 +00:00
|
|
|
$(idref + ' > div').hide();
|
2010-11-05 16:15:56 +00:00
|
|
|
var type = $(this).attr('data-type');
|
2018-05-17 09:42:46 +00:00
|
|
|
/* var container = */ $(idref + ' .jGraduate_gradPick').show();
|
2018-05-13 10:47:00 +00:00
|
|
|
if (type === 'rg' || type === 'lg') {
|
2010-11-05 16:15:56 +00:00
|
|
|
// Show/hide appropriate fields
|
|
|
|
$('.jGraduate_' + type + '_field').show();
|
|
|
|
$('.jGraduate_' + (type === 'lg' ? 'rg' : 'lg') + '_field').hide();
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
$('#' + id + '_jgraduate_rect')[0].setAttribute('fill', 'url(#' + id + '_' + type + '_jgraduate_grad)');
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
// Copy stops
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
curType = type === 'lg' ? 'linearGradient' : 'radialGradient';
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
$('#' + id + '_jGraduate_OpacInput').val($this.paint.alpha).change();
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-11-05 16:15:56 +00:00
|
|
|
var newGrad = $('#' + id + '_' + type + '_jgraduate_grad')[0];
|
2018-05-13 10:47:00 +00:00
|
|
|
|
|
|
|
if (curGradient !== newGrad) {
|
2018-05-15 15:10:20 +00:00
|
|
|
var curStops = $(curGradient).find('stop');
|
|
|
|
$(newGrad).empty().append(curStops);
|
2010-11-05 16:15:56 +00:00
|
|
|
curGradient = newGrad;
|
|
|
|
var sm = spreadMethodOpt.val();
|
|
|
|
curGradient.setAttribute('spreadMethod', sm);
|
|
|
|
}
|
2018-05-15 15:10:20 +00:00
|
|
|
showFocus = type === 'rg' && curGradient.getAttribute('fx') != null && !(cx === fx && cy === fy);
|
2010-11-05 16:15:56 +00:00
|
|
|
$('#' + id + '_jGraduate_focusCoord').toggle(showFocus);
|
2018-05-13 10:47:00 +00:00
|
|
|
if (showFocus) {
|
2010-11-05 16:15:56 +00:00
|
|
|
$('#' + id + '_jGraduate_match_ctr')[0].checked = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$(idref + ' .jGraduate_gradPick').hide();
|
|
|
|
$(idref + ' .jGraduate_colPick').show();
|
|
|
|
}
|
2009-07-30 22:45:59 +00:00
|
|
|
});
|
2018-05-13 10:47:00 +00:00
|
|
|
$(idref + ' > div').hide();
|
2010-03-10 18:17:48 +00:00
|
|
|
tabs.removeClass('jGraduate_tab_current');
|
|
|
|
var tab;
|
2018-05-13 10:47:00 +00:00
|
|
|
switch ($this.paint.type) {
|
|
|
|
case 'linearGradient':
|
|
|
|
tab = $(idref + ' .jGraduate_tab_lingrad');
|
|
|
|
break;
|
|
|
|
case 'radialGradient':
|
|
|
|
tab = $(idref + ' .jGraduate_tab_radgrad');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tab = $(idref + ' .jGraduate_tab_color');
|
|
|
|
break;
|
2009-07-30 22:45:59 +00:00
|
|
|
}
|
|
|
|
$this.show();
|
2018-05-13 10:47:00 +00:00
|
|
|
|
2010-10-14 16:54:15 +00:00
|
|
|
// jPicker will try to show after a 0ms timeout, so need to fire this after that
|
2018-05-13 10:47:00 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
tab.addClass('jGraduate_tab_current').click();
|
2010-10-14 16:54:15 +00:00
|
|
|
}, 10);
|
2009-07-30 22:45:59 +00:00
|
|
|
});
|
|
|
|
};
|
2018-05-13 10:47:00 +00:00
|
|
|
})();
|