📄 moorainbow.js
字号:
}, eventKeys: function(e, el, id) { var wheel, type; id = (!id) ? el.id : this.arrHSB[0]; if (e.type == 'keydown') { if (e.key == 'up') wheel = 1; else if (e.key == 'down') wheel = -1; else return; } else if (e.type == Element.Events.mousewheel.base) wheel = (e.wheel > 0) ? 1 : -1; if (this.arrRGB.contains(el)) type = 'rgb'; else if (this.arrHSB.contains(el)) type = 'hsb'; else type = 'hsb'; if (type == 'rgb') { var rgb = this.sets.rgb, hsb = this.sets.hsb, prefix = this.options.prefix, pass; var value = (el.value.toInt() || 0) + wheel; value = (value > 255) ? 255 : (value < 0) ? 0 : value; switch(el.className) { case prefix + 'rInput': pass = [value, rgb[1], rgb[2]]; break; case prefix + 'gInput': pass = [rgb[0], value, rgb[2]]; break; case prefix + 'bInput': pass = [rgb[0], rgb[1], value]; break; default : pass = rgb; } this.manualSet(pass); this.fireEvent('onChange', [this.sets, this]); } else { var rgb = this.sets.rgb, hsb = this.sets.hsb, prefix = this.options.prefix, pass; var value = (el.value.toInt() || 0) + wheel; if (el.className.test(/(HueInput)/)) value = (value > 359) ? 0 : (value < 0) ? 0 : value; else value = (value > 100) ? 100 : (value < 0) ? 0 : value; switch(el.className) { case prefix + 'HueInput': pass = [value, hsb[1], hsb[2]]; break; case prefix + 'SatuInput': pass = [hsb[0], value, hsb[2]]; break; case prefix + 'BrighInput': pass = [hsb[0], hsb[1], value]; break; default : pass = hsb; } this.manualSet(pass, 'hsb'); this.fireEvent('onChange', [this.sets, this]); } e.stop(); }, eventKeydown: function(e, el) { var n = e.code, k = e.key; if ((!el.className.test(/hexInput/) && !(n >= 48 && n <= 57)) && (k!='backspace' && k!='tab' && k !='delete' && k!='left' && k!='right')) e.stop(); }, eventKeyup: function(e, el) { var n = e.code, k = e.key, pass, prefix, chr = el.value.charAt(0); if (!$chk(el.value)) return; if (el.className.test(/hexInput/)) { if (chr != "#" && el.value.length != 6) return; if (chr == '#' && el.value.length != 7) return; } else { if (!(n >= 48 && n <= 57) && (!['backspace', 'tab', 'delete', 'left', 'right'].contains(k)) && el.value.length > 3) return; } prefix = this.options.prefix; if (el.className.test(/(rInput|gInput|bInput)/)) { if (el.value < 0 || el.value > 255) return; switch(el.className){ case prefix + 'rInput': pass = [el.value, this.sets.rgb[1], this.sets.rgb[2]]; break; case prefix + 'gInput': pass = [this.sets.rgb[0], el.value, this.sets.rgb[2]]; break; case prefix + 'bInput': pass = [this.sets.rgb[0], this.sets.rgb[1], el.value]; break; default : pass = this.sets.rgb; } this.manualSet(pass); this.fireEvent('onChange', [this.sets, this]); } else if (!el.className.test(/hexInput/)) { if (el.className.test(/HueInput/) && el.value < 0 || el.value > 360) return; else if (el.className.test(/HueInput/) && el.value == 360) el.value = 0; else if (el.className.test(/(SatuInput|BrighInput)/) && el.value < 0 || el.value > 100) return; switch(el.className){ case prefix + 'HueInput': pass = [el.value, this.sets.hsb[1], this.sets.hsb[2]]; break; case prefix + 'SatuInput': pass = [this.sets.hsb[0], el.value, this.sets.hsb[2]]; break; case prefix + 'BrighInput': pass = [this.sets.hsb[0], this.sets.hsb[1], el.value]; break; default : pass = this.sets.hsb; } this.manualSet(pass, 'hsb'); this.fireEvent('onChange', [this.sets, this]); } else { pass = el.value.hexToRgb(true); if (isNaN(pass[0])||isNaN(pass[1])||isNaN(pass[2])) return; if ($chk(pass)) { this.manualSet(pass); this.fireEvent('onChange', [this.sets, this]); } } }, doLayout: function() { var id = this.options.id, prefix = this.options.prefix; var idPrefix = id + ' .' + prefix; this.layout = new Element('div', { 'styles': {'display': 'block', 'position': 'absolute'}, 'id': id }).inject(document.body); var box = new Element('div', { 'styles': {'position': 'relative'}, 'class': prefix + 'box' }).inject(this.layout); var div = new Element('div', { 'styles': {'position': 'absolute', 'overflow': 'hidden'}, 'class': prefix + 'overlayBox' }).inject(box); var ar = new Element('div', { 'styles': {'position': 'absolute', 'zIndex': 1}, 'class': prefix + 'arrows' }).inject(box); ar.width = ar.getStyle('width').toInt(); ar.height = ar.getStyle('height').toInt(); var ov = new Element('img', { 'styles': {'background-color': '#fff', 'position': 'relative', 'zIndex': 2}, 'src': this.options.imgPath + 'moor_woverlay.png', 'class': prefix + 'overlay' }).inject(div); var ov2 = new Element('img', { 'styles': {'position': 'absolute', 'top': 0, 'left': 0, 'zIndex': 2}, 'src': this.options.imgPath + 'moor_boverlay.png', 'class': prefix + 'overlay' }).inject(div); if (Browser.Engine.trident4) { div.setStyle('overflow', ''); var src = ov.src; ov.src = this.options.imgPath + 'blank.gif'; ov.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"; src = ov2.src; ov2.src = this.options.imgPath + 'blank.gif'; ov2.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"; } ov.width = ov2.width = div.getStyle('width').toInt(); ov.height = ov2.height = div.getStyle('height').toInt(); var cr = new Element('div', { 'styles': {'overflow': 'hidden', 'position': 'absolute', 'zIndex': 2}, 'class': prefix + 'cursor' }).inject(div); cr.width = cr.getStyle('width').toInt(); cr.height = cr.getStyle('height').toInt(); var sl = new Element('img', { 'styles': {'position': 'absolute', 'z-index': 2}, 'src': this.options.imgPath + 'moor_slider.png', 'class': prefix + 'slider' }).inject(box); this.layout.slider = sl; sl.width = sl.getStyle('width').toInt(); sl.height = sl.getStyle('height').toInt(); new Element('div', { 'styles': {'position': 'absolute'}, 'class': prefix + 'colorBox' }).inject(box); new Element('div', { 'styles': {'zIndex': 2, 'position': 'absolute'}, 'class': prefix + 'chooseColor' }).inject(box); this.layout.backup = new Element('div', { 'styles': {'zIndex': 2, 'position': 'absolute', 'cursor': 'pointer'}, 'class': prefix + 'currentColor' }).inject(box); var R = new Element('label').inject(box).setStyle('position', 'absolute'); var G = R.clone().inject(box).addClass(prefix + 'gLabel').set('html', 'G: '); var B = R.clone().inject(box).addClass(prefix + 'bLabel').set('html', 'B: '); R.set('html', 'R: ').addClass(prefix + 'rLabel'); var inputR = new Element('input'); var inputG = inputR.clone().inject(G).addClass(prefix + 'gInput'); var inputB = inputR.clone().inject(B).addClass(prefix + 'bInput'); inputR.inject(R).addClass(prefix + 'rInput'); var HU = new Element('label').inject(box).setStyle('position', 'absolute'); var SA = HU.clone().inject(box).addClass(prefix + 'SatuLabel').set('html', 'S: '); var BR = HU.clone().inject(box).addClass(prefix + 'BrighLabel').set('html', 'B: '); HU.set('html', 'H: ').addClass(prefix + 'HueLabel'); var inputHU = new Element('input'); var inputSA = inputHU.clone().inject(SA).addClass(prefix + 'SatuInput'); var inputBR = inputHU.clone().inject(BR).addClass(prefix + 'BrighInput'); inputHU.inject(HU).addClass(prefix + 'HueInput'); SA.innerHTML += " %"; BR.innerHTML += " %"; SP = new Element('span', {'styles': {'position': 'absolute'}, 'class': prefix + 'ballino'}) SP.innerHTML = " °" SP.inject(HU,'after'); var hex = new Element('label').inject(box).setStyle('position', 'absolute').addClass(prefix + 'hexLabel').set('html', '#hex: ').adopt(new Element('input').addClass(prefix + 'hexInput')); var ok = new Element('input', { 'styles': {'position': 'absolute'}, 'type': 'button', 'value': this.options.selectText, 'class': prefix + 'okButton' }).inject(box); this.rePosition(); var overlays = $$('#' + id + ' .' + prefix + 'overlay'); this.layout.overlay = overlays[0]; this.layout.overlay2 = overlays[1]; this.layout.cursor = cr; this.layout.arrows = ar; this.chooseColor = this.layout.getElement('.' + prefix + 'chooseColor'); this.RedInput = inputR; this.GreenInput = inputG; this.BlueInput = inputB; this.HueInput = inputHU; this.SatuInput = this.layout.getElement('.' + prefix + 'SatuInput'); this.BrighInput = this.layout.getElement('.' + prefix + 'BrighInput'); this.hexInput = this.layout.getElement('.' + prefix + 'hexInput');; this.arrRGB = [this.RedInput, this.GreenInput, this.BlueInput]; this.arrHSB = [this.HueInput, this.SatuInput, this.BrighInput]; this.okButton = ok; if (!Browser.Engine.webkit419) this.hide(); }, rePosition: function() { var coords = this.element.getCoordinates(); this.layout.setStyles({ 'left': coords.left, 'top': coords.top + coords.height + 1 }); }, snippet: function(mode, type) { var size; type = (type) ? type : 'none'; switch(mode) { case 'arrPos': var t = this.layout.arrows.getStyle('top').toInt(); size = t; break; case 'arrSize': var h = this.layout.arrows.height; h = (type == 'int') ? (h/2).toInt() : h; size = h; break; case 'curPos': var l = this.layout.cursor.getStyle('left').toInt(); var t = this.layout.cursor.getStyle('top').toInt(); size = {'l': l, 't': t}; break; case 'slider': var t = this.layout.slider.getStyle('marginTop').toInt(); size = t; break; default : var h = this.layout.cursor.height; var w = this.layout.cursor.width; h = (type == 'int') ? (h/2).toInt() : h; w = (type == 'int') ? (w/2).toInt() : w; size = {w: w, h: h}; }; return size; }});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -