How to use rev method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

tp-color-picker.min.js

Source:tp-color-picker.min.js Github

copy

Full Screen

1;window.RevColor = {2 3 defaultValue: '#ffffff',4 get: function(val) {5 6 if(!val) return 'transparent';7 return RevColor.process(val, true)[0];8 9 },10 11 parse: function(val, prop, returnColorType) {12 13 val = RevColor.process(val, true);14 var ar = [];15 16 if(!prop) ar[0] = val[0]; 17 else ar[0] = prop + ': ' + val[0] + ';';18 19 if(returnColorType) ar[1] = val[1];20 return ar;21 22 },23 24 convert: function(color, opacity) {25 26 if(!color) return RevColor.defaultValue;27 if(color === 'transparent') return color;28 if(color.search(/\[\{/) !== -1 || color.search('gradient') !== -1) return RevColor.process(color, true)[0];29 if(color.length === 3 || color.replace('#', '').length === 3) color = RevColor.sanitizeHex(color);30 if(typeof opacity === 'undefined' || isNaN(opacity)) return RevColor.process(color, true)[0];31 32 opacity = parseFloat(opacity);33 if(opacity <= 1) opacity *= 100;34 35 opacity = Math.max(Math.min(parseInt(opacity, 10), 100), 0);36 37 if(opacity === 0) return 'transparent';38 if(color.search('#') !== -1) {39 40 return RevColor.processRgba(RevColor.sanitizeHex(color), opacity);41 42 }43 else {44 45 color = RevColor.rgbValues(color, 3);46 return RevColor.rgbaString(color[0], color[1], color[2], opacity * 0.01);47 48 }49 50 },51 52 process: function(clr, processColor) {53 54 if(typeof clr !== 'string') {55 56 if(processColor) clr = RevColor.sanitizeGradient(clr);57 return [RevColor.processGradient(clr), 'gradient', clr];58 59 }60 else if(clr.trim() === 'transparent') {61 62 return ['transparent', 'transparent'];63 64 }65 else if(clr.search(/\[\{/) !== -1) {66 67 try {68 69 clr = JSON.parse(clr.replace(/\&/g, '"'));70 if(processColor) clr = RevColor.sanitizeGradient(clr); 71 return [RevColor.processGradient(clr), 'gradient', clr];72 73 }74 catch(e) {75 76 console.log('RevColor.process() failed to parse JSON string');77 return [78 79 'linear-gradient(0deg, rgba(255, 255, 255, 1) 0%, rgba(0, 0, 0, 1) 100%)', 80 'gradient', {81 82 'type': 'linear', 83 'angle': '0', 84 'colors': [85 86 {'r': '255', 'g': '255', 'b': '255', 'a': '1', 'position': '0', 'align': 'bottom'}, 87 {'r': '0', 'g': '0', 'b': '0', 'a': '1', 'position': '100', 'align': 'bottom'}88 89 ]90 }91 ];92 }93 94 }95 else if(clr.search('#') !== -1) {96 97 return [RevColor.sanitizeHex(clr), 'hex'];98 99 }100 else if(clr.search('rgba') !== -1) {101 102 return [clr.replace(/\s/g, ''), 'rgba'];103 104 }105 else {106 107 return [clr.replace(/\s/g, ''), 'rgb'];108 109 }110 111 },112 113 transparentRgba: function(val, processed) {114 115 if(!processed) {116 117 var tpe = RevColor.process(val)[1];118 if(tpe !== 'rgba') return false;119 120 }121 122 return RevColor.rgbValues(val, 4)[3] === '0';123 124 },125 126 rgbValues: function(values, num) {127 128 values = values.substring(values.indexOf('(') + 1, values.lastIndexOf(')')).split(',');129 if(values.length === 3 && num === 4) values[3] = '1';130 131 for(var i = 0; i < num; i++) values[i] = values[i].trim();132 return values;133 134 },135 136 rgbaString: function(r, g, b, a) {137 138 return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + a + ')';139 140 },141 142 rgbToHex: function(clr) {143 144 var values = RevColor.rgbValues(clr, 3);145 return RevColor.getRgbToHex(values[0], values[1], values[2]);146 147 },148 149 rgbaToHex: function(clr) {150 151 var values = RevColor.rgbValues(clr, 4);152 return [RevColor.getRgbToHex(values[0], values[1], values[2]), values[3]];153 154 },155 156 getOpacity: function(val) {157 158 return parseInt(RevColor.rgbValues(val, 4)[3] * 100, 10) + '%';159 160 },161 162 getRgbToHex: function(r, g, b) {163 164 return '#' + ("0" + parseInt(r).toString(16)).slice(-2) + 165 ("0" + parseInt(g).toString(16)).slice(-2) + 166 ("0" + parseInt(b).toString(16)).slice(-2);167 168 },169 170 joinToRgba:function(val) {171 172 val = val.split('||');173 return RevColor.convert(val[0], val[1]);174 175 },176 177 processRgba: function(hex, opacity) {178 179 hex = hex.replace('#', '');180 181 var hasOpacity = typeof opacity !== 'undefined',182 rgb = hasOpacity ? 'rgba' : 'rgb',183 color = rgb + '(' + 184 parseInt(hex.substring(0, 2), 16) + ', ' + 185 parseInt(hex.substring(2, 4), 16) + ', ' + 186 parseInt(hex.substring(4, 6), 16);187 188 if(hasOpacity) color += ', ' + (parseInt(opacity, 10) * 0.01).toFixed(2).replace(/\.?0*$/, '') + ')';189 else color += ')';190 191 return color;192 193 },194 195 processGradient: function(obj) {196 var tpe = obj.type,197 begin = tpe + '-gradient(',198 middle = tpe === 'linear' ? obj.angle + 'deg, ' : 'ellipse at center, ',199 colors = obj.colors,200 len = colors.length,201 end = '',202 clr;203 204 for(var i = 0; i < len; i++) {205 206 if(i > 0) end += ', ';207 clr = colors[i];208 end += 'rgba(' + clr.r + ', ' + clr.g + ', ' + clr.b + ', ' + clr.a + ') ' + clr.position + '%';209 210 }211 212 return begin + middle + end + ')';213 214 },215 216 sanitizeHex: function(hex) {217 218 hex = hex.replace('#', '').trim();219 if(hex.length === 3) {220 221 var a = hex.charAt(0),222 b = hex.charAt(1),223 c = hex.charAt(2);224 225 hex = a + a + b + b + c + c;226 227 }228 229 return '#' + hex;230 231 },232 233 sanitizeGradient: function(obj) {234 var colors = obj.colors,235 len = colors.length,236 ar = [],237 prev;238 239 for(var i = 0; i < len; i++) {240 241 var cur = colors[i];242 delete cur.align;243 244 if(prev) {245 246 if(JSON.stringify(cur) !== JSON.stringify(prev)) {247 248 ar[ar.length] = cur;249 250 }251 252 }253 else {254 255 ar[ar.length] = cur;256 257 }258 259 prev = cur;260 261 }262 263 obj.colors = ar;264 return obj;265 266 }267 268};269(function($) {270 271 var doc,272 angle,273 inited,274 bodies,275 isFull,276 points,277 radial,278 hitTop,279 onEdit,280 onInit,281 onAjax,282 cPicker,283 prepped,284 reverse,285 gradBtn,286 gradHex,287 defMode,288 inFocus,289 defEdit,290 defAjax,291 colorBox,292 colorBtn,293 colorHex,294 colorLoc,295 gradIris,296 blankRow,297 curPoint,298 appended,299 gradCore,300 onCancel,301 defCancel,302 defChange,303 dragPoint,304 topPoints,305 botPoints,306 hitBottom,307 textareas,308 curSquare,309 curCorner,310 colorIris,311 langColor,312 gradInput,313 onReverse,314 wheelDown,315 editTitle,316 angleWheel,317 wheelPoint,318 gradOutput,319 colorClear,320 directions,321 pointIndex,322 opacityLoc,323 gradViewed,324 wheelActive,325 gradOpacity,326 groupPoints,327 pointerWrap,328 gradSection,329 colorDelete,330 curLanguage,331 customAdded,332 defWidgetId,333 selectedHex,334 currentInput,335 presetGroups,336 colorSection,337 colorOpacity,338 openingValue,339 openingColor,340 appendedHTML,341 currentColor,342 supressColor,343 supressWheel,344 supressCheck,345 isTransparent,346 mainContainer,347 opacityDelete,348 selectedColor,349 opacitySlider,350 supressOpacity,351 currentEditing,352 defaultClasses,353 changeCallback,354 gradientPreview = {},355 isColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i;356 357 var hitWidth = 265,358 maxPoints = 20,359 centerWheel = 30,360 minGradRows = 6,361 minColorRows = 5,362 presetColumns = 6,363 deleteBuffer = 10,364 warningBuffer = 15,365 sliderHeight = 180,366 dragObj = {axis: "x", containment: "#rev-cpicker-point-wrap"};367 368 var lang = {369 370 'color': 'Color',371 'solid_color': 'Solid Color',372 'gradient_color': 'Gradient Color',373 'currently_editing': 'Currently Editing',374 'core_presets': 'Core Presets',375 'custom_presets': 'Custom Presets',376 'enter_a_name': 'Enter a Name',377 'save_a_new_preset': 'Save a new Preset',378 'save': 'Save',379 'color_hex_value': 'Color Hex Value',380 'opacity': 'Opacity',381 'clear': 'Clear',382 'location': 'Location',383 'delete': 'Delete',384 'horizontal': 'Horizontal',385 'vertical': 'Vertical',386 'radial': 'Radial',387 'enter_angle': 'Enter Angle',388 'reverse_gradient': 'Reverse Gradient',389 'delete_confirm': 'Remove/Delete this custom preset color?',390 'naming_error': 'Please enter a unique name for the new color preset'391 392 };393 394 var defColors = ['#FFFFFF', '#000000', '#FF3A2D', '#007AFF', '#4CD964', '#FFCC00', '#C7C7CC', '#8E8E93', '#FFD3E0', '#34AADC', '#E0F8D8', '#FF9500'];395 396 var defGradients = [397 398 {'0': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:247,&g&:247,&b&:247,&a&:&1&,&position&:0,&align&:&top&},{&r&:247,&g&:247,&b&:247,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:215,&g&:215,&b&:215,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:215,&g&:215,&b&:215,&a&:&1&,&position&:100,&align&:&top&}]}'},399 {'1': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:74,&g&:74,&b&:74,&a&:&1&,&position&:0,&align&:&top&},{&r&:74,&g&:74,&b&:74,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:43,&g&:43,&b&:43,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:43,&g&:43,&b&:43,&a&:&1&,&position&:100,&align&:&top&}]}'},400 {'2': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:219,&g&:221,&b&:222,&a&:&1&,&position&:0,&align&:&top&},{&r&:219,&g&:221,&b&:222,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:137,&g&:140,&b&:144,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:137,&g&:140,&b&:144,&a&:&1&,&position&:100,&align&:&top&}]}'},401 {'3': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:26,&g&:214,&b&:253,&a&:&1&,&position&:0,&align&:&top&},{&r&:26,&g&:214,&b&:253,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:29,&g&:98,&b&:240,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:29,&g&:98,&b&:240,&a&:&1&,&position&:100,&align&:&top&}]}'},402 {'4': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:198,&g&:68,&b&:252,&a&:&1&,&position&:0,&align&:&top&},{&r&:198,&g&:68,&b&:252,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:88,&g&:86,&b&:214,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:88,&g&:86,&b&:214,&a&:&1&,&position&:100,&align&:&top&}]}'},403 {'5': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:255,&g&:94,&b&:58,&a&:&1&,&position&:0,&align&:&top&},{&r&:255,&g&:94,&b&:58,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:255,&g&:42,&b&:104,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:255,&g&:42,&b&:104,&a&:&1&,&position&:100,&align&:&top&}]}'},404 {'6': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:228,&g&:221,&b&:202,&a&:&1&,&position&:0,&align&:&top&},{&r&:228,&g&:221,&b&:202,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:214,&g&:206,&b&:195,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:214,&g&:206,&b&:195,&a&:&1&,&position&:100,&align&:&top&}]}'},405 {'7': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:255,&g&:219,&b&:76,&a&:&1&,&position&:0,&align&:&top&},{&r&:255,&g&:219,&b&:76,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:255,&g&:205,&b&:2,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:255,&g&:205,&b&:2,&a&:&1&,&position&:100,&align&:&top&}]}'},406 {'8': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:255,&g&:149,&b&:0,&a&:&1&,&position&:0,&align&:&top&},{&r&:255,&g&:149,&b&:0,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:255,&g&:94,&b&:58,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:255,&g&:94,&b&:58,&a&:&1&,&position&:100,&align&:&top&}]}'},407 {'9': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:82,&g&:237,&b&:199,&a&:&1&,&position&:0,&align&:&top&},{&r&:82,&g&:237,&b&:199,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:90,&g&:200,&b&:251,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:90,&g&:200,&b&:251,&a&:&1&,&position&:100,&align&:&top&}]}'},408 {'10': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:228,&g&:183,&b&:240,&a&:&1&,&position&:0,&align&:&top&},{&r&:228,&g&:183,&b&:240,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:200,&g&:110,&b&:223,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:200,&g&:110,&b&:223,&a&:&1&,&position&:100,&align&:&top&}]}'},409 {'11': '{&type&:&linear&,&angle&:&180&,&colors&:[{&r&:135,&g&:252,&b&:112,&a&:&1&,&position&:0,&align&:&top&},{&r&:135,&g&:252,&b&:112,&a&:&1&,&position&:0,&align&:&bottom&},{&r&:11,&g&:211,&b&:24,&a&:&1&,&position&:100,&align&:&bottom&},{&r&:11,&g&:211,&b&:24,&a&:&1&,&position&:100,&align&:&top&}]}'}410 411 ];412 413 var markup = 414 415 '<div id="rev-cpicker-back" class="rev-cpicker-close"></div>' + 416 417 '<div id="rev-cpicker">' + 418 419 '<div id="rev-cpicker-head">' + 420 421 '<div id="rev-cpicker-drag" class="rev-cpicker-draggable"></div>' + 422 '<span id="rev-cpicker-color-btn" class="rev-cpicker-main-btn" data-text="solid_color"></span>' + 423 '<span id="rev-cpicker-gradient-btn" class="rev-cpicker-main-btn" data-text="gradient_color"></span>' + 424 425 '<div id="rev-cpicker-editing" class="rev-cpicker-draggable">' + 426 '<span id="rev-cpicker-edit-title" data-text="currently_editing"></span>' + 427 '<span id="rev-cpicker-current-edit"></span>' + 428 '</div>' + 429 430 '<span id="rev-cpicker-exit" class="rev-cpicker-close"></span>' + 431 432 '</div>' + 433 434 '<div id="rev-cpicker-section-left" class="rev-cpicker-section">' + 435 436 '<div id="rev-cpicker-body">' + 437 438 '<div id="rev-cpicker-colors" class="rev-cpicker-type">' + 439 440 '<div class="rev-cpicker-column rev-cpicker-column-left"> ' + 441 442 '<div class="rev-cpicker-column-inner-left">' + 443 444 '<div class="rev-cpicker-presets">' + 445 446 '<span id="rev-cpicker-colors-core-btn" class="rev-cpicker-preset-title rev-cpicker-preset-title-core selected">' + 447 '<span data-text="core_presets"></span> ' + 448 '<span class="rev-cpicker-arrow rev-cpicker-arrow-down"></span>' + 449 '<span class="rev-cpicker-arrow rev-cpicker-arrow-up"></span>' + 450 '</span>' + 451 452 '<span id="rev-cpicker-colors-custom-btn" class="rev-cpicker-preset-title rev-cpicker-preset-title-custom">' + 453 '<span data-text="custom_presets"></span> ' + 454 '<span class="rev-cpicker-arrow rev-cpicker-arrow-down"></span>' + 455 '<span class="rev-cpicker-arrow rev-cpicker-arrow-up"></span>' + 456 '</span>' + 457 458 '<div id="rev-cpicker-colors-core" class="rev-cpicker-presets-group"></div>' + 459 '<div id="rev-cpicker-colors-custom" class="rev-cpicker-presets-group rev-cpicker-presets-custom"></div>' + 460 461 '</div>' + 462 463 '<div class="rev-cpicker-iris">' + 464 465 '<input id="rev-cpicker-iris-color" class="rev-cpicker-iris-input" value="#ffffff" />' + 466 467 '<div id="rev-cpicker-scroller" class="iris-slider iris-strip">' +468 '<div id="rev-cpicker-scroll-bg"></div>' + 469 '<div id="rev-cpicker-scroll" class="iris-slider-offset"></div>' +470 '</div>' +471 472 '</div>' + 473 474 '</div>' + 475 476 '</div>' + 477 478 '<div class="rev-cpicker-column rev-cpicker-column-right">' + 479 480 '<div class="rev-cpicker-column-inner-right">' + 481 482 '<div>' + 483 484 '<span data-text="save_a_new_preset"></span>' + 485 486 '<div class="rev-cpicker-presets-save-as">' + 487 488 '<input type="text" class="rev-cpicker-preset-save" placeholder="" data-placeholder="enter_a_name" />' + 489 '<span class="rev-cpicker-btn rev-cpicker-save-preset-btn" data-alert="naming_error">' + 490 '<span class="rev-cpicker-save-icon"></span>' + 491 '<span class="rev-cpicker-preset-save-text" data-text="save"></span>' + 492 '</span>' + 493 494 '</div>' + 495 496 '</div>' + 497 498 '<div class="rev-cpicker-meta">' + 499 500 '<span data-text="color_hex_value"></span>' + 501 '<br>' + 502 '<input type="text" id="rev-cpicker-color-hex" class="rev-cpicker-input rev-cpicker-hex" value="#ffffff" />' + 503 '<br>' + 504 '<span data-text="opacity"></span>' +505 '<br>' + 506 '<input type="text" id="rev-cpicker-color-opacity" class="rev-cpicker-input rev-cpicker-opacity-input" value="100%" />' + 507 '<span id="rev-cpciker-clear-hex" class="rev-cpicker-btn rev-cpicker-btn-small rev-cpciker-clear" data-text="clear"></span>' + 508 509 '</div>' + 510 511 '</div>' + 512 513 '</div>' + 514 '</div>' + 515 516 '<div id="rev-cpicker-gradients" class="rev-cpicker-type">' + 517 518 '<div class="rev-cpicker-column rev-cpicker-column-left"> ' + 519 520 '<div class="rev-cpicker-column-inner-left">' + 521 522 '<div class="rev-cpicker-presets">' + 523 524 '<span id="rev-cpicker-gradients-core-btn" class="rev-cpicker-preset-title rev-cpicker-preset-title-core selected">' + 525 '<span data-text="core_presets"></span> ' + 526 '<span class="rev-cpicker-arrow rev-cpicker-arrow-down"></span>' + 527 '<span class="rev-cpicker-arrow rev-cpicker-arrow-up"></span>' + 528 '</span>' + 529 530 '<span id="rev-cpicker-gradients-custom-btn" class="rev-cpicker-preset-title rev-cpicker-preset-title-custom">' + 531 '<span data-text="custom_presets"></span> ' + 532 '<span class="rev-cpicker-arrow rev-cpicker-arrow-down"></span>' + 533 '<span class="rev-cpicker-arrow rev-cpicker-arrow-up"></span>' + 534 '</span>' + 535 536 '<div id="rev-cpicker-gradients-core" class="rev-cpicker-presets-group"></div>' + 537 '<div id="rev-cpicker-gradients-custom" class="rev-cpicker-presets-group rev-cpicker-presets-custom"></div>' + 538 539 '</div>' + 540 541 '<div class="rev-cpicker-gradient-block">' + 542 543 '<div id="rev-cpicker-gradient-input" class="rev-cpicker-gradient-builder">' + 544 545 '<span id="rev-cpicker-hit-top" class="rev-cpicker-builder-hit"></span>' + 546 '<div id="rev-cpicker-point-wrap">' + 547 '<div id="rev-cpciker-point-container"></div>' + 548 '</div>' + 549 '<span id="rev-cpicker-hit-bottom" class="rev-cpicker-builder-hit"></span>' + 550 551 '</div>' + 552 553 '<div class="rev-cpicker-meta-row-wrap">' + 554 555 '<div class="rev-cpicker-meta-row">' + 556 557 '<div><label data-text="opacity"></label><input type="text" id="rev-cpicker-grad-opacity" class="rev-cpicker-point-input rev-cpicker-opacity-input" value="100%" disabled /></div>' + 558 '<div><label data-text="location"></label><input type="text" id="rev-cpicker-opacity-location" class="rev-cpicker-point-input rev-cpicker-point-location" value="100%" disabled /></div>' + 559 '<div><label>&nbsp;</label><span class="rev-cpicker-btn rev-cpicker-btn-small rev-cpicker-point-delete" id="rev-cpicker-opacity-delete" data-text="delete">{{delete}}</span></div>' + 560 561 '</div>' + 562 563 '<div class="rev-cpicker-meta-row">' + 564 565 '<div><label data-text="color"></label><span class="rev-cpicker-point-input" id="rev-cpicker-color-box"></span></div>' + 566 '<div><label data-text="location"></label><input type="text" id="rev-cpicker-color-location" class="rev-cpicker-point-input rev-cpicker-point-location" value="100%" disabled /></div>' + 567 '<div><label>&nbsp;</label><span class="rev-cpicker-btn rev-cpicker-btn-small rev-cpicker-point-input rev-cpicker-point-delete" id="rev-cpicker-color-delete" data-text="delete">{{delete}}</span></div>' + 568 569 '</div>' + 570 571 '</div>' + 572 573 '</div>' + 574 575 '</div>' + 576 577 '</div>' + 578 579 '<div class="rev-cpicker-column rev-cpicker-column-right">' + 580 581 '<div class="rev-cpicker-column-inner-right">' + 582 583 '<div>' + 584 585 '<span data-text="save_a_new_preset"></span>' + 586 587 '<div class="rev-cpicker-presets-save-as">' + 588 589 '<input type="text" class="rev-cpicker-preset-save" placeholder="" data-placeholder="enter_a_name" />' + 590 '<span class="rev-cpicker-btn rev-cpicker-save-preset-btn" data-alert="naming_error">' + 591 '<span class="rev-cpicker-save-icon"></span>' + 592 '<span class="rev-cpicker-preset-save-text" data-text="save"></span>' + 593 '</span>' + 594 595 '</div>' + 596 597 '</div>' + 598 599 '<div class="rev-cpicker-gradient-block">' + 600 601 '<div id="rev-cpicker-gradient-output" class="rev-cpicker-gradient-builder"></div>' + 602 603 '</div>' + 604 605 '<div class="rev-cpicker-meta-row-wrap">' + 606 607 '<div class="rev-cpicker-meta-row">' + 608 609 '<div><label>Orientation</label>' + 610 611 '<span id="rev-cpicker-orientation-horizontal" class="rev-cpicker-btn rev-cpicker-btn-small rev-cpicker-orientation" data-direction="90" data-text="horizontal"></span>' + 612 '<span id="rev-cpicker-orientation-vertical" class="rev-cpicker-btn rev-cpicker-btn-small rev-cpicker-orientation" data-direction="180" data-text="vertical"></span>' + 613 '<span id="rev-cpicker-orientation-radial" class="rev-cpicker-btn rev-cpicker-btn-small rev-cpicker-orientation" data-direction="radial" data-text="radial"></span>' + 614 615 '</div>' + 616 617 '</div>' + 618 619 '<div class="rev-cpicker-meta-row rev-cpicker-meta-row-push">' + 620 621 '<div>' + 622 '<label data-text="enter_angle"></label>' + 623 '<div id="rev-cpicker-angle-container">' + 624 '<input type="text" class="rev-cpicker-input" id="rev-cpicker-meta-angle" value="" />' + 625 '<div id="rev-cpicker-wheel">' + 626 '<div id="rev-cpicker-wheel-inner"><span id="rev-cpicker-wheel-point"></span></div>' + 627 '</div>' + 628 '</div>' + 629 '</div>' + 630 '<div><label data-text="reverse_gradient"></label><span id="rev-cpicker-meta-reverse"></span></div>' + 631 632 '</div>' + 633 634 '</div>' + 635 636 '</div>' + 637 638 '</div>' + 639 640 '</div>' + 641 642 '</div>' + 643 644 '</div>' + 645 646 '<span id="rev-cpicker-check"></span>' + 647 648 '<div id="rev-cpicker-section-right" class="rev-cpicker-section">' + 649 650 '<div class="rev-cpicker-iris">' + 651 652 '<input id="rev-cpicker-iris-gradient" class="rev-cpicker-iris-input" value="#ffffff" />' + 653 654 '</div>' + 655 656 '<div class="rev-cpicker-fields">' + 657 658 '<input type="text" id="rev-cpicker-gradient-hex" class="rev-cpicker-input rev-cpicker-hex" value="#ffffff" />' + 659 '<span id="rev-cpciker-clear-gradient" class="rev-cpicker-btn rev-cpicker-btn-small rev-cpciker-clear" data-text="clear"></span>' + 660 '<span id="rev-cpicker-check-gradient" class="rev-cpicker-btn"></span>' + 661 662 '</div>' + 663 664 '</div>' + 665 666 '<span id="rev-cpicker-remove-delete"></span>' + 667 '</div>';668 669 function changeDegree(grad, deg) {670 671 grad = grad.split('(');672 673 var begin = grad[0];674 grad.shift();675 676 var end = grad.join('(').split(','); 677 end.shift();678 679 deg = typeof deg !== 'undefined' ? deg + 'deg,' : 'ellipse at center,';680 return begin + '(' + deg + end.join(',');681 682 }683 684 function gradientView(val) {685 return changeDegree(val.replace('radial-', 'linear-'), '90');686 687 }688 689 function replaceText() {690 691 this.innerHTML = curLanguage[getAttribute(this, 'data-text')];692 693 }694 695 function replaceHolder() {696 697 this.setAttribute('placeholder', curLanguage[getAttribute(this, 'data-placeholder')]);698 699 }700 701 function replaceAlert() {702 703 this.setAttribute('data-message', curLanguage[getAttribute(this, 'data-alert')]);704 705 }706 707 function getAttribute(el, attr) {708 709 return el.getAttribute(attr) || '';710 711 }712 713 function writeLanguage(language) {714 715 if(!language) language = {};716 if(typeof language === 'string') language = JSON.parse(language.replace(/\&/g, '"'));717 718 curLanguage = $.extend({}, lang, language);719 langColor = curLanguage.color;720 721 cPicker.find('*[data-placeholder]').each(replaceHolder);722 cPicker.find('*[data-alert]').each(replaceAlert);723 cPicker.find('*[data-text]').each(replaceText);724 725 }726 727 function newPreset(val, core, cls, grad) {728 729 var titl,730 obj,731 el;732 733 if(!$.isPlainObject(val)) {734 735 titl = val;736 737 }738 else {739 740 var angl,741 tpe;742 743 for(var prop in val) {744 745 if(!val.hasOwnProperty(prop)) continue;746 747 val = val[prop];748 if(typeof val === 'string') {749 750 val = RevColor.process(val);751 if(val[1] === 'gradient') {752 753 obj = val[2];754 angl = obj.angle;755 tpe = obj.type;756 757 }758 759 val = val[0];760 761 }762 else {763 764 angl = val.angle;765 tpe = val.type;766 767 }768 769 if(!isNaN(prop)) {770 771 titl = tpe !== 'radial' ? angl + '&deg;' : 'radial';772 773 } 774 else {775 776 titl = prop.replace(/_/g, ' ').replace(/\b\w/g, function(chr) {return chr.toUpperCase();});777 778 }779 780 }781 782 }783 784 if(val !== 'blank') {785 786 var datas;787 if($.isPlainObject(val)) {788 789 obj = val;790 datas = '';791 val = grad || RevColor.processGradient(val); 792 793 }794 795 var shell = '<span class="rev-cpicker-color tptip' + cls + '" data-title="' + titl + '" data-color="' + val + '">' + 796 '<span class="rev-cpicker-preset-tile"></span>' + 797 '<span class="rev-cpicker-preset-bg" style="background: ' + val + '"></span>';798 799 if(!core) shell += '<span class="rev-cpicker-delete"><span class="rev-cpicker-delete-icon"></span></span>';800 shell += '</span>';801 802 el = $(shell);803 if(obj) el.data('gradient', obj);804 return el[0];805 806 }807 else {808 809 el = document.createElement('span');810 el.className = 'rev-cpicker-color blank';811 return el;812 813 }814 815 }816 817 function checkPreset() {818 819 var presetColor = getAttribute(this, 'data-color').toLowerCase(),820 toCheck = !supressCheck ? presetColor === openingColor.toLowerCase() : false;821 822 if(presetColor === selectedHex || toCheck) {823 824 var $this = $(this);825 $this.closest('.rev-cpicker-presets-group').find('.rev-cpicker-color.selected').removeClass('selected');826 827 selectedColor = $this.addClass('selected');828 return false;829 830 }831 832 }833 834 function writePresets(container, colors) {835 836 var frag = document.createDocumentFragment(),837 core = container.search('core') !== -1,838 cls = core ? '' : ' rev-picker-color-custom',839 len = colors.length,840 minRows = container.search('colors') !== -1 ? minColorRows : minGradRows,841 rows = Math.max(Math.ceil(len / presetColumns), minRows);842 843 for(var i = 0; i < rows; i++) {844 845 while(colors.length < ((i + 1) * presetColumns)) colors[colors.length] = 'blank';846 847 }848 849 len = colors.length;850 for(i = 0; i < len; i++) {851 frag.appendChild(newPreset(colors[i], core, cls));852 853 }854 855 return ['rev-cpicker-' + container, frag];856 857 }858 859 function onChange(gradient, color, trans) {860 861 if(!currentColor) return;862 if(!gradient) {863 864 var hex = color || colorHex.val(),865 opacity = typeof trans !== 'undefined' ? trans : colorOpacity.val();866 867 if(hex === 'transparent') color = 'transparent';868 else if(opacity === '100%') color = RevColor.sanitizeHex(hex);869 else color = RevColor.processRgba(hex, opacity);870 871 }872 873 var isTrans = color === 'transparent',874 val = !isTrans ? color : '';875 876 if(!gradient) colorBtn.data('state', color);877 else gradBtn.data('state', color);878 879 if(!isTrans) currentColor[0].style.background = val;880 else currentColor.css('background', val);881 882 if(onEdit) onEdit(currentInput, color);883 doc.trigger('revcolorpickerupdate', [currentInput, color]);884 885 }886 887 function setValue(val, fromPreset) {888 889 var obj = RevColor.process(val),890 type = obj[1],891 clr = obj[0];892 893 if(isFull) reverse.removeClass('checked');894 if(type !== 'gradient') {895 896 switch(type) {897 898 case 'hex':899 900 val = RevColor.sanitizeHex(clr);901 colorOpacity.val('100%');902 updateSlider(100);903 904 break;905 906 case 'rgba': 907 908 var values = RevColor.rgbaToHex(clr),909 opacity = parseInt(values[1] * 100, 10);910 val = values[0];911 912 colorOpacity.val(opacity + '%');913 updateSlider(opacity);914 915 break;916 917 case 'rgb':918 919 val = RevColor.rgbToHex(clr);920 colorOpacity.val('100%');921 updateSlider(100);922 923 break;924 925 default:926 927 colorClear.click();928 colorBtn.click();929 930 // end default931 932 }933 934 colorIris.val(val).change();935 if(!fromPreset) colorBtn.click();936 937 }938 else {939 940 if(isFull) {941 942 buildGradientInput(obj[2]);943 buildGradientOutput();944 945 if(!fromPreset) {946 947 gradViewed = true;948 gradBtn.click();949 950 }951 952 }953 else {954 955 colorIris.val(RevColor.defaultValue).change();956 colorBtn.click();957 958 }959 960 }961 962 return [clr, type];963 964 }965 966 function getSibling(align, x) {967 968 var locations = points.slice(),969 len = locations.length,970 pnt;971 972 locations.sort(sortPoints);973 while(len--) {974 975 pnt = locations[len];976 if(pnt.align === align && pnt.x < x) return pnt;977 978 }979 980 len = locations.length;981 for(var i = 0; i < len; i++) {982 983 pnt = locations[i];984 if(pnt.align === align && pnt.x > x) return pnt;985 986 }987 988 }989 990 function clonePoint(align, pos) {991 992 var sibling = getSibling(align, pos),993 clr = sibling.color,994 bg = getBgVal(clr, align, true),995 rgb = getRgbVal(clr, true);996 997 var pnt = newPoint(align, pos, rgb, bg);998 if(curPoint) curPoint.removeClass('active');999 1000 curPoint = $(pnt).addClass('active').appendTo(pointerWrap).draggable(dragObj);1001 curSquare = curPoint.children('.rev-cpicker-point-square')[0];1002 curCorner = curPoint.children('.rev-cpicker-point-triangle')[0];1003 groupPoints = pointerWrap.children();1004 1005 var grad = activatePoint(pos);1006 buildGradientOutput(pnt);1007 1008 if(align === 'bottom') gradIris.val(grad[1]).change();1009 1010 }1011 1012 function activatePoint(pointX) {1013 1014 if(typeof pointX === 'undefined') pointX = points[pointIndex].x;1015 1016 var color = curPoint.attr('data-color'),1017 bottom = curPoint.hasClass('rev-cpicker-point-bottom');1018 1019 if(bottom) {1020 1021 if(opacityDelete.hasClass('active')) {1022 1023 gradOpacity.attr('disabled', 'disabled');1024 opacityLoc.attr('disabled', 'disabled');1025 opacityDelete.removeClass('active');1026 1027 }1028 1029 color = RevColor.rgbaToHex(color)[0];1030 colorBox.css('background', color);1031 colorLoc.removeAttr('disabled').val(pointX + '%');1032 1033 if(cPicker.find('.rev-cpicker-point-bottom').length > 2) { 1034 colorDelete.addClass('active');1035 }1036 1037 cPicker.addClass('open');1038 1039 }1040 else {1041 1042 if(colorDelete.hasClass('active')) {1043 1044 colorBox.css('background', '');1045 colorLoc.attr('disabled', 'disabled');1046 colorDelete.removeClass('active');1047 1048 }1049 1050 var opacity = RevColor.getOpacity(color);1051 gradOpacity.attr('data-opacity', opacity).val(opacity).removeAttr('disabled');1052 opacityLoc.val(pointX + '%').removeAttr('disabled');1053 1054 if(cPicker.find('.rev-cpicker-point-top').length > 2) { 1055 opacityDelete.addClass('active');1056 }1057 1058 cPicker.removeClass('open');1059 1060 }1061 1062 return [bottom, color];1063 1064 }1065 1066 function getBgVal(clr, align, cloned) {1067 1068 if(align === 'bottom') return 'rgb(' + clr.r + ',' + clr.g + ',' + clr.b + ')';1069 var opacity = !cloned ? clr.a : '1';1070 return 'rgba(0, 0, 0, ' + opacity + ')';1071 1072 }1073 1074 function getRgbVal(clr, cloned) {1075 1076 var opacity = !cloned ? clr.a : '1';1077 return 'rgba(' + clr.r + ',' + clr.g + ',' + clr.b + ',' + opacity + ')';1078 1079 }1080 1081 function setPoints(colors) {1082 1083 var frag = document.createDocumentFragment(),1084 len = colors.length,1085 align,1086 clr; 1087 1088 for(var i = 0; i < len; i++) {1089 1090 clr = colors[i];1091 align = clr.align;1092 frag.appendChild(1093 1094 newPoint(1095 1096 align, 1097 clr.position, 1098 getRgbVal(clr), 1099 getBgVal(clr, align)1100 1101 )1102 1103 );1104 1105 }1106 1107 if(groupPoints) groupPoints.draggable('destroy');1108 pointerWrap.empty().append(frag);1109 groupPoints = pointerWrap.children().draggable(dragObj);1110 1111 }1112 1113 function newPoint(align, pos, val, bg) {1114 1115 var el = document.createElement('span');1116 el.className = 'rev-cpicker-point rev-cpicker-point-' + align;1117 1118 if(typeof val === 'string') el.setAttribute('data-color', val);1119 else $(el).data('gradient', val);1120 1121 el.setAttribute('data-location', pos);1122 el.style.left = pos + '%';1123 1124 if(align === 'bottom') {1125 1126 el.innerHTML = 1127 '<span class="rev-cpicker-point-triangle" style="border-bottom-color: ' + bg + '"></span>' + 1128 '<span class="rev-cpicker-point-square" style="background: ' + bg +'"></span>';1129 1130 }1131 else {1132 1133 el.innerHTML = 1134 '<span class="rev-cpicker-point-square" style="background: ' + bg + '"></span>' + 1135 '<span class="rev-cpicker-point-triangle" style="border-top-color: ' + bg + '"></span>';1136 1137 }1138 1139 return el;1140 1141 }1142 1143 function getDegree(val) {1144 1145 if(!val || val === 'radial') val = '0';1146 textareas.innerHTML = val + '&deg;';1147 return textareas.value;1148 1149 }1150 1151 function deactivate() {1152 1153 if(curPoint) {1154 1155 curPoint.removeClass('active');1156 curPoint = false;1157 1158 }1159 1160 colorLoc.attr('disabled', 'disabled');1161 gradOpacity.attr('disabled', 'disabled');1162 opacityLoc.attr('disabled', 'disabled');1163 1164 opacityDelete.removeClass('active');1165 colorDelete.removeClass('active');1166 1167 colorBox.css('background', '');1168 cPicker.removeClass('open');1169 1170 }1171 1172 function onClose(e, changed) {1173 1174 cPicker.removeClass('active').hide();1175 bodies.removeClass('rev-colorpicker-open');1176 mainContainer.css({left: '', top: ''});1177 1178 if(appended) {1179 1180 appended.remove();1181 appended = false;1182 1183 }1184 1185 if(selectedColor) {1186 1187 if(selectedColor.hasClass('selected')) {1188 1189 if(changed) currentInput.data('hex', selectedColor.attr('data-color').toLowerCase()); 1190 selectedColor.removeClass('selected');1191 1192 }1193 else {1194 1195 currentInput.removeData('hex');1196 1197 }1198 1199 selectedColor = false;1200 1201 }1202 else {1203 1204 currentInput.removeData('hex');1205 1206 }1207 1208 if(!changed) {1209 1210 if(onCancel) onCancel();1211 if(openingValue && openingValue !== 'transparent') { 1212 1213 currentColor[0].style.background = openingValue;1214 1215 }1216 else {1217 1218 currentColor.css('background', '');1219 1220 }1221 1222 doc.trigger('revcolorpickerupdate', [currentInput, openingValue]);1223 1224 }1225 1226 currentColor = false;1227 currentInput = false;1228 1229 }1230 1231 function checkGroup() {1232 1233 var $this = $(this),1234 len = $this.children('.rev-cpicker-color').not('.blank').length;1235 1236 if(len > presetColumns) $('#' + this.id + '-btn').addClass('multiplerows');1237 else $('#' + this.id + '-btn').removeClass('multiplerows');1238 1239 return len;1240 1241 }1242 1243 function checkRows() {1244 1245 var $this = $(this),1246 minRows = this.id.search('colors') !== -1 ? minColorRows : minGradRows,1247 colors = $this.children('.rev-cpicker-color'),1248 len = colors.length,1249 rows = Math.ceil(len / presetColumns),1250 minItems = minRows * presetColumns,1251 rowRemoved; 1252 1253 len += 1; 1254 for(var i = 0; i < rows; i++) {1255 1256 var start = i * presetColumns,1257 range = colors.slice(start, parseInt(start + presetColumns, 10) - 1);1258 1259 blankRow = true;1260 range.each(checkRow);1261 if(blankRow) {1262 1263 len -= presetColumns;1264 if(len >= minItems) {1265 1266 range.remove();1267 rowRemoved = true;1268 1269 }1270 1271 }1272 1273 }1274 1275 return rowRemoved;1276 1277 }1278 1279 function checkRow() {1280 1281 if(this.className.search('blank') === -1) {1282 1283 blankRow = false;1284 return false;1285 1286 }1287 1288 }1289 function buildGradientInput(obj) {1290 1291 var degree = obj.angle;1292 if(obj.type === 'radial') degree = 'radial';1293 1294 directions.removeClass('selected');1295 $('.rev-cpicker-orientation[data-direction="' + degree + '"]').addClass('selected');1296 1297 angle.val(getDegree(degree));1298 updateWheel(degree);1299 setPoints(obj.colors);1300 1301 }1302 1303 function buildGradientOutput(el, revrse, save) {1304 1305 onReverse = revrse;1306 calculatePoints();1307 onReverse = false;1308 1309 var elm,1310 color,1311 point,1312 ar = [],1313 len = points.length;1314 1315 for(var i = 0; i < len; i++) {1316 1317 point = points[i];1318 color = point.color;1319 ar[i] = color;1320 1321 elm = point.el;1322 elm.setAttribute('data-color', RevColor.rgbaString(color.r, color.g, color.b, color.a));1323 elm.setAttribute('data-opacity', color.a * 100);1324 1325 if(el && el === elm) pointIndex = i;1326 1327 }1328 1329 if(!radial.hasClass('selected')) {1330 1331 gradientPreview.type = 'linear';1332 gradientPreview.angle = parseInt(angle.val(), 10).toString();1333 1334 }1335 else {1336 1337 gradientPreview.type = 'radial';1338 gradientPreview.angle = '0';1339 1340 }1341 1342 gradientPreview.colors = ar;1343 if(selectedColor) selectedColor.removeClass('selected');1344 1345 var gradient = RevColor.processGradient(gradientPreview);1346 onChange(true, gradient);1347 1348 if(!save) {1349 1350 gradInput.style.background = gradientView(gradient);1351 gradOutput.style.background = gradient;1352 1353 }1354 else {1355 1356 return [gradientPreview, gradient];1357 1358 }1359 1360 }1361 1362 function back(i, align) {1363 1364 if(i === 0) return false;1365 1366 var pnt;1367 while(i--) {1368 1369 pnt = points[i];1370 if(pnt.align !== align) return pnt;1371 1372 }1373 1374 return false;1375 1376 }1377 1378 function front(i, align, len) {1379 1380 if(i === len) return false;1381 1382 var pnt;1383 while(i++ < len) {1384 1385 pnt = points[i];1386 if(pnt.align !== align) return pnt;1387 1388 }1389 1390 return false;1391 1392 }1393 1394 function dist(px, bx, ex, bv, ev) {1395 1396 return Math.max(Math.min(Math.round(Math.abs((((px - bx) / (ex - bx)) * (ev - bv)) + bv)), 255), 0);1397 1398 }1399 1400 function distAlpha(px, bx, ex, bv, ev) {1401 1402 return Math.max(Math.min(Math.abs(parseFloat((((px - bx) / (ex - bx)) * (ev - bv)).toFixed(2)) + parseFloat(bv)), 1), 0);1403 1404 }1405 1406 function adjustAlpha(point, begin, end) {1407 1408 var val,1409 beginAlpha = begin.alpha,1410 endAlpha = end.alpha;1411 1412 if(beginAlpha !== endAlpha) {1413 1414 val = distAlpha(point.x, begin.x, end.x, beginAlpha, endAlpha).toFixed(2);1415 1416 }1417 else {1418 1419 val = beginAlpha;1420 1421 }1422 1423 point.alpha = val;1424 point.color.a = val;1425 1426 }1427 1428 function adjustColor(point, begin, end) {1429 1430 var p = point.color,1431 bv = begin.color, 1432 ev = end.color;1433 1434 if(begin !== end) {1435 1436 var px = point.x,1437 bx = begin.x, 1438 ex = end.x;1439 1440 p.r = dist(px, bx, ex, bv.r, ev.r);1441 p.g = dist(px, bx, ex, bv.g, ev.g);1442 p.b = dist(px, bx, ex, bv.b, ev.b);1443 1444 }1445 else {1446 1447 p.r = bv.r;1448 p.g = bv.g;1449 p.b = bv.b;1450 1451 }1452 1453 }1454 1455 function calculatePoints() {1456 1457 points = [];1458 topPoints = [];1459 botPoints = [];1460 1461 groupPoints.each(getPoints);1462 points.sort(sortPoints);1463 1464 var len = points.length,1465 iLen = len - 1,1466 point,1467 begin,1468 tpe,1469 end;1470 1471 for(var i = 0; i < len; i++) {1472 1473 point = points[i];1474 tpe = point.align;1475 1476 begin = back(i, tpe);1477 if(begin === false) begin = front(i, tpe, iLen);1478 1479 end = front(i, tpe, iLen);1480 if(end === false) end = back(i, tpe);1481 1482 if(tpe === 'bottom') adjustAlpha(point, begin, end);1483 else adjustColor(point, begin, end);1484 1485 }1486 1487 points.sort(sortPoints);1488 1489 }1490 1491 function sortPoints(a, b) {1492 1493 return a.x < b.x ? -1 : a.x > b.x ? 1 : 0;1494 1495 }1496 1497 function getPoints(i) {1498 1499 var rgba = RevColor.rgbValues(getAttribute(this, 'data-color'), 4),1500 align = this.className.search('bottom') !== -1 ? 'bottom' : 'top',1501 alpha = rgba[3].replace(/\.?0*$/, '') || 0,1502 pos = parseInt(this.style.left, 10);1503 1504 if(onReverse) {1505 1506 if(pos < 50) pos += (50 - pos) * 2;1507 else pos -= (pos - 50) * 2; 1508 1509 this.style.left = pos + '%';1510 this.setAttribute('data-location', pos);1511 1512 }1513 1514 points[i] = {1515 1516 el: this, 1517 x: pos,1518 alpha: alpha,1519 align: align,1520 color: {1521 1522 r: parseInt(rgba[0], 10),1523 g: parseInt(rgba[1], 10),1524 b: parseInt(rgba[2], 10),1525 a: alpha,1526 position: pos,1527 align: align1528 1529 }1530 1531 };1532 1533 if(curPoint && curPoint[0] !== this) {1534 1535 if(align === 'bottom') botPoints[botPoints.length] = pos;1536 else topPoints[topPoints.length] = pos;1537 1538 }1539 1540 }1541 1542 function updateWheel(val) {1543 1544 val = typeof val !== 'undefined' ? val : parseInt(angle.val(), 10);1545 wheelPoint[0].style.transform = 'rotate(' + val + 'deg)';1546 1547 }1548 1549 function onAngleChange(e, dir, wheel) {1550 1551 var isWheel = typeof wheel !== 'undefined',1552 val = isWheel ? wheel : parseInt(angle.val(), 10),1553 changed,1554 value;1555 1556 if(e && e.type === 'keyup') {1557 1558 changed = !isNaN(val) && val >= -360 && val <= 360;1559 value = val;1560 1561 }1562 else {1563 1564 var oValue = parseInt(angle.data('orig-value'), 10);1565 1566 if(!val) val = '0';1567 if(isNaN(val) || val < -360 || val > 360) val = oValue;1568 if(val !== oValue) {1569 1570 value = val;1571 changed = true;1572 angle.val(getDegree(val));1573 1574 if(!isWheel) {1575 1576 val = dir || val;1577 directions.removeClass('selected');1578 $('.rev-cpicker-orientation[data-direction="' + val + '"]').addClass('selected');1579 1580 }1581 1582 }1583 1584 }1585 1586 if(changed || dir) {1587 1588 if(value) updateWheel(value);1589 buildGradientOutput();1590 1591 }1592 1593 }1594 1595 function onArrowClick() {1596 1597 var $this = $(this);1598 if(this.className.search('down') !== -1) {1599 1600 $this.parent().addClass('active');1601 $this.closest('.rev-cpicker-presets').addClass('active');1602 $(this.id.replace('-btn', '')).addClass('active');1603 1604 }1605 else {1606 1607 $this.parent().removeClass('active');1608 $this.closest('.rev-cpicker-presets').removeClass('active');1609 $(this.id.replace('-btn', '')).removeClass('active');1610 1611 }1612 1613 }1614 1615 function onDrag(e, ui) {1616 1617 var pos = parseInt((Math.round(ui.position.left) / (hitWidth - 2)).toFixed(2) * 100, 10);1618 if(dragPoint === 'bottom') colorLoc.val(pos + '%').trigger('keyup');1619 else opacityLoc.val(pos + '%').trigger('keyup');1620 1621 }1622 1623 function onDragStart() {1624 1625 var $this = $(this);1626 dragPoint = $this.hasClass('rev-cpicker-point-bottom') ? 'bottom' : 'top'; 1627 $this.click();1628 1629 }1630 1631 function onDragStop() {1632 1633 if(dragPoint === 'bottom') colorLoc.trigger('focusout');1634 else opacityLoc.trigger('focusout');1635 1636 }1637 1638 function updateSlider(opacity) {1639 1640 supressOpacity = true;1641 opacitySlider.slider('value', Math.round((opacity * 0.01) * sliderHeight));1642 supressOpacity = false;1643 1644 }1645 1646 function wheelMove(e) {1647 1648 var offset = angleWheel.offset(),1649 posX = e.pageX - offset.left,1650 posY = e.pageY - offset.top;1651 1652 if(isNaN(posX) || isNaN(posY)) return;1653 1654 var val = Math.atan2(posY - centerWheel, posX - centerWheel) * (180 / Math.PI) + 90;1655 if(val < 0) val += 360;1656 1657 val = Math.max(0, Math.min(360, Math.round(val)));1658 val = 5 * (Math.round(val / 5));1659 1660 supressWheel = true;1661 onAngleChange(false, false, val);1662 supressWheel = false;1663 1664 }1665 1666 function init() {1667 1668 if(!prepped) $.tpColorPicker();1669 1670 currentEditing = document.getElementById('rev-cpicker-current-edit');1671 gradOutput = document.getElementById('rev-cpicker-gradient-output');1672 gradInput = document.getElementById('rev-cpicker-gradient-input');1673 editTitle = document.getElementById('rev-cpicker-edit-title');1674 textareas = document.createElement('textarea');1675 opacityDelete = $('#rev-cpicker-opacity-delete');1676 pointerWrap = $('#rev-cpciker-point-container');1677 opacityLoc = $('#rev-cpicker-opacity-location');1678 presetGroups = $('.rev-cpicker-presets-group');1679 colorOpacity = $('#rev-cpicker-color-opacity');1680 radial = $('#rev-cpicker-orientation-radial');1681 colorDelete = $('#rev-cpicker-color-delete');1682 gradOpacity = $('#rev-cpicker-grad-opacity');1683 colorLoc = $('#rev-cpicker-color-location');1684 gradCore = $('#rev-cpicker-gradients-core');1685 directions = $('.rev-cpicker-orientation');1686 gradIris = $('#rev-cpicker-iris-gradient');1687 wheelPoint = $('#rev-cpicker-wheel-point');1688 gradSection = $('#rev-cpicker-gradients');1689 colorIris = $('#rev-cpicker-iris-color');1690 gradBtn = $('#rev-cpicker-gradient-btn');1691 gradHex = $('#rev-cpicker-gradient-hex');1692 colorClear = $('#rev-cpciker-clear-hex');1693 reverse = $('#rev-cpicker-meta-reverse');1694 hitBottom = $('#rev-cpicker-hit-bottom');1695 opacitySlider = $('#rev-cpicker-scroll');1696 colorSection = $('#rev-cpicker-colors');1697 colorHex = $('#rev-cpicker-color-hex');1698 colorBtn = $('#rev-cpicker-color-btn');1699 colorBox = $('#rev-cpicker-color-box');1700 angle = $('#rev-cpicker-meta-angle');1701 angleWheel = $('#rev-cpicker-wheel');1702 hitTop = $('#rev-cpicker-hit-top');1703 mainContainer = $('#rev-cpicker');1704 doc = $(document);1705 1706 dragObj.drag = onDrag;1707 dragObj.stop = onDragStop;1708 dragObj.start = onDragStart;1709 1710 colorBtn.data('state', colorSection.find('.rev-cpicker-color').eq(0).attr('data-color') || '#ffffff');1711 gradBtn.data('state', gradSection.find('.rev-cpicker-color').eq(0).attr('data-color') || 'linear-gradient(0deg, rgba(255, 255, 255, 1) 0%, rgba(0, 0, 0, 1) 100%)');1712 1713 mainContainer.draggable({containment: 'window', handle: '.rev-cpicker-draggable'});1714 presetGroups.perfectScrollbar({wheelPropagation: false, suppressScrollX: true});1715 1716 angleWheel.on('mousedown.revcpicker', function(e) {1717 1718 directions.removeClass('selected');1719 wheelDown = true;1720 wheelMove(e);1721 1722 }).on('mousemove.revcpicker', function(e) {1723 1724 if(!wheelDown) return;1725 wheelMove(e);1726 1727 }).on('mouseleave.revcpicker mouseup.revcpicker', function() {1728 1729 wheelDown = false;1730 1731 });1732 1733 $('.rev-cpicker-main-btn').on('click.revcpicker', function() {1734 1735 var $this,1736 state;1737 1738 if(currentColor) {1739 1740 $this = $(this);1741 state = $this.data('state');1742 1743 }1744 1745 if(this.id.search('gradient') === -1) {1746 1747 if(currentColor) selectedHex = colorHex.val();1748 cPicker.removeClass('gradient-view').addClass('color-view');1749 1750 }1751 else {1752 1753 if(currentColor) selectedHex = state;1754 1755 cPicker.removeClass('color-view').addClass('gradient-view');1756 if(!gradViewed) gradCore.children('.rev-cpicker-color').not('.blank').eq(0).click();1757 1758 }1759 1760 presetGroups.perfectScrollbar('update');1761 if(state) {1762 1763 var isTrans = state === 'transparent',1764 val = !isTrans ? state : '';1765 1766 if(!isTrans) currentColor[0].style.background = val;1767 else currentColor.css('background', val);1768 1769 supressCheck = true;1770 $('.rev-cpicker-color').not('.blank').each(checkPreset);1771 supressCheck = false;1772 1773 doc.trigger('revcolorpickerupdate', [currentInput, state]);1774 1775 }1776 1777 });1778 1779 $('#rev-cpicker-check').on('click.revcipicker', function() {1780 1781 var ar,1782 color,1783 changed;1784 1785 if(cPicker.hasClass('color-view')) {1786 1787 var hex = colorHex.val(),1788 opacity = colorOpacity.val();1789 1790 currentInput.removeData('gradient');1791 if(hex === 'transparent') color = 'transparent';1792 else if(opacity === '100%') color = RevColor.sanitizeHex(hex);1793 else color = RevColor.processRgba(hex, opacity);1794 ar = [currentInput, color, false];1795 1796 }1797 else {1798 1799 deactivate();1800 var grad = buildGradientOutput(false, false, true),1801 obj = $.extend({}, grad[0]),1802 clr = grad[1];1803 1804 currentInput.data('gradient', clr);1805 color = JSON.stringify(obj).replace(/\"/g, '&');1806 ar = [currentInput, clr, obj];1807 1808 }1809 1810 changed = ar[1] !== openingValue;1811 if(changed) {1812 1813 currentInput.attr('data-color', ar[1]).val(color).change();1814 doc.trigger('revcolorpicker', ar);1815 if(changeCallback) changeCallback(ar[0], ar[1], ar[2]);1816 1817 }1818 1819 onClose(false, changed);1820 1821 });1822 1823 cPicker.on('click.revcpicker', function(e) {1824 1825 if(cPicker.hasClass('open')) {1826 1827 var targt = e.target,1828 $this = $(targt),1829 ids = targt.id,1830 isTarget = targt.className.search('rev-cpicker-point') !== -1 || 1831 ids === 'rev-cpicker-section-right' || ids.search('hit') !== -1 || 1832 $this.closest('#rev-cpicker-section-right, #rev-cpicker-point-wrap').length;1833 1834 if(isTarget) {1835 1836 if($this.attr('type') === 'text') {1837 1838 isTarget = !$this.attr('disabled');1839 1840 }1841 else if(ids === 'rev-cpicker-check-gradient') {1842 1843 isTarget = false;1844 1845 }1846 1847 }1848 1849 if(!isTarget) deactivate();1850 1851 }1852 else if(wheelActive && /wheel|angle|reverse/.test(e.target.id) === false) {1853 1854 if(e.target.id.search('radial') === -1) {1855 1856 $('.rev-cpicker-orientation[data-direction="' + parseInt(angle.val()) + '"]').addClass('selected');1857 1858 }1859 1860 angleWheel.removeClass('active');1861 wheelActive = false;1862 1863 }1864 1865 });1866 1867 $('.rev-cpicker-close').on('click.revcpicker', onClose);1868 1869 colorIris.wpColorPicker({palettes: false, width: 267, border: false, hide: false, change: function(e, ui) {1870 1871 var val = ui.color.toString();1872 this.value = val;1873 1874 colorHex.val(val);1875 if(!supressColor) {1876 1877 var opacity = colorOpacity.val();1878 if(parseInt(opacity, 10) === 0) val = 'transparent';1879 onChange(false, val, opacity);1880 1881 if(selectedColor) {1882 1883 selectedColor.removeClass('selected');1884 selectedColor = false;1885 1886 }1887 1888 }1889 1890 }});1891 1892 gradIris.wpColorPicker({palettes: false, height: 250, border: false, hide: false, change: function(e, ui) {1893 1894 var val = ui.color.toString();1895 this.value = val;1896 1897 gradHex.val(val);1898 colorBox.css('background', val);1899 curSquare.style.backgroundColor = val;1900 curCorner.style.borderBottomColor = val;1901 1902 var rgba = RevColor.processRgba(val, 100),1903 parsed = RevColor.rgbValues(rgba, 4),1904 color = gradientPreview.colors[pointIndex];1905 1906 color.r = parsed[0];1907 color.g = parsed[1];1908 color.b = parsed[2];1909 color.a = parsed[3];1910 1911 curPoint.attr('data-color', rgba);1912 buildGradientOutput();1913 1914 }});1915 1916 opacitySlider.slider({orientation: 'vertical', max: sliderHeight, value: sliderHeight, 1917 1918 start: function() {1919 1920 isTransparent = colorHex.val() === 'transparent';1921 1922 }, 1923 1924 slide: function(e, ui) {1925 1926 if(!supressOpacity) {1927 1928 var opacity = parseInt((ui.value / sliderHeight).toFixed(2) * 100, 10),1929 val;1930 1931 if(isTransparent) {1932 1933 val = opacity ? '#ffffff' : 'transparent';1934 colorHex.val(val);1935 1936 }1937 1938 if(opacity === 0) val = 'transparent';1939 onChange(false, val, opacity || 'transparent');1940 colorOpacity.val(opacity + '%');1941 1942 }1943 1944 }1945 1946 });1947 1948 $('.rev-cpicker-point-location').on('keyup.revcpicker focusout.revcpicker', function(e) {1949 1950 if(!curPoint) return;1951 1952 var align = curPoint.hasClass('rev-cpicker-point-bottom') ? 'bottom' : 'top',1953 locations = align === 'bottom' ? botPoints : topPoints,1954 input = align === 'bottom' ? colorLoc : opacityLoc,1955 point = input.val().replace('%', '') || '0',1956 evt = e.type,1957 dir;1958 1959 if(isNaN(point)) point = evt === 'keyup' ? '0' : curPoint.attr('data-location');1960 point = Math.max(0, Math.min(100, parseInt(point, 10)));1961 1962 dir = point < 50 ? 1 : -1;1963 1964 while(locations.indexOf(point) !== -1) point += dir;1965 1966 if(evt === 'focusout') {1967 1968 input.val(point + '%');1969 curPoint.attr('data-location', point);1970 1971 }1972 1973 curPoint.css('left', point + '%');1974 buildGradientOutput();1975 1976 });1977 1978 $('body').on('click.revcpicker', '.rev-cpicker-point', function() {1979 1980 pointerWrap.find('.rev-cpicker-point.active').removeClass('active');1981 curPoint = $(this).addClass('active');1982 1983 curSquare = curPoint.children('.rev-cpicker-point-square')[0];1984 curCorner = curPoint.children('.rev-cpicker-point-triangle')[0];1985 1986 buildGradientOutput(this);1987 selectedColor = false;1988 1989 var grad = activatePoint();1990 if(grad[0]) gradIris.val(grad[1]).change();1991 1992 }).on('mousedown.revcpicker', '.rev-cpicker-point', function(e) {1993 1994 curPoint = $(this).data('mousestart', e.pageY);1995 1996 }).on('mousemove.revcpicker', function(e) {1997 1998 if(!curPoint || !curPoint.data('mousestart')) return;1999 2000 var start = curPoint.data('mousestart'),2001 posY = e.pageY;2002 2003 if(curPoint.hasClass('rev-cpicker-point-bottom')) {2004 2005 if(posY > start && posY - start > warningBuffer && colorDelete.hasClass('active')) {2006 curPoint.addClass('warning');2007 }2008 else {2009 curPoint.removeClass('warning');2010 }2011 2012 }2013 else {2014 2015 if(start > posY && start - posY > warningBuffer && opacityDelete.hasClass('active')) {2016 curPoint.addClass('warning');2017 }2018 else {2019 curPoint.removeClass('warning');2020 }2021 2022 }2023 2024 }).on('mouseup.revcpicker', function(e) {2025 2026 if(!curPoint || !curPoint.data('mousestart')) return;2027 2028 var start = curPoint.data('mousestart'),2029 end = e.pageY;2030 2031 curPoint.removeData('mousestart');2032 if(curPoint.hasClass('rev-cpicker-point-bottom')) {2033 2034 if(end > start && end - start > deleteBuffer && colorDelete.hasClass('active')) {2035 colorDelete.click();2036 }2037 else {2038 curPoint.removeClass('warning');2039 }2040 2041 }2042 else {2043 2044 if(start > end && start - end > deleteBuffer && opacityDelete.hasClass('active')) {2045 opacityDelete.click();2046 }2047 else {2048 curPoint.removeClass('warning');2049 }2050 2051 }2052 2053 }).on('change.revcpicker', '.rev-cpicker-component', function() {2054 2055 var $this = $(this),2056 val = $this.data('gradient') || $this.val() || 'transparent';2057 2058 if(val === 'transparent' || RevColor.transparentRgba(val)) val = '';2059 $this.data('tpcp').css('background', val);2060 2061 }).on('keypress.revcpicker', function(e) {2062 2063 if(cPicker.hasClass('active')) {2064 2065 var key = e.which;2066 if(key == 27) {2067 2068 onClose();2069 2070 }2071 else if(key == 13 && inFocus) {2072 2073 inFocus.blur();2074 2075 }2076 2077 }2078 2079 }).on('click.revcpicker', '.rev-cpicker-color:not(.blank)', function() {2080 2081 if(selectedColor) {2082 2083 if(selectedColor[0] === this && selectedColor.hasClass('selected')) return;2084 selectedColor.removeClass('selected');2085 2086 } 2087 2088 var $this = $(this);2089 selectedColor = $this;2090 2091 var ids = selectedColor.parent()[0].id,2092 tpe = ids.search('core') !== -1 ? 'core' : 'custom',2093 view = ids.search('colors') !== -1 ? 'colors' : 'gradients', 2094 btn = $('#rev-cpicker-' + view + '-' + tpe + '-btn');2095 2096 if(btn.hasClass('active')) btn.find('.rev-cpicker-arrow-up').click();2097 if(cPicker.hasClass('color-view')) {2098 2099 var val = selectedColor.attr('data-color');2100 2101 supressColor = true;2102 colorIris.val(val).change();2103 supressColor = false;2104 2105 var opacity = colorOpacity.val();2106 if(parseInt(opacity, 10) === 0) val = 'transparent';2107 onChange(false, val, opacity);2108 2109 }2110 else {2111 2112 hitTop.removeClass('full');2113 hitBottom.removeClass('full');2114 2115 setValue(selectedColor.data('gradient'), true);2116 reverse.removeClass('checked');2117 gradCore.find('.rev-cpicker-color.selected').removeClass('selected');2118 2119 }2120 2121 $this.addClass('selected');2122 2123 }).on('click.revcpicker', '.rev-cpicker-delete', function() {2124 2125 if(!onAjax) {2126 2127 console.log('Ajax callback not defined');2128 return;2129 2130 }2131 2132 if(window.confirm(document.getElementById('rev-cpicker-remove-delete').innerHTML)) {2133 2134 cPicker.addClass('onajax onajaxdelete');2135 2136 var $this = $(this),2137 colr = $this.parent(),2138 titl = colr.attr('data-title') || '';2139 2140 if(!titl) {2141 2142 console.log('Preset does not have a name/title');2143 return;2144 2145 }2146 var group = $this.closest('.rev-cpicker-presets-group'),2147 ids = group[0].id,2148 tpe = ids.search('colors') !== -1 ? 'colors' : 'gradients';2149 2150 doc.off('revcpicker_onajax_delete.revcpicker').on('revcpicker_onajax_delete.revcpicker', function(evt, err) {2151 2152 if(err) console.log(err);2153 2154 var group = $this.closest('.rev-cpicker-presets-group'),2155 scroller = group.find('.ps-scrollbar-x-rail'),2156 btn = $('#' + ids + '-btn');2157 2158 colr.remove();2159 2160 if(!checkRows.call(group[0])) {2161 2162 $('<span class="rev-cpicker-color blank"></span>').insertBefore(scroller);2163 2164 }2165 else {2166 2167 group.perfectScrollbar('update');2168 2169 }2170 2171 if(checkGroup.call(group[0]) < presetColumns + 1) {2172 $('<span class="rev-cpicker-color blank"></span>').insertBefore(scroller);2173 if(btn.hasClass('active')) btn.children('.rev-cpicker-arrow-up').click();2174 2175 }2176 2177 cPicker.removeClass('onajax onajaxdelete');2178 2179 });2180 2181 titl = $.trim(titl.replace(/\W+/g, '_')).replace(/^\_|\_$/g, '').toLowerCase();2182 onAjax('delete', titl, tpe, 'revcpicker_onajax_delete', currentInput);2183 2184 }2185 2186 return false;2187 2188 });2189 2190 $('.rev-cpicker-save-preset-btn').on('click.revcpicker', function() {2191 2192 if(!onAjax) {2193 2194 console.log('Ajax callback not defined');2195 return;2196 2197 }2198 2199 var presetGroup,2200 duplicateTitle,2201 $this = $(this),2202 input = $this.closest('.rev-cpicker-presets-save-as').find('.rev-cpicker-preset-save'),2203 titl = input.val();2204 2205 if(!titl || !isNaN(titl)) {2206 2207 alert($this.attr('data-message'));2208 return;2209 2210 }2211 2212 presetGroup = cPicker.hasClass('color-view') ? 'colors' : 'gradients';2213 titl = $.trim(titl.replace(/\W+/g, '_')).replace(/^\_|\_$/g, '').toLowerCase();2214 2215 $('#rev-cpicker-' + presetGroup + '-custom').find('.rev-cpicker-color').not('.blank').each(function() {2216 2217 var atr = $.trim(getAttribute(this, 'data-title').replace(/\W+/g, '_')).replace(/^\_|\_$/g, '').toLowerCase();2218 if(atr === titl) {2219 2220 alert($this.attr('data-message'));2221 duplicateTitle = true;2222 return false;2223 2224 }2225 2226 });2227 2228 if(duplicateTitle) return;2229 cPicker.addClass('onajax onajaxsave');2230 2231 var newColorValue = {},2232 presetGroup,2233 color,2234 grad;2235 2236 if(presetGroup === 'colors') {2237 2238 var hex = colorHex.val(),2239 opacity = colorOpacity.val();2240 2241 if(hex === 'transparent') color = 'transparent';2242 else if(opacity === '100%') color = RevColor.sanitizeHex(hex);2243 else color = RevColor.processRgba(hex, opacity);2244 2245 }2246 else {2247 grad = gradOutput.style.background;2248 color = $.extend({}, buildGradientOutput(false, false, true)[0]);2249 2250 }2251 2252 newColorValue[titl] = color;2253 doc.off('revcpicker_onajax_save.revcpicker').on('revcpicker_onajax_save.revcpicker', function(evt, err) {2254 2255 if(err) {2256 2257 cPicker.removeClass('onajax onajaxsave');2258 alert($this.attr('data-message'));2259 return;2260 2261 }2262 2263 var pre = $(newPreset(newColorValue, false, ' rev-picker-color-custom', grad)),2264 group = $('#rev-cpicker-' + presetGroup + '-custom'),2265 box = group.find('.rev-cpicker-color.blank'),2266 btn = $('#' + group[0].id + '-btn');2267 2268 2269 if(box.length) pre.insertBefore(box.eq(0));2270 else pre.insertBefore(group.find('.ps-scrollbar-x-rail'));2271 2272 $('#rev-cpicker-' + presetGroup + '-custom-btn').click();2273 var len = checkGroup.call(group[0]);2274 2275 if(len > 6) {2276 2277 if(box.length) box.last().remove();2278 btn.addClass('active').children('.rev-cpicker-arrow-down').click();2279 group.perfectScrollbar('update');2280 2281 }2282 pre.click();2283 cPicker.removeClass('onajax onajaxsave');2284 2285 });2286 2287 onAjax('save', newColorValue, presetGroup, 'revcpicker_onajax_save', currentInput);2288 2289 });2290 2291 $('.rev-cpicker-preset-title').on('click.revcpicker', function() {2292 2293 var $this = $(this),2294 par = $this.parent(),2295 arrow = $this.hasClass('active') ? 'down' : 'up';2296 2297 onArrowClick.call($this.find('.rev-cpicker-arrow-' + arrow)[0]);2298 2299 par.find('.rev-cpicker-preset-title').removeClass('selected');2300 $this.addClass('selected');2301 2302 par.find('.rev-cpicker-presets-group').hide();2303 document.getElementById(this.id.replace('-btn', '')).style.display = 'block';2304 2305 presetGroups.perfectScrollbar('update');2306 2307 });2308 2309 colorClear.on('click.revcpicker', function() {2310 2311 colorOpacity.val('0%');2312 updateSlider(0);2313 colorIris.val(RevColor.defaultValue).change();2314 colorHex.val('transparent');2315 onChange(false, 'transparent');2316 2317 });2318 2319 cPicker.find('input[type="text"]').on('focusin.revcpicker', function() {2320 2321 inFocus = this;2322 2323 }).on('focusout.revcpicker', function() {2324 2325 inFocus = false;2326 2327 });2328 2329 $('.rev-cpicker-input').on('focusin.revcpicker', function() {2330 2331 var $this = $(this);2332 $this.data('orig-value', $this.val());2333 2334 });2335 2336 $('.rev-cpicker-hex').on('focusout.revcpicker', function() {2337 2338 var $this, 2339 oVal,2340 val;2341 2342 if(this.id === 'rev-cpicker-color-hex') {2343 2344 val = colorHex.val();2345 if(val) {2346 2347 val = RevColor.sanitizeHex(val);2348 if(isColor.test(val)) {2349 2350 colorHex.val(val);2351 2352 }2353 else {2354 2355 $this = $(this);2356 oVal = $this.data('orig-value');2357 2358 if(oVal) {2359 2360 val = oVal;2361 colorHex.val(val);2362 2363 }2364 else {2365 2366 colorClear.click();2367 return;2368 2369 }2370 2371 }2372 2373 }2374 else { 2375 2376 val = 'transparent';2377 2378 }2379 2380 colorIris.val(val).change();2381 2382 }2383 else {2384 2385 val = gradHex.val() || RevColor.defaultValue;2386 val = RevColor.sanitizeHex(val);2387 2388 if(!isColor.test(val)) {2389 2390 $this = $(this);2391 oVal = $this.data('orig-value');2392 val = oVal ? oVal : RevColor.defaultValue;2393 2394 }2395 2396 gradHex.val(val);2397 gradIris.val(val).change();2398 2399 }2400 2401 });2402 2403 $('#rev-cpciker-clear-gradient').on('click.revcpicker', function() {2404 2405 gradIris.val(RevColor.defaultValue).change();2406 2407 });2408 2409 angle.on('keyup.revcpicker focusout.revcpicker', onAngleChange).on('focusin.revcpicker', function() {2410 2411 wheelActive = true;2412 angleWheel.addClass('active');2413 2414 });2415 2416 directions.on('click.revcpicker', function() {2417 2418 var $this = $(this),2419 dir = $this.attr('data-direction');2420 2421 directions.removeClass('selected');2422 $this.addClass('selected');2423 2424 if(dir !== 'radial') angle.removeAttr('disabled').val(getDegree(dir));2425 else angle.attr('disabled', 'disabled');2426 2427 onAngleChange(false, dir);2428 2429 });2430 2431 $('.rev-cpicker-point-delete').on('click.revcpicker', function() {2432 2433 if(this.className.search('active') === -1) return;2434 2435 var align = curPoint.hasClass('rev-cpicker-point-bottom') ? 'bottom' : 'top',2436 len = cPicker.find('.rev-cpicker-point-' + align).length;2437 2438 if(len > 2) {2439 2440 curPoint.draggable('destroy').remove();2441 groupPoints = pointerWrap.children();2442 2443 cPicker.click();2444 buildGradientOutput();2445 }2446 2447 if(len <= maxPoints) {2448 2449 if(align === 'bottom') hitBottom.removeClass('full');2450 else hitTop.removeClass('full');2451 2452 }2453 2454 });2455 2456 $('.rev-cpicker-opacity-input').on('keyup.revcpicker focusout.revcpicker', function(e) {2457 2458 var isColor = this.id.search('grad') === -1,2459 $this = isColor ? colorOpacity : gradOpacity,2460 opacity = $this.val().replace('%', ''),2461 evt = e.type,2462 clr;2463 2464 if(isNaN(opacity)) opacity = evt === 'keyup' ? '0' : $(this).data('orig-value');2465 opacity = Math.max(0, Math.min(100, opacity));2466 2467 if(evt === 'focusout') {2468 2469 $this.val(opacity + '%');2470 if(!isColor) curPoint.attr('data-opacity', opacity);2471 2472 }2473 2474 if(isColor) {2475 2476 var opaque = parseInt(opacity, 10),2477 val = opaque !== 0 ? false : 'transparent';2478 onChange(false, val, opacity);2479 updateSlider(opacity);2480 2481 }2482 else {2483 2484 var parsed = RevColor.rgbValues(curPoint.attr('data-color'), 3),2485 color = gradientPreview.colors[pointIndex];2486 2487 opacity = (parseInt(opacity, 10) * 0.01).toFixed(2).replace(/\.?0*$/, '');2488 2489 color.r = parsed[0];2490 color.g = parsed[1];2491 color.b = parsed[2];2492 color.a = opacity;2493 2494 clr = RevColor.rgbaString(color.r, color.g, color.b, opacity);2495 curPoint.attr('data-color', clr);2496 buildGradientOutput();2497 2498 clr = 'rgba(0, 0, 0, ' + opacity + ')'; 2499 curSquare.style.backgroundColor = clr;2500 curCorner.style.borderTopColor = clr;2501 2502 }2503 2504 });2505 2506 $('.rev-cpicker-builder-hit').on('click.revcpicker', function(e) {2507 2508 if(!points) calculatePoints();2509 2510 var hit = parseInt(((e.pageX - hitTop.offset().left) / hitWidth).toFixed(2) * 100, 10),2511 align = this.id.search('bottom') !== -1 ? 'bottom' : 'top',2512 locations = align === 'bottom' ? botPoints : topPoints,2513 dir = hit < 50 ? 1 : -1;2514 2515 while(locations.indexOf(hit) !== -1) hit += dir;2516 if(align === 'bottom') {2517 2518 if(cPicker.find('.rev-cpicker-point-bottom').length < maxPoints) {2519 2520 clonePoint(align, hit);2521 selectedColor = false;2522 2523 }2524 else {2525 2526 hitBottom.addClass('full');2527 2528 }2529 2530 }2531 else {2532 2533 if(cPicker.find('.rev-cpicker-point-top').length < maxPoints) {2534 2535 clonePoint(align, hit);2536 selectedColor = false;2537 2538 }2539 else {2540 2541 hitTop.addClass('full');2542 2543 }2544 2545 }2546 2547 });2548 2549 reverse.on('click.revcpicker', function() {2550 2551 var rev = !reverse.hasClass('checked');2552 2553 if(rev) reverse.addClass('checked');2554 else reverse.removeClass('checked');2555 2556 buildGradientOutput(false, true);2557 2558 });2559 2560 $('.rev-cpicker-arrow').on('click.revcpicker', onArrowClick);2561 inited = true;2562 2563 }2564 2565 function addPresets(sets) {2566 2567 var settings = $.extend({}, sets),2568 core = settings.core || {},2569 custom = settings.custom,2570 container,2571 preset,2572 colors,2573 len,2574 el;2575 2576 if(!customAdded || custom) {2577 2578 len = 4;2579 customAdded = custom;2580 custom = customAdded || {'colors': [], 'gradients': []};2581 2582 }2583 else {2584 2585 len = 2;2586 2587 }2588 2589 if(!core.colors) core.colors = defColors;2590 if(!core.gradients) core.gradients = defGradients;2591 2592 for(var i = 0; i < len; i++) {2593 2594 switch(i) {2595 2596 case 0:2597 2598 container = 'colors-core';2599 colors = core.colors;2600 2601 break;2602 2603 case 1:2604 2605 container = 'gradients-core';2606 colors = core.gradients;2607 2608 break;2609 2610 case 2:2611 2612 container = 'colors-custom';2613 colors = custom.colors;2614 2615 break;2616 2617 case 3:2618 2619 container = 'gradients-custom';2620 colors = custom.gradients;2621 2622 break;2623 2624 }2625 preset = writePresets(container, colors.slice() || []);2626 el = $('#' + preset[0]);2627 el.find('.rev-cpicker-color').remove();2628 el.prepend(preset[1]);2629 2630 }2631 2632 }2633 2634 $.tpColorPicker = function(settings) {2635 2636 if(!bodies) {2637 2638 bodies = $('body');2639 cPicker = $('<div class="' + 'rev-cpicker-wrap color-view">' + markup + '</div>').appendTo(bodies);2640 2641 }2642 2643 if(!settings) settings = {}; 2644 if(settings.core) {2645 2646 if(settings.core.colors) defColors = settings.core.colors;2647 if(settings.core.gradients) defGradients = settings.core.gradients;2648 2649 }2650 2651 addPresets(settings);2652 2653 if(!prepped) {2654 2655 writeLanguage(settings.language || lang);2656 defMode = settings.mode || 'full';2657 2658 }2659 else {2660 2661 presetGroups.perfectScrollbar('update');2662 if(settings.mode) defMode = settings.mode;2663 if(settings.language) writeLanguage(settings.language);2664 2665 }2666 2667 if(settings.init) onInit = settings.init;2668 if(settings.onAjax) defAjax = settings.onAjax;2669 if(settings.onEdit) defEdit = settings.onEdit;2670 if(settings.change) defChange = settings.change;2671 if(settings.cancel) defCancel = settings.cancel;2672 if(settings.widgetId) defWidgetId = settings.widgetId;2673 if(settings.defaultValue) RevColor.defaultValue = settings.defaultValue;2674 if(settings.wrapClasses) defaultClasses = settings.wrapClasses;2675 if(settings.appendedHtml) appendedHTML = settings.appendedHtml;2676 2677 prepped = true;2678 2679 };2680 2681 var ColorPicker = {2682 2683 refresh: function() {2684 2685 var $this = $(this);2686 if($this.hasClass('rev-cpicker-component')) {2687 2688 var settings = $this.data('revcp') || {},2689 val = $this.val() || settings.defaultValue || RevColor.defaultValue,2690 colorValue = RevColor.process(val);2691 2692 val = colorValue[0];2693 colorValue = colorValue[1] !== 'rgba' || !RevColor.transparentRgba(val, true) ? val : '';2694 2695 if(val !== 'transparent') $this.data('tpcp')[0].style.background = colorValue;2696 else $this.data('tpcp').css('background', '');2697 2698 $this.attr('data-color', val);2699 2700 }2701 2702 },2703 2704 destroy: function() {2705 2706 var $this = $(this).removeData();2707 $this.closest('.rev-cpicker-master-wrap').removeData().remove();2708 2709 }2710 2711 };2712 2713 $.fn.tpColorPicker = function(settings) {2714 2715 if(settings && typeof settings === 'string') return this.each(ColorPicker[settings]);2716 2717 return this.each(function() {2718 2719 var $this = $(this),2720 instantiated = $this.hasClass('rev-cpicker-component');2721 2722 if($this.hasClass('rev-cpicker-component')) {2723 2724 $this.tpColorPicker('refresh');2725 return;2726 2727 }2728 2729 var wrap = $('<span class="rev-colorpicker"></span>').data('revcolorinput', $this),2730 box = $('<span class="rev-colorbox" />'),2731 btn = $('<span class="rev-colorbtn" />'),2732 cls = $this.attr('data-wrap-classes'),2733 wrapper = $this.attr('data-wrapper'),2734 ids = $this.attr('data-wrap-id'),2735 txt = $this.attr('data-title'),2736 skin = $this.attr('data-skin'),2737 val = $this.val(),2738 colorValue,2739 defValue;2740 2741 wrap.insertBefore($this).append([box, btn, $this]);2742 2743 if(settings && $.isPlainObject(settings)) {2744 2745 if(!wrapper) wrapper = settings.wrapper;2746 if(!cls) cls = settings.wrapClasses;2747 if(!skin) skin = settings.skin;2748 if(!ids) ids = settings.wrapId;2749 if(!txt) txt = settings.title;2750 2751 defValue = settings.defaultValue;2752 var sets = $this.data('revcp');2753 2754 if(sets) settings = $.extend({}, sets, settings);2755 $this.data('revcp', settings);2756 2757 }2758 2759 if(!cls) cls = defaultClasses;2760 if(cls) wrap.addClass(cls);2761 if(ids) wrap.attr('id', ids);2762 if(!val) {2763 2764 val = defValue || RevColor.defaultValue;2765 $this.val(val);2766 2767 }2768 2769 colorValue = RevColor.process(val);2770 val = colorValue[0];2771 2772 colorValue = colorValue[1] !== 'rgba' || !RevColor.transparentRgba(val, true) ? val : '';2773 box[0].style.background = colorValue;2774 2775 btn[0].innerHTML = txt || langColor || lang.color;2776 $this.attr({type: 'hidden', 'data-color': val}).data('tpcp', box).addClass('rev-cpicker-component');2777 2778 if(skin) wrap.addClass(skin);2779 if(!wrapper) {2780 2781 wrap.addClass('rev-cpicker-master-wrap');2782 2783 }2784 else {2785 2786 wrapper = $(wrapper).addClass('rev-cpicker-master-wrap');2787 wrap.wrap(wrapper);2788 2789 }2790 2791 var initCallback = settings ? settings.init || onInit : false;2792 if(initCallback) initCallback(wrap, $this, val, settings);2793 2794 });2795 2796 };2797 2798 $(function() {2799 2800 $('body').on('click.revcpicker', '.rev-colorpicker', function() {2801 2802 if(!inited) init();2803 currentInput = $(this).data('revcolorinput');2804 2805 var widgetId = currentInput.attr('data-widget-id'),2806 html = currentInput.attr('data-appended-html'),2807 editing = currentInput.attr('data-editing'),2808 data = currentInput.attr('data-colors'),2809 mode = currentInput.attr('data-mode'),2810 settings = currentInput.data('revcp'),2811 lang = currentInput.attr('data-lang'),2812 settingsGradients,2813 customGradients,2814 settingsColors,2815 dataGradients,2816 customColors,2817 dataColors,2818 presets,2819 change,2820 cancel,2821 value,2822 edit,2823 ajax,2824 val;2825 if(data) {2826 2827 data = JSON.parse(data.replace(/\&/g, '"'));2828 if(data.colors) dataColors = data.colors;2829 if(data.gradients) dataGradients = data.gradients;2830 2831 }2832 2833 if(settings) {2834 2835 var colorSets = settings.colors;2836 if(colorSets) {2837 2838 if(colorSets.core) {2839 2840 settingsColors = colorSets.core.colors;2841 settingsGradients = colorSets.core.gradients;2842 2843 }2844 2845 if(colorSets.custom) {2846 2847 customColors = colorSets.custom.colors;2848 customGradients = colorSets.custom.gradients;2849 2850 }2851 2852 }2853 2854 edit = settings.onEdit;2855 ajax = settings.onAjax;2856 change = settings.change;2857 cancel = settings.cancel;2858 2859 if(!lang) lang = settings.lang;2860 if(!mode) mode = settings.mode;2861 if(!html) html = settings.appendedHtml;2862 if(!editing) editing = settings.editing;2863 if(!widgetId) widgetId = settings.widgetId;2864 2865 }2866 2867 if(settingsGradients || settingsColors || customGradients || customColors || dataGradients || dataColors) {2868 2869 presets = {};2870 if(settingsGradients || settingsColors || dataGradients || dataColors) {2871 2872 presets.core = {2873 2874 colors: dataColors || settingsColors || defColors,2875 gradients: dataGradients || settingsGradients || defGradients2876 2877 };2878 2879 }2880 2881 if(customGradients || customColors) {2882 2883 presets.custom = {2884 2885 colors: customColors || defColors,2886 gradients: customGradients || defGradients2887 2888 };2889 2890 }2891 2892 addPresets(presets);2893 2894 }2895 2896 if(!widgetId) widgetId = defWidgetId;2897 if(widgetId) cPicker[0].id = widgetId;2898 2899 if(!html) html = appendedHTML;2900 if(html) appended = $(html).appendTo(mainContainer);2901 2902 if(lang) writeLanguage(lang);2903 if(!mode) mode = defMode;2904 2905 if(!editing) {2906 2907 editing = '';2908 editTitle.style.visibility = 'hidden';2909 2910 }2911 else {2912 2913 editTitle.style.visibility = 'visible';2914 2915 }2916 2917 currentEditing.innerHTML = editing;2918 2919 if(mode === 'single') {2920 2921 isFull = false;2922 gradBtn.hide();2923 colorBtn.show();2924 2925 }2926 else {2927 2928 isFull = true;2929 gradBtn.show();2930 colorBtn.show();2931 2932 }2933 2934 val = currentInput.val() || currentInput.attr('data-color') || RevColor.defaultValue;2935 if(val.split('||').length > 1) {2936 2937 val = RevColor.joinToRgba(val);2938 currentInput.val(val);2939 2940 }2941 2942 value = setValue(val);2943 openingValue = value[0];2944 2945 onEdit = edit || defEdit;2946 onAjax = ajax || defAjax;2947 onCancel = cancel || defCancel;2948 changeCallback = change || defChange;2949 2950 if(value[1] !== 'gradient') colorBtn.data('state', openingValue);2951 else gradBtn.data('state', openingValue);2952 2953 bodies.addClass('rev-colorpicker-open');2954 currentColor = currentInput.data('tpcp');2955 cPicker.data('revcpickerinput', currentInput).addClass('active').show();2956 2957 presetGroups.each(checkGroup).perfectScrollbar('update');2958 openingColor = currentInput.attr('data-color');2959 2960 selectedHex = currentInput.data('hex');2961 $('.rev-cpicker-color').not('.blank').each(checkPreset);2962 2963 });2964 2965 });2966 ...

Full Screen

Full Screen

livecodeserver.js

Source:livecodeserver.js Github

copy

Full Screen

1/*2Language: LiveCode server and revIgniter3Author: Ralf Bitter <rabit@revigniter.com>4Description: Language definition for LiveCode server accounting for revIgniter (a web application framework) characteristics.5Version: 1.0a6Date: 2013-06-037*/8function(hljs) {9 var VARIABLE = {10 className: 'variable', begin: '\\b[gtps][A-Z]+[A-Za-z0-9_\\-]*\\b|\\$_[A-Z]+',11 relevance: 012 };13 var COMMENT = {14 className: 'comment', end: '$',15 variants: [16 hljs.C_BLOCK_COMMENT_MODE,17 hljs.HASH_COMMENT_MODE,18 {19 begin: '--'20 },21 {22 begin: '[^:]//'23 }24 ]25 };26 var TITLE1 = hljs.inherit(hljs.TITLE_MODE, {27 variants: [28 {begin: '\\b_*rig[A-Z]+[A-Za-z0-9_\\-]*'},29 {begin: '\\b_[a-z0-9\\-]+'}30 ]31 });32 var TITLE2 = hljs.inherit(hljs.TITLE_MODE, {begin: '\\b([A-Za-z0-9_\\-]+)\\b'});33 return {34 case_insensitive: false,35 keywords: {36 keyword:37 'after byte bytes english the until http forever descending using line real8 with seventh ' +38 'for stdout finally element word fourth before black ninth sixth characters chars stderr ' +39 'uInt1 uInt1s uInt2 uInt2s stdin string lines relative rel any fifth items from middle mid ' +40 'at else of catch then third it file milliseconds seconds second secs sec int1 int1s int4 ' +41 'int4s internet int2 int2s normal text item last long detailed effective uInt4 uInt4s repeat ' +42 'end repeat URL in try into switch to words https token binfile each tenth as ticks tick ' +43 'system real4 by dateItems without char character ascending eighth whole dateTime numeric short ' +44 'first ftp integer abbreviated abbr abbrev private case while if',45 constant:46 'SIX TEN FORMFEED NINE ZERO NONE SPACE FOUR FALSE COLON CRLF PI COMMA ENDOFFILE EOF EIGHT FIVE ' +47 'QUOTE EMPTY ONE TRUE RETURN CR LINEFEED RIGHT BACKSLASH NULL SEVEN TAB THREE TWO ' +48 'six ten formfeed nine zero none space four false colon crlf pi comma endoffile eof eight five ' +49 'quote empty one true return cr linefeed right backslash null seven tab three two ' +50 'RIVERSION RISTATE FILE_READ_MODE FILE_WRITE_MODE FILE_WRITE_MODE DIR_WRITE_MODE FILE_READ_UMASK ' +51 'FILE_WRITE_UMASK DIR_READ_UMASK DIR_WRITE_UMASK',52 operator:53 'div mod wrap and or bitAnd bitNot bitOr bitXor among not in a an within ' +54 'contains ends with begins the keys of keys',55 built_in:56 'put abs acos aliasReference annuity arrayDecode arrayEncode asin atan atan2 average avg base64Decode ' +57 'base64Encode baseConvert binaryDecode binaryEncode byteToNum cachedURL cachedURLs charToNum ' +58 'cipherNames commandNames compound compress constantNames cos date dateFormat decompress directories ' +59 'diskSpace DNSServers exp exp1 exp2 exp10 extents files flushEvents folders format functionNames global ' +60 'globals hasMemory hostAddress hostAddressToName hostName hostNameToAddress isNumber ISOToMac itemOffset ' +61 'keys len length libURLErrorData libUrlFormData libURLftpCommand libURLLastHTTPHeaders libURLLastRHHeaders ' +62 'libUrlMultipartFormAddPart libUrlMultipartFormData libURLVersion lineOffset ln ln1 localNames log log2 log10 ' +63 'longFilePath lower macToISO matchChunk matchText matrixMultiply max md5Digest median merge millisec ' +64 'millisecs millisecond milliseconds min monthNames num number numToByte numToChar offset open openfiles ' +65 'openProcesses openProcessIDs openSockets paramCount param params peerAddress pendingMessages platform ' +66 'processID random randomBytes replaceText result revCreateXMLTree revCreateXMLTreeFromFile revCurrentRecord ' +67 'revCurrentRecordIsFirst revCurrentRecordIsLast revDatabaseColumnCount revDatabaseColumnIsNull ' +68 'revDatabaseColumnLengths revDatabaseColumnNames revDatabaseColumnNamed revDatabaseColumnNumbered ' +69 'revDatabaseColumnTypes revDatabaseConnectResult revDatabaseCursors revDatabaseID revDatabaseTableNames ' +70 'revDatabaseType revDataFromQuery revdb_closeCursor revdb_columnbynumber revdb_columncount revdb_columnisnull ' +71 'revdb_columnlengths revdb_columnnames revdb_columntypes revdb_commit revdb_connect revdb_connections ' +72 'revdb_connectionerr revdb_currentrecord revdb_cursorconnection revdb_cursorerr revdb_cursors revdb_dbtype ' +73 'revdb_disconnect revdb_execute revdb_iseof revdb_isbof revdb_movefirst revdb_movelast revdb_movenext ' +74 'revdb_moveprev revdb_query revdb_querylist revdb_recordcount revdb_rollback revdb_tablenames ' +75 'revGetDatabaseDriverPath revNumberOfRecords revOpenDatabase revOpenDatabases revQueryDatabase ' +76 'revQueryDatabaseBlob revQueryResult revQueryIsAtStart revQueryIsAtEnd revUnixFromMacPath ' +77 'revXMLAttribute revXMLAttributes revXMLAttributeValues revXMLChildContents revXMLChildNames ' +78 'revXMLFirstChild revXMLMatchingNode revXMLNextSibling revXMLNodeContents revXMLNumberOfChildren ' +79 'revXMLParent revXMLPreviousSibling revXMLRootNode revXMLRPC_CreateRequest revXMLRPC_Documents ' +80 'revXMLRPC_Error revXMLRPC_Execute revXMLRPC_GetHost revXMLRPC_GetMethod revXMLRPC_GetParam revXMLText ' +81 'revXMLRPC_GetParamCount revXMLRPC_GetParamNode revXMLRPC_GetParamType revXMLRPC_GetPath revXMLRPC_GetPort ' +82 'revXMLRPC_GetProtocol revXMLRPC_GetRequest revXMLRPC_GetResponse revXMLRPC_GetSocket revXMLTree ' +83 'revXMLTrees revXMLValidateDTD revZipDescribeItem revZipEnumerateItems revZipOpenArchives round ' +84 'sec secs seconds sha1Digest shell shortFilePath sin specialFolderPath sqrt standardDeviation statRound ' +85 'stdDev sum sysError systemVersion tan tempName tick ticks time to toLower toUpper transpose trunc ' +86 'uniDecode uniEncode upper URLDecode URLEncode URLStatus value variableNames version waitDepth weekdayNames wordOffset ' +87 'add breakpoint cancel clear local variable file word line folder directory URL close socket process ' +88 'combine constant convert create new alias folder directory decrypt delete variable word line folder ' +89 'directory URL dispatch divide do encrypt filter get include intersect kill libURLDownloadToFile ' +90 'libURLFollowHttpRedirects libURLftpUpload libURLftpUploadFile libURLresetAll libUrlSetAuthCallback ' +91 'libURLSetCustomHTTPHeaders libUrlSetExpect100 libURLSetFTPListCommand libURLSetFTPMode libURLSetFTPStopTime ' +92 'libURLSetStatusCallback load multiply socket process post seek rel relative read from process rename ' +93 'replace require resetAll revAddXMLNode revAppendXML revCloseCursor revCloseDatabase revCommitDatabase ' +94 'revCopyFile revCopyFolder revCopyXMLNode revDeleteFolder revDeleteXMLNode revDeleteAllXMLTrees ' +95 'revDeleteXMLTree revExecuteSQL revGoURL revInsertXMLNode revMoveFolder revMoveToFirstRecord revMoveToLastRecord ' +96 'revMoveToNextRecord revMoveToPreviousRecord revMoveToRecord revMoveXMLNode revPutIntoXMLNode revRollBackDatabase ' +97 'revSetDatabaseDriverPath revSetXMLAttribute revXMLRPC_AddParam revXMLRPC_DeleteAllDocuments revXMLAddDTD ' +98 'revXMLRPC_Free revXMLRPC_FreeAll revXMLRPC_DeleteDocument revXMLRPC_DeleteParam revXMLRPC_SetHost ' +99 'revXMLRPC_SetMethod revXMLRPC_SetPort revXMLRPC_SetProtocol revXMLRPC_SetSocket revZipAddItemWithData ' +100 'revZipAddItemWithFile revZipAddUncompressedItemWithData revZipAddUncompressedItemWithFile revZipCancel ' +101 'revZipCloseArchive revZipDeleteItem revZipExtractItemToFile revZipExtractItemToVariable revZipSetProgressCallback ' +102 'revZipRenameItem revZipReplaceItemWithData revZipReplaceItemWithFile revZipOpenArchive send set sort split ' +103 'subtract union unload wait write'104 },105 contains: [106 VARIABLE,107 {108 className: 'keyword',109 begin: '\\bend\\sif\\b'110 },111 {112 className: 'function',113 beginKeywords: 'function', end: '$',114 contains: [115 VARIABLE,116 TITLE2,117 hljs.APOS_STRING_MODE,118 hljs.QUOTE_STRING_MODE,119 hljs.BINARY_NUMBER_MODE,120 hljs.C_NUMBER_MODE,121 TITLE1122 ]123 },124 {125 className: 'function',126 beginKeywords: 'end', end: '$',127 contains: [128 TITLE2,129 TITLE1130 ]131 },132 {133 className: 'command',134 beginKeywords: 'command on', end: '$',135 contains: [136 VARIABLE,137 TITLE2,138 hljs.APOS_STRING_MODE,139 hljs.QUOTE_STRING_MODE,140 hljs.BINARY_NUMBER_MODE,141 hljs.C_NUMBER_MODE,142 TITLE1143 ]144 },145 {146 className: 'command',147 beginKeywords: 'end', end: '$',148 contains: [149 TITLE2,150 TITLE1151 ]152 },153 {154 className: 'preprocessor',155 begin: '<\\?rev|<\\?lc|<\\?livecode',156 relevance: 10157 },158 {159 className: 'preprocessor',160 begin: '<\\?'161 },162 {163 className: 'preprocessor',164 begin: '\\?>'165 },166 COMMENT,167 hljs.APOS_STRING_MODE,168 hljs.QUOTE_STRING_MODE,169 hljs.BINARY_NUMBER_MODE,170 hljs.C_NUMBER_MODE,171 TITLE1172 ],173 illegal: ';$|^\\[|^='174 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { rev } = require("fast-check-monorepo");2console.log(rev("hello"));3const { rev } = require("fast-check-monorepo");4console.log(rev("hello"));5const { rev } = require("fast-check-monorepo");6console.log(rev("hello"));7- [fast-check](

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { rev } = require('fast-check-monorepo');3fc.assert(4 fc.property(fc.array(fc.integer()), (arr) => {5 return rev(rev(arr)).join(',') === arr.join(',');6 })7);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const { rev } = require("fast-check-monorepo");3 .string()4 .filter(s => s.length > 0)5 .map(rev);6fc.assert(7 fc.property(revArb, s => {8 const s2 = rev(rev(s));9 return s2 === s;10 })11);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { rev } = require('fast-check-monorepo');2const assert = require('assert');3assert.strictEqual(rev('abc'), 'cba');4assert.strictEqual(rev(''), '');5assert.strictEqual(rev('a'), 'a');6MIT © [Ludovic HENIN](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { rev } = require("fast-check-monorepo");2console.log(rev("abcd"));3const { rev } = require("fast-check-monorepo");4const { revArb } = require("fast-check-monorepo");5fc.assert(6 fc.property(revArb(), (str) => {7 return rev(rev(str)) === str;8 })9);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { rev } = require("fast-check-monorepo");2const { property } = require("fast-check");3const { expect } = require("chai");4describe("test3", () => {5 it("should invert the array", () => {6 property(7 fc.array(fc.integer()),8 (arr) => {9 expect(rev(rev(arr))).to.deep.equal(arr);10 }11 );12 });13});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful