Merge pull request #289 from zhaouv/colorPicker
colorPicker - blockly binding
This commit is contained in:
commit
52690de448
2
_server/blockly/Converter.bundle.min.js
vendored
2
_server/blockly/Converter.bundle.min.js
vendored
File diff suppressed because one or more lines are too long
@ -384,13 +384,13 @@ return code;
|
||||
*/;
|
||||
|
||||
setText_s
|
||||
: '设置剧情文本的属性' '位置' SetTextPosition_List '偏移像素' EvalString? BGNL? '标题颜色' EvalString? '正文颜色' EvalString? '背景色' EvalString? '粗体' B_1_List BGNL? '标题字体大小' EvalString? '正文字体大小' EvalString? '打字间隔' EvalString? Newline
|
||||
: '设置剧情文本的属性' '位置' SetTextPosition_List '偏移像素' EvalString? BGNL? '标题颜色' EvalString? Colour '正文颜色' EvalString? Colour '背景色' EvalString? Colour BGNL? '粗体' B_1_List '标题字体大小' EvalString? '正文字体大小' EvalString? '打字间隔' EvalString? Newline
|
||||
|
||||
|
||||
/* setText_s
|
||||
tooltip : setText:设置剧情文本的属性,颜色为RGB三元组或RGBA四元组,打字间隔为剧情文字添加的时间间隔,为整数或不填
|
||||
helpUrl : https://h5mota.com/games/template/docs/#/event?id=settext%EF%BC%9A%E8%AE%BE%E7%BD%AE%E5%89%A7%E6%83%85%E6%96%87%E6%9C%AC%E7%9A%84%E5%B1%9E%E6%80%A7
|
||||
default : [null,"","","","",null,"","",""]
|
||||
default : [null,"","",null,"",null,"",null,null,"","",""]
|
||||
SetTextPosition_List_0 =SetTextPosition_List_0==='null'?'': ', "position": "'+SetTextPosition_List_0+'"';
|
||||
var colorRe = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(,0(\.\d+)?|,1)?$/;
|
||||
if (EvalString_0) {
|
||||
@ -1118,13 +1118,13 @@ return code;
|
||||
*/;
|
||||
|
||||
setFg_0_s
|
||||
: '更改画面色调' EvalString '动画时间' Int? '不等待执行完毕' Bool Newline
|
||||
: '更改画面色调' EvalString Colour '动画时间' Int? '不等待执行完毕' Bool Newline
|
||||
|
||||
|
||||
/* setFg_0_s
|
||||
tooltip : setFg: 更改画面色调,动画时间可不填
|
||||
helpUrl : https://h5mota.com/games/template/docs/#/event?id=setfg%EF%BC%9A%E6%9B%B4%E6%94%B9%E7%94%BB%E9%9D%A2%E8%89%B2%E8%B0%83
|
||||
default : ["255,255,255,1",500,false]
|
||||
default : ["255,255,255,1",'rgba(255,255,255,1)',500,false]
|
||||
colour : this.soundColor
|
||||
var colorRe = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(,0(\.\d+)?|,1)?$/;
|
||||
if (!colorRe.test(EvalString_0))throw new Error('颜色格式错误,形如:0~255,0~255,0~255,0~1');
|
||||
@ -1150,12 +1150,12 @@ return code;
|
||||
*/;
|
||||
|
||||
screenFlash_s
|
||||
: '画面闪烁' EvalString '单次时间' Int '执行次数' Int? '不等待执行完毕' Bool Newline
|
||||
: '画面闪烁' EvalString Colour '单次时间' Int '执行次数' Int? '不等待执行完毕' Bool Newline
|
||||
|
||||
/* screenFlash_s
|
||||
tooltip : screenFlash: 画面闪烁,动画时间可不填
|
||||
helpUrl : https://h5mota.com/games/template/docs/#/event?id=screenFlash%EF%BC%9A%E7%94%BB%E9%9D%A2%E9%97%AA%E7%83%81
|
||||
default : ["255,255,255,1",500,1,false]
|
||||
default : ["255,255,255,1",'rgba(255,255,255,1)',500,1,false]
|
||||
colour : this.soundColor
|
||||
var colorRe = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d),(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(,0(\.\d+)?|,1)?$/;
|
||||
if (!colorRe.test(EvalString_0))throw new Error('颜色格式错误,形如:0~255,0~255,0~255,0~1');
|
||||
@ -1729,6 +1729,14 @@ Global_Value_List
|
||||
: '血网伤害'|'中毒伤害'|'衰弱效果'|'红宝石效果'|'蓝宝石效果'|'绿宝石效果'|'红血瓶效果'|'蓝血瓶效果'|'黄血瓶效果'|'绿血瓶效果'|'破甲比例'|'反击比例'|'净化比例'|'仇恨增加值'|'行走速度'|'动画时间'|'楼层切换时间'
|
||||
/*Global_Value_List ['lavaDamage','poisonDamage','weakValue', 'redJewel', 'blueJewel', 'greenJewel', 'redPotion', 'bluePotion', 'yellowPotion', 'greenPotion', 'breakArmor', 'counterAttack', 'purify', 'hatred', 'moveSpeed', 'animateSpeed', 'floorChangeTime']*/;
|
||||
|
||||
Colour
|
||||
: 'sdeirughvuiyasdeb'+ //为了被识别为复杂词法规则
|
||||
;
|
||||
|
||||
Angle
|
||||
: 'sdeirughvuiyasdeb'+ //为了被识别为复杂词法规则
|
||||
;
|
||||
|
||||
Bool: 'TRUE'
|
||||
| 'FALSE'
|
||||
;
|
||||
@ -1970,7 +1978,7 @@ ActionParser.prototype.parseAction = function() {
|
||||
if (!/^\w+\.png$/.test(data.background))
|
||||
data.background=setTextfunc(data.background);
|
||||
this.next = MotaActionBlocks['setText_s'].xmlText([
|
||||
data.position,data.offset,data.title,data.text,data.background,data.bold,data.titlefont,data.textfont,data.time,this.next]);
|
||||
data.position,data.offset,data.title,`rgba(${data.title})`,data.text,`rgba(${data.text})`,data.background,`rgba(${data.background})`,data.bold,data.titlefont,data.textfont,data.time,this.next]);
|
||||
break;
|
||||
case "tip":
|
||||
this.next = MotaActionBlocks['tip_s'].xmlText([
|
||||
@ -2142,7 +2150,7 @@ ActionParser.prototype.parseAction = function() {
|
||||
case "setFg": // 颜色渐变
|
||||
if(this.isset(data.color)){
|
||||
this.next = MotaActionBlocks['setFg_0_s'].xmlText([
|
||||
data.color,data.time||0,data.async||false,this.next]);
|
||||
data.color,`rgba(${data.color})`,data.time||0,data.async||false,this.next]);
|
||||
} else {
|
||||
this.next = MotaActionBlocks['setFg_1_s'].xmlText([
|
||||
data.time||0,data.async||false,this.next]);
|
||||
@ -2150,7 +2158,7 @@ ActionParser.prototype.parseAction = function() {
|
||||
break;
|
||||
case "screenFlash": // 画面闪烁
|
||||
this.next = MotaActionBlocks['screenFlash_s'].xmlText([
|
||||
data.color,data.time||500,data.times||1,data.async||false,this.next]);
|
||||
data.color,`rgba(${data.color})`,data.time||500,data.times||1,data.async||false,this.next]);
|
||||
break;
|
||||
case "setWeather": // 更改天气
|
||||
this.next = MotaActionBlocks['setWeather_s'].xmlText([
|
||||
|
||||
@ -1,263 +1,263 @@
|
||||
(function (window) {
|
||||
window.jsColorPicker = function(selectors, config) {
|
||||
var renderCallback = function(colors, mode) {
|
||||
var options = this,
|
||||
input = options.input,
|
||||
patch = options.patch,
|
||||
RGB = colors.RND.rgb,
|
||||
HSL = colors.RND.hsl,
|
||||
AHEX = options.isIE8 ? (colors.alpha < 0.16 ? '0' : '') +
|
||||
(Math.round(colors.alpha * 100)).toString(16).toUpperCase() + colors.HEX : '',
|
||||
RGBInnerText = RGB.r + ',' + RGB.g + ',' + RGB.b,
|
||||
RGBAText = RGBInnerText + ',' + colors.alpha,
|
||||
isAlpha = colors.alpha !== 1 && !options.isIE8,
|
||||
colorMode = input.getAttribute('data-colorMode');
|
||||
window.jsColorPicker = function(selectors, config) {
|
||||
var renderCallback = function(colors, mode) {
|
||||
var options = this,
|
||||
input = options.input,
|
||||
patch = options.patch,
|
||||
RGB = colors.RND.rgb,
|
||||
HSL = colors.RND.hsl,
|
||||
AHEX = options.isIE8 ? (colors.alpha < 0.16 ? '0' : '') +
|
||||
(Math.round(colors.alpha * 100)).toString(16).toUpperCase() + colors.HEX : '',
|
||||
RGBInnerText = RGB.r + ',' + RGB.g + ',' + RGB.b,
|
||||
RGBAText = RGBInnerText + ',' + colors.alpha,
|
||||
isAlpha = colors.alpha !== 1 && !options.isIE8,
|
||||
colorMode = input.getAttribute('data-colorMode');
|
||||
|
||||
patch.style.cssText =
|
||||
'color:' + (colors.rgbaMixCustom.luminance > 0.22 ? '#222' : '#ddd') + ';' + // Black...???
|
||||
'background-color: rgba(' + RGBAText + ');' +
|
||||
'filter:' + (options.isIE8 ? 'progid:DXImageTransform.Microsoft.gradient(' + // IE<9
|
||||
'startColorstr=#' + AHEX + ',' + 'endColorstr=#' + AHEX + ')' : '');
|
||||
patch.style.cssText =
|
||||
'color:' + (colors.rgbaMixCustom.luminance > 0.22 ? '#222' : '#ddd') + ';' + // Black...???
|
||||
'background-color: rgba(' + RGBAText + ');' +
|
||||
'filter:' + (options.isIE8 ? 'progid:DXImageTransform.Microsoft.gradient(' + // IE<9
|
||||
'startColorstr=#' + AHEX + ',' + 'endColorstr=#' + AHEX + ')' : '');
|
||||
|
||||
input.value = RGBAText;
|
||||
input.value = RGBAText;
|
||||
|
||||
if (options.displayCallback) {
|
||||
options.displayCallback(colors, mode, options);
|
||||
}
|
||||
},
|
||||
extractValue = function(elm) {
|
||||
var val = elm.value || elm.getAttribute('value') || elm.style.backgroundColor || "0,0,0,1";
|
||||
if (/^[0-9 ]+,[0-9 ]+,[0-9 ]+,[0-9. ]+$/.test(val)) return "rgba("+val+")";
|
||||
if (options.displayCallback) {
|
||||
options.displayCallback(colors, mode, options);
|
||||
}
|
||||
},
|
||||
extractValue = function(elm) {
|
||||
var val = elm.value || elm.getAttribute('value') || elm.style.backgroundColor || "0,0,0,1";
|
||||
if (/^[0-9 ]+,[0-9 ]+,[0-9 ]+,[0-9. ]+$/.test(val)) return "rgba("+val+")";
|
||||
if (/^[0-9 ]+,[0-9 ]+,[0-9 ]+$/.test(val)) return "rgba("+val+",1)";
|
||||
return null;
|
||||
},
|
||||
actionCallback = function(event, action) {
|
||||
var options = this,
|
||||
colorPicker = colorPickers.current;
|
||||
return null;
|
||||
},
|
||||
actionCallback = function(event, action) {
|
||||
var options = this,
|
||||
colorPicker = colorPickers.current;
|
||||
|
||||
if (action === 'toMemory') {
|
||||
var memos = colorPicker.nodes.memos,
|
||||
backgroundColor = '',
|
||||
opacity = 0,
|
||||
cookieTXT = [];
|
||||
if (action === 'toMemory') {
|
||||
var memos = colorPicker.nodes.memos,
|
||||
backgroundColor = '',
|
||||
opacity = 0,
|
||||
cookieTXT = [];
|
||||
|
||||
for (var n = 0, m = memos.length; n < m; n++) {
|
||||
backgroundColor = memos[n].style.backgroundColor;
|
||||
opacity = memos[n].style.opacity;
|
||||
opacity = Math.round((opacity === '' ? 1 : opacity) * 100) / 100;
|
||||
cookieTXT.push(backgroundColor.
|
||||
replace(/, /g, ',').
|
||||
replace('rgb(', 'rgba(').
|
||||
replace(')', ',' + opacity + ')')
|
||||
);
|
||||
}
|
||||
cookieTXT = '\'' + cookieTXT.join('\',\'') + '\'';
|
||||
ColorPicker.docCookies('colorPickerMemos' + (options.noAlpha ? 'NoAlpha' : ''), cookieTXT);
|
||||
} else if (action === 'resizeApp') {
|
||||
ColorPicker.docCookies('colorPickerSize', colorPicker.color.options.currentSize);
|
||||
} else if (action === 'modeChange') {
|
||||
var mode = colorPicker.color.options.mode;
|
||||
for (var n = 0, m = memos.length; n < m; n++) {
|
||||
backgroundColor = memos[n].style.backgroundColor;
|
||||
opacity = memos[n].style.opacity;
|
||||
opacity = Math.round((opacity === '' ? 1 : opacity) * 100) / 100;
|
||||
cookieTXT.push(backgroundColor.
|
||||
replace(/, /g, ',').
|
||||
replace('rgb(', 'rgba(').
|
||||
replace(')', ',' + opacity + ')')
|
||||
);
|
||||
}
|
||||
cookieTXT = '\'' + cookieTXT.join('\',\'') + '\'';
|
||||
ColorPicker.docCookies('colorPickerMemos' + (options.noAlpha ? 'NoAlpha' : ''), cookieTXT);
|
||||
} else if (action === 'resizeApp') {
|
||||
ColorPicker.docCookies('colorPickerSize', colorPicker.color.options.currentSize);
|
||||
} else if (action === 'modeChange') {
|
||||
var mode = colorPicker.color.options.mode;
|
||||
|
||||
ColorPicker.docCookies('colorPickerMode', mode.type + '-' + mode.z);
|
||||
}
|
||||
},
|
||||
createInstance = function(elm, config) {
|
||||
var initConfig = {
|
||||
klass: window.ColorPicker,
|
||||
input: elm,
|
||||
patch: elm,
|
||||
isIE8: !!document.all && !document.addEventListener, // Opera???
|
||||
// *** animationSpeed: 200,
|
||||
// *** draggable: true,
|
||||
margin: {left: -1, top: 2},
|
||||
customBG: '#FFFFFF',
|
||||
// displayCallback: displayCallback,
|
||||
/* --- regular colorPicker options from this point --- */
|
||||
color: extractValue(elm),
|
||||
initStyle: 'display: none',
|
||||
mode: ColorPicker.docCookies('colorPickerMode') || 'hsv-h',
|
||||
// memoryColors: (function(colors, config) {
|
||||
// return config.noAlpha ?
|
||||
// colors.replace(/\,\d*\.*\d*\)/g, ',1)') : colors;
|
||||
// })($.docCookies('colorPickerMemos'), config || {}),
|
||||
memoryColors: ColorPicker.docCookies('colorPickerMemos' +
|
||||
((config || {}).noAlpha ? 'NoAlpha' : '')),
|
||||
size: ColorPicker.docCookies('colorPickerSize') || 1,
|
||||
renderCallback: renderCallback,
|
||||
actionCallback: actionCallback
|
||||
};
|
||||
ColorPicker.docCookies('colorPickerMode', mode.type + '-' + mode.z);
|
||||
}
|
||||
},
|
||||
createInstance = function(elm, config) {
|
||||
var initConfig = {
|
||||
klass: window.ColorPicker,
|
||||
input: elm,
|
||||
patch: elm,
|
||||
isIE8: !!document.all && !document.addEventListener, // Opera???
|
||||
// *** animationSpeed: 200,
|
||||
// *** draggable: true,
|
||||
margin: {left: -1, top: 2},
|
||||
customBG: '#FFFFFF',
|
||||
// displayCallback: displayCallback,
|
||||
/* --- regular colorPicker options from this point --- */
|
||||
color: extractValue(elm),
|
||||
initStyle: 'display: none',
|
||||
mode: ColorPicker.docCookies('colorPickerMode') || 'hsv-h',
|
||||
// memoryColors: (function(colors, config) {
|
||||
// return config.noAlpha ?
|
||||
// colors.replace(/\,\d*\.*\d*\)/g, ',1)') : colors;
|
||||
// })($.docCookies('colorPickerMemos'), config || {}),
|
||||
memoryColors: ColorPicker.docCookies('colorPickerMemos' +
|
||||
((config || {}).noAlpha ? 'NoAlpha' : '')),
|
||||
size: ColorPicker.docCookies('colorPickerSize') || 1,
|
||||
renderCallback: renderCallback,
|
||||
actionCallback: actionCallback
|
||||
};
|
||||
|
||||
for (var n in config) {
|
||||
initConfig[n] = config[n];
|
||||
}
|
||||
return new initConfig.klass(initConfig);
|
||||
},
|
||||
doEventListeners = function(elm, multiple, off) {
|
||||
var onOff = off ? 'removeEventListener' : 'addEventListener',
|
||||
inputListener = function(e) {
|
||||
var index = multiple ? Array.prototype.indexOf.call(elms, this) : 0,
|
||||
colorPicker = colorPickers[index] ||
|
||||
(colorPickers[index] = createInstance(this, config)),
|
||||
options = colorPicker.color.options;
|
||||
for (var n in config) {
|
||||
initConfig[n] = config[n];
|
||||
}
|
||||
return new initConfig.klass(initConfig);
|
||||
},
|
||||
doEventListeners = function(elm, multiple, off) {
|
||||
var onOff = off ? 'removeEventListener' : 'addEventListener',
|
||||
inputListener = function(e) {
|
||||
var index = multiple ? Array.prototype.indexOf.call(elms, this) : 0,
|
||||
colorPicker = colorPickers[index] ||
|
||||
(colorPickers[index] = createInstance(this, config)),
|
||||
options = colorPicker.color.options;
|
||||
|
||||
options.color = extractValue(elm); // brings color to default on reset
|
||||
//检查颜色合法性
|
||||
if (options.color != null && options.color == options.color.match(/rgba\([0-9 ]+,[0-9 ]+,[0-9 ]+,[0-9. ]+\)/)[0]) {
|
||||
var chec = options.color.match(/[0-9.]+/g);
|
||||
if (chec.length != 4)
|
||||
return;
|
||||
for (var i = 0; i < 3; i++) {
|
||||
if (chec[i] != chec[i].match(/\d+/)[0] || +chec[i] < 0 || +chec[i] > 255)
|
||||
return;
|
||||
}
|
||||
if (chec[3] != chec[3].match(/\d+(\.\d+)?/)[0] || parseFloat(chec[3]) > 1 || parseFloat(chec[3] < 0))
|
||||
return;
|
||||
if (!multiple) {
|
||||
colorPicker.setColor(extractValue(elm), undefined, undefined, true);
|
||||
colorPicker.saveAsBackground();
|
||||
}
|
||||
colorPickers.current = colorPickers[index];
|
||||
}
|
||||
}
|
||||
focusListener = function(e) {
|
||||
elm = document.getElementById("colorPicker");
|
||||
var input = elm,
|
||||
position = window.ColorPicker.getOrigin(input),
|
||||
index = multiple ? Array.prototype.indexOf.call(elms, elm) : 0,
|
||||
colorPicker = colorPickers[index] ||
|
||||
(colorPickers[index] = createInstance(elm, config)),
|
||||
options = colorPicker.color.options,
|
||||
colorPickerUI = colorPicker.nodes.colorPicker,
|
||||
appendTo = (options.appendTo || document.body),
|
||||
isStatic = /static/.test(window.getComputedStyle(appendTo).position),
|
||||
atrect = isStatic ? {left: 0, top: 0} : appendTo.getBoundingClientRect(),
|
||||
waitTimer = 0;
|
||||
|
||||
options.color = extractValue(elm); // brings color to default on reset
|
||||
colorPickerUI.style.cssText =
|
||||
'position: absolute;' + (!colorPickers[index].cssIsReady ? 'display: none;' : '') +
|
||||
'left:' + (position.left + options.margin.left - atrect.left) + 'px;' +
|
||||
'top:' + (position.top + +input.offsetHeight + options.margin.top - atrect.top) + 'px;';
|
||||
options.color = extractValue(elm); // brings color to default on reset
|
||||
//检查颜色合法性
|
||||
if (options.color != null && options.color == options.color.match(/rgba\([0-9 ]+,[0-9 ]+,[0-9 ]+,[0-9. ]+\)/)[0]) {
|
||||
var chec = options.color.match(/[0-9.]+/g);
|
||||
if (chec.length != 4)
|
||||
return;
|
||||
for (var i = 0; i < 3; i++) {
|
||||
if (chec[i] != chec[i].match(/\d+/)[0] || +chec[i] < 0 || +chec[i] > 255)
|
||||
return;
|
||||
}
|
||||
if (chec[3] != chec[3].match(/\d+(\.\d+)?/)[0] || parseFloat(chec[3]) > 1 || parseFloat(chec[3] < 0))
|
||||
return;
|
||||
if (!multiple) {
|
||||
colorPicker.setColor(extractValue(elm), undefined, undefined, true);
|
||||
colorPicker.saveAsBackground();
|
||||
}
|
||||
colorPickers.current = colorPickers[index];
|
||||
}
|
||||
}
|
||||
focusListener = function(e) {
|
||||
elm = document.getElementById("colorPicker");
|
||||
var input = elm,
|
||||
position = window.ColorPicker.getOrigin(input),
|
||||
index = multiple ? Array.prototype.indexOf.call(elms, elm) : 0,
|
||||
colorPicker = colorPickers[index] ||
|
||||
(colorPickers[index] = createInstance(elm, config)),
|
||||
options = colorPicker.color.options,
|
||||
colorPickerUI = colorPicker.nodes.colorPicker,
|
||||
appendTo = (options.appendTo || document.body),
|
||||
isStatic = /static/.test(window.getComputedStyle(appendTo).position),
|
||||
atrect = isStatic ? {left: 0, top: 0} : appendTo.getBoundingClientRect(),
|
||||
waitTimer = 0;
|
||||
|
||||
options.color = extractValue(elm); // brings color to default on reset
|
||||
colorPickerUI.style.cssText =
|
||||
'position: absolute;' + (!colorPickers[index].cssIsReady ? 'display: none;' : '') +
|
||||
'left:' + (position.left + options.margin.left - atrect.left) + 'px;' +
|
||||
'top:' + (position.top + +input.offsetHeight + options.margin.top - atrect.top) + 'px;';
|
||||
|
||||
if (!multiple) {
|
||||
options.input = elm;
|
||||
options.patch = elm; // check again???
|
||||
colorPicker.setColor(extractValue(elm), undefined, undefined, true);
|
||||
colorPicker.saveAsBackground();
|
||||
}
|
||||
colorPickers.current = colorPickers[index];
|
||||
appendTo.appendChild(colorPickerUI);
|
||||
waitTimer = setInterval(function() { // compensating late style on onload in colorPicker
|
||||
if (colorPickers.current.cssIsReady) {
|
||||
waitTimer = clearInterval(waitTimer);
|
||||
colorPickerUI.style.display = 'block';
|
||||
}
|
||||
}, 10);
|
||||
},
|
||||
mousDownListener = function(e) {
|
||||
var colorPicker = colorPickers.current,
|
||||
colorPickerUI = (colorPicker ? colorPicker.nodes.colorPicker : undefined),
|
||||
animationSpeed = colorPicker ? colorPicker.color.options.animationSpeed : 0,
|
||||
isColorPicker = colorPicker && (function(elm) {
|
||||
while (elm) {
|
||||
if ((elm.className || '').indexOf('cpPanel') !== -1) return elm;
|
||||
elm = elm.parentNode;
|
||||
}
|
||||
return false;
|
||||
})(e.target),
|
||||
inputIndex = Array.prototype.indexOf.call(elms, e.target);
|
||||
if (!multiple) {
|
||||
options.input = elm;
|
||||
options.patch = elm; // check again???
|
||||
colorPicker.setColor(extractValue(elm), undefined, undefined, true);
|
||||
colorPicker.saveAsBackground();
|
||||
}
|
||||
colorPickers.current = colorPickers[index];
|
||||
appendTo.appendChild(colorPickerUI);
|
||||
waitTimer = setInterval(function() { // compensating late style on onload in colorPicker
|
||||
if (colorPickers.current.cssIsReady) {
|
||||
waitTimer = clearInterval(waitTimer);
|
||||
colorPickerUI.style.display = 'block';
|
||||
}
|
||||
}, 10);
|
||||
},
|
||||
mousDownListener = function(e) {
|
||||
var colorPicker = colorPickers.current,
|
||||
colorPickerUI = (colorPicker ? colorPicker.nodes.colorPicker : undefined),
|
||||
animationSpeed = colorPicker ? colorPicker.color.options.animationSpeed : 0,
|
||||
isColorPicker = colorPicker && (function(elm) {
|
||||
while (elm) {
|
||||
if ((elm.className || '').indexOf('cpPanel') !== -1) return elm;
|
||||
elm = elm.parentNode;
|
||||
}
|
||||
return false;
|
||||
})(e.target),
|
||||
inputIndex = Array.prototype.indexOf.call(elms, e.target);
|
||||
|
||||
if (isColorPicker && Array.prototype.indexOf.call(colorPickers, isColorPicker)) {
|
||||
if (e.target === colorPicker.nodes.exit) {
|
||||
colorPickerUI.parentNode.style.display = 'none';
|
||||
document.activeElement.blur();
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
} else if (inputIndex !== -1) {
|
||||
// ...
|
||||
} else if (colorPickerUI) {
|
||||
colorPickerUI.parentNode.style.display = 'none';
|
||||
}
|
||||
};
|
||||
button = document.getElementById("colorSwitch");
|
||||
button[onOff]('click', focusListener);
|
||||
elm[onOff]('input', inputListener);
|
||||
if (isColorPicker && Array.prototype.indexOf.call(colorPickers, isColorPicker)) {
|
||||
if (e.target === colorPicker.nodes.exit) {
|
||||
colorPickerUI.parentNode.style.display = 'none';
|
||||
document.activeElement.blur();
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
} else if (inputIndex !== -1) {
|
||||
// ...
|
||||
} else if (colorPickerUI) {
|
||||
colorPickerUI.parentNode.style.display = 'none';
|
||||
}
|
||||
};
|
||||
button = document.getElementById("colorSwitch");
|
||||
button[onOff]('click', focusListener);
|
||||
elm[onOff]('input', inputListener);
|
||||
|
||||
if (!colorPickers.evt || off) {
|
||||
colorPickers.evt = true; // prevent new eventListener for window
|
||||
if (!colorPickers.evt || off) {
|
||||
colorPickers.evt = true; // prevent new eventListener for window
|
||||
|
||||
window[onOff]('mousedown', mousDownListener);
|
||||
}
|
||||
},
|
||||
// this is a way to prevent data binding on HTMLElements
|
||||
colorPickers = window.jsColorPicker.colorPickers || [],
|
||||
elms = document.querySelectorAll(selectors),
|
||||
testColors = new window.Colors({customBG: config.customBG, allMixDetails: true});
|
||||
window[onOff]('mousedown', mousDownListener);
|
||||
}
|
||||
},
|
||||
// this is a way to prevent data binding on HTMLElements
|
||||
colorPickers = window.jsColorPicker.colorPickers || [],
|
||||
elms = document.querySelectorAll(selectors),
|
||||
testColors = new window.Colors({customBG: config.customBG, allMixDetails: true});
|
||||
|
||||
window.jsColorPicker.colorPickers = colorPickers;
|
||||
window.jsColorPicker.colorPickers = colorPickers;
|
||||
|
||||
for (var n = 0, m = elms.length; n < m; n++) {
|
||||
var elm = elms[n];
|
||||
for (var n = 0, m = elms.length; n < m; n++) {
|
||||
var elm = elms[n];
|
||||
|
||||
if (config === 'destroy') {
|
||||
doEventListeners(elm, (config && config.multipleInstances), true);
|
||||
if (colorPickers[n]) {
|
||||
colorPickers[n].destroyAll();
|
||||
}
|
||||
} else {
|
||||
var color = extractValue(elm);
|
||||
var value = color.split('(');
|
||||
if (config === 'destroy') {
|
||||
doEventListeners(elm, (config && config.multipleInstances), true);
|
||||
if (colorPickers[n]) {
|
||||
colorPickers[n].destroyAll();
|
||||
}
|
||||
} else {
|
||||
var color = extractValue(elm);
|
||||
var value = color.split('(');
|
||||
|
||||
testColors.setColor(color);
|
||||
if (config && config.init) {
|
||||
config.init(elm, testColors.colors);
|
||||
}
|
||||
elm.setAttribute('data-colorMode', value[1] ? value[0].substr(0, 3) : 'HEX');
|
||||
doEventListeners(elm, (config && config.multipleInstances), false);
|
||||
if (config && config.readOnly) {
|
||||
elm.readOnly = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
testColors.setColor(color);
|
||||
if (config && config.init) {
|
||||
config.init(elm, testColors.colors);
|
||||
}
|
||||
elm.setAttribute('data-colorMode', value[1] ? value[0].substr(0, 3) : 'HEX');
|
||||
doEventListeners(elm, (config && config.multipleInstances), false);
|
||||
if (config && config.readOnly) {
|
||||
elm.readOnly = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return window.jsColorPicker.colorPickers;
|
||||
};
|
||||
return window.jsColorPicker.colorPickers;
|
||||
};
|
||||
|
||||
window.ColorPicker.docCookies = function(key, val, options) {
|
||||
var encode = encodeURIComponent, decode = decodeURIComponent,
|
||||
cookies, n, tmp, cache = {},
|
||||
days;
|
||||
window.ColorPicker.docCookies = function(key, val, options) {
|
||||
var encode = encodeURIComponent, decode = decodeURIComponent,
|
||||
cookies, n, tmp, cache = {},
|
||||
days;
|
||||
|
||||
if (val === undefined) { // all about reading cookies
|
||||
cookies = document.cookie.split(/;\s*/) || [];
|
||||
for (n = cookies.length; n--; ) {
|
||||
tmp = cookies[n].split('=');
|
||||
if (tmp[0]) cache[decode(tmp.shift())] = decode(tmp.join('=')); // there might be '='s in the value...
|
||||
}
|
||||
if (val === undefined) { // all about reading cookies
|
||||
cookies = document.cookie.split(/;\s*/) || [];
|
||||
for (n = cookies.length; n--; ) {
|
||||
tmp = cookies[n].split('=');
|
||||
if (tmp[0]) cache[decode(tmp.shift())] = decode(tmp.join('=')); // there might be '='s in the value...
|
||||
}
|
||||
|
||||
if (!key) return cache; // return Json for easy access to all cookies
|
||||
else return cache[key]; // easy access to cookies from here
|
||||
} else { // write/delete cookie
|
||||
options = options || {};
|
||||
if (!key) return cache; // return Json for easy access to all cookies
|
||||
else return cache[key]; // easy access to cookies from here
|
||||
} else { // write/delete cookie
|
||||
options = options || {};
|
||||
|
||||
if (val === '' || options.expires < 0) { // prepare deleteing the cookie
|
||||
options.expires = -1;
|
||||
// options.path = options.domain = options.secure = undefined; // to make shure the cookie gets deleted...
|
||||
}
|
||||
if (val === '' || options.expires < 0) { // prepare deleteing the cookie
|
||||
options.expires = -1;
|
||||
// options.path = options.domain = options.secure = undefined; // to make shure the cookie gets deleted...
|
||||
}
|
||||
|
||||
if (options.expires !== undefined) { // prepare date if any
|
||||
days = new Date();
|
||||
days.setDate(days.getDate() + options.expires);
|
||||
}
|
||||
if (options.expires !== undefined) { // prepare date if any
|
||||
days = new Date();
|
||||
days.setDate(days.getDate() + options.expires);
|
||||
}
|
||||
|
||||
document.cookie = encode(key) + '=' + encode(val) +
|
||||
(days ? '; expires=' + days.toUTCString() : '') +
|
||||
(options.path ? '; path=' + options.path : '') +
|
||||
(options.domain ? '; domain=' + options.domain : '') +
|
||||
(options.secure ? '; secure' : '');
|
||||
}
|
||||
};
|
||||
document.cookie = encode(key) + '=' + encode(val) +
|
||||
(days ? '; expires=' + days.toUTCString() : '') +
|
||||
(options.path ? '; path=' + options.path : '') +
|
||||
(options.domain ? '; domain=' + options.domain : '') +
|
||||
(options.secure ? '; secure' : '');
|
||||
}
|
||||
};
|
||||
})(this);
|
||||
|
||||
// Added
|
||||
@ -285,4 +285,60 @@ function copyColor() {
|
||||
colorPicker.select();
|
||||
document.execCommand("Copy");
|
||||
doHide();
|
||||
}
|
||||
}
|
||||
|
||||
Blockly.FieldColour.prototype.createWidget_ = function() {
|
||||
// Create the palette using Closure.
|
||||
var picker = new goog.ui.ColorPicker();
|
||||
picker.setSize(this.columns_ || Blockly.FieldColour.COLUMNS);
|
||||
picker.setColors(this.colours_ || Blockly.FieldColour.COLOURS);
|
||||
var div = Blockly.WidgetDiv.DIV;
|
||||
picker.render(div);
|
||||
picker.setSelectedColor(this.getValue());
|
||||
|
||||
Blockly.WidgetDiv.hide();
|
||||
|
||||
self=this;
|
||||
var pb=self.sourceBlock_
|
||||
var args = MotaActionBlocks[pb.type].args
|
||||
var targetf=args[args.indexOf(self.name)-1]
|
||||
|
||||
var getValue=function(){
|
||||
return self.getValue() // css颜色
|
||||
// 也可以用 pb.getFieldValue(targetf) 获得颜色块左边的域的内容
|
||||
}
|
||||
|
||||
var getPosition=function(){
|
||||
return [
|
||||
Blockly.WidgetDiv.DIV.style.left,
|
||||
Blockly.WidgetDiv.DIV.style.top,
|
||||
Blockly.WidgetDiv.DIV.style.zIndex
|
||||
] // 画在这个位置刚好是颜色块下面
|
||||
}
|
||||
|
||||
var setValue=function(newValue){ // css颜色
|
||||
self.setValue(newValue)
|
||||
var c=new Colors();
|
||||
c.setColor(newValue)
|
||||
var rgbatext=`${c.colors.webSmart.r},${c.colors.webSmart.g},${c.colors.webSmart.b},${c.colors.alpha}` // 转成r,g,b,a文本
|
||||
pb.setFieldValue(rgbatext, targetf) // 放在颜色块左边的域中
|
||||
}
|
||||
|
||||
// 没看出来这个插件要怎么通过 getValue getPosition setValue 绑定
|
||||
|
||||
// 创建一个 input[type=color] 来选颜色
|
||||
|
||||
var a = document.createElement('input');
|
||||
a.setAttribute('type','color')
|
||||
a.setAttribute('value',getValue())
|
||||
a.oninput=function(){
|
||||
setValue(a.value)
|
||||
}
|
||||
a.dispatchEvent(new MouseEvent("click", {
|
||||
"view": window,
|
||||
"bubbles": true,
|
||||
"cancelable": false
|
||||
}));
|
||||
|
||||
return picker;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user