1/* 2* jPicker 1.1.6 3* 4* jQuery Plugin for Photoshop style color picker 5* 6* Copyright (c) 2010 Christopher T. Tillman 7* Digital Magic Productions, Inc. (http://www.digitalmagicpro.com/) 8* MIT style license, FREE to use, alter, copy, sell, and especially ENHANCE 9* 10* Painstakingly ported from John Dyers' excellent work on his own color picker based on the Prototype framework. 11* 12* John Dyers' website: (http://johndyer.name) 13* Color Picker page: (http://johndyer.name/post/2007/09/PhotoShop-like-JavaScript-Color-Picker.aspx) 14* 15*/ 16 17var zIndexNewValue = 200000; 18(function ($, version) { 19 Math.precision = function (value, precision) { 20 if (precision === undefined) precision = 0; 21 return Math.round(value * Math.pow(10, precision)) / Math.pow(10, precision); 22 }; 23 var Slider = // encapsulate slider functionality for the ColorMap and ColorBar - could be useful to use a jQuery UI draggable for this with certain extensions 24 function (bar, options) { 25 var $this = this, // private properties, methods, and events - keep these variables and classes invisible to outside code 26 arrow = bar.find('img:first'), // the arrow image to drag 27 minX = 0, 28 maxX = 100, 29 rangeX = 100, 30 minY = 0, 31 maxY = 100, 32 rangeY = 100, 33 x = 0, 34 y = 0, 35 offset, 36 timeout, 37 changeEvents = new Array(), 38 fireChangeEvents = 39 function (context) { 40 for (var i = 0; i < changeEvents.length; i++) changeEvents[i].call($this, $this, context); 41 }, 42 mouseDown = // bind the mousedown to the bar not the arrow for quick snapping to the clicked location 43 function (e) { 44 var off = bar.offset(); 45 offset = { l: off.left | 0, t: off.top | 0 }; 46 clearTimeout(timeout); 47 timeout = setTimeout( // using setTimeout for visual updates - once the style is updated the browser will re-render internally allowing the next Javascript to run 48 function () { 49 setValuesFromMousePosition.call($this, e); 50 }, 0); 51 // Bind mousemove and mouseup event to the document so it responds when dragged of of the bar - we will unbind these when on mouseup to save processing 52 $(document).bind('mousemove', mouseMove).bind('mouseup', mouseUp); 53 e.preventDefault(); // don't try to select anything or drag the image to the desktop 54 }, 55 mouseMove = // set the values as the mouse moves 56 function (e) { 57 clearTimeout(timeout); 58 timeout = setTimeout( 59 function () { 60 setValuesFromMousePosition.call($this, e); 61 }, 0); 62 e.stopPropagation(); 63 e.preventDefault(); 64 return false; 65 }, 66 mouseUp = // unbind the document events - they aren't needed when not dragging 67 function (e) { 68 $(document).unbind('mouseup', mouseUp).unbind('mousemove', mouseMove); 69 e.stopPropagation(); 70 e.preventDefault(); 71 return false; 72 }, 73 setValuesFromMousePosition = // calculate mouse position and set value within the current range 74 function (e) { 75 var locX = e.pageX - offset.l, 76 locY = e.pageY - offset.t, 77 barW = bar.w, // local copies for YUI compressor 78 barH = bar.h; 79 // keep the arrow within the bounds of the bar 80 if (locX < 0) locX = 0; 81 else if (locX > barW) locX = barW; 82 if (locY < 0) locY = 0; 83 else if (locY > barH) locY = barH; 84 val.call($this, 'xy', { x: ((locX / barW) * rangeX) + minX, y: ((locY / barH) * rangeY) + minY }); 85 }, 86 draw = 87 function () { 88 var arrowOffsetX = 0, 89 arrowOffsetY = 0, 90 barW = bar.w, 91 barH = bar.h, 92 arrowW = arrow.w, 93 arrowH = arrow.h; 94 setTimeout( 95 function () { 96 if (rangeX > 0) // range is greater than zero 97 { 98 // constrain to bounds 99 if (x == maxX) arrowOffsetX = barW; 100 else arrowOffsetX = ((x / rangeX) * barW) | 0; 101 } 102 if (rangeY > 0) // range is greater than zero 103 { 104 // constrain to bounds 105 if (y == maxY) arrowOffsetY = barH; 106 else arrowOffsetY = ((y / rangeY) * barH) | 0; 107 } 108 // if arrow width is greater than bar width, center arrow and prevent horizontal dragging 109 if (arrowW >= barW) arrowOffsetX = (barW >> 1) - (arrowW >> 1); // number >> 1 - superfast bitwise divide by two and truncate (move bits over one bit discarding lowest) 110 else arrowOffsetX -= arrowW >> 1; 111 // if arrow height is greater than bar height, center arrow and prevent vertical dragging 112 if (arrowH >= barH) arrowOffsetY = (barH >> 1) - (arrowH >> 1); 113 else arrowOffsetY -= arrowH >> 1; 114 // set the arrow position based on these offsets 115 arrow.css({ left: arrowOffsetX + 'px', top: arrowOffsetY + 'px' }); 116 }, 0); 117 }, 118 val = 119 function (name, value, context) { 120 var set = value !== undefined; 121 if (!set) { 122 if (name === undefined || name == null) name = 'xy'; 123 switch (name.toLowerCase()) { 124 case 'x': return x; 125 case 'y': return y; 126 case 'xy': 127 default: return { x: x, y: y }; 128 } 129 } 130 if (context != null && context == $this) return; 131 var changed = false, 132 newX, 133 newY; 134 if (name == null) name = 'xy'; 135 switch (name.toLowerCase()) { 136 case 'x': 137 newX = value && (value.x && value.x | 0 || value | 0) || 0; 138 break; 139 case 'y': 140 newY = value && (value.y && value.y | 0 || value | 0) || 0; 141 break; 142 case 'xy': 143 default: 144 newX = value && value.x && value.x | 0 || 0; 145 newY = value && value.y && value.y | 0 || 0; 146 break; 147 } 148 if (newX != null) { 149 if (newX < minX) newX = minX; 150 else if (newX > maxX) newX = maxX; 151 if (x != newX) { 152 x = newX; 153 changed = true; 154 } 155 } 156 if (newY != null) { 157 if (newY < minY) newY = minY; 158 else if (newY > maxY) newY = maxY; 159 if (y != newY) { 160 y = newY; 161 changed = true; 162 } 163 } 164 changed && fireChangeEvents.call($this, context || $this); 165 }, 166 range = 167 function (name, value) { 168 var set = value !== undefined; 169 if (!set) { 170 if (name === undefined || name == null) name = 'all'; 171 switch (name.toLowerCase()) { 172 case 'minx': return minX; 173 case 'maxx': return maxX; 174 case 'rangex': return { minX: minX, maxX: maxX, rangeX: rangeX }; 175 case 'miny': return minY; 176 case 'maxy': return maxY; 177 case 'rangey': return { minY: minY, maxY: maxY, rangeY: rangeY }; 178 case 'all': 179 default: return { minX: minX, maxX: maxX, rangeX: rangeX, minY: minY, maxY: maxY, rangeY: rangeY }; 180 } 181 } 182 var changed = false, 183 newMinX, 184 newMaxX, 185 newMinY, 186 newMaxY; 187 if (name == null) name = 'all'; 188 switch (name.toLowerCase()) { 189 case 'minx': 190 newMinX = value && (value.minX && value.minX | 0 || value | 0) || 0; 191 break; 192 case 'maxx': 193 newMaxX = value && (value.maxX && value.maxX | 0 || value | 0) || 0; 194 break; 195 case 'rangex': 196 newMinX = value && value.minX && value.minX | 0 || 0; 197 newMaxX = value && value.maxX && value.maxX | 0 || 0; 198 break; 199 case 'miny': 200 newMinY = value && (value.minY && value.minY | 0 || value | 0) || 0; 201 break; 202 case 'maxy': 203 newMaxY = value && (value.maxY && value.maxY | 0 || value | 0) || 0; 204 break; 205 case 'rangey': 206 newMinY = value && value.minY && value.minY | 0 || 0; 207 newMaxY = value && value.maxY && value.maxY | 0 || 0; 208 break; 209 case 'all': 210 default: 211 newMinX = value && value.minX && value.minX | 0 || 0; 212 newMaxX = value && value.maxX && value.maxX | 0 || 0; 213 newMinY = value && value.minY && value.minY | 0 || 0; 214 newMaxY = value && value.maxY && value.maxY | 0 || 0; 215 break; 216 } 217 if (newMinX != null && minX != newMinX) { 218 minX = newMinX; 219 rangeX = maxX - minX; 220 } 221 if (newMaxX != null && maxX != newMaxX) { 222 maxX = newMaxX; 223 rangeX = maxX - minX; 224 } 225 if (newMinY != null && minY != newMinY) { 226 minY = newMinY; 227 rangeY = maxY - minY; 228 } 229 if (newMaxY != null && maxY != newMaxY) { 230 maxY = newMaxY; 231 rangeY = maxY - minY; 232 } 233 }, 234 bind = 235 function (callback) { 236 if ($.isFunction(callback)) changeEvents.push(callback); 237 }, 238 unbind = 239 function (callback) { 240 if (!$.isFunction(callback)) return; 241 var i; 242 while ((i = $.inArray(callback, changeEvents)) != -1) changeEvents.splice(i, 1); 243 }, 244 destroy = 245 function () { 246 // unbind all possible events and null objects 247 $(document).unbind('mouseup', mouseUp).unbind('mousemove', mouseMove); 248 bar.unbind('mousedown', mouseDown);
249 bar = null; 250 arrow = null; 251 changeEvents = null; 252 }; 253 $.extend(true, $this, // public properties, methods, and event bindings - these we need to access from other controls 254 { 255 val: val, 256 range: range, 257 bind: bind, 258 unbind: unbind, 259 destroy: destroy 260 }); 261 // initialize this control 262 arrow.src = options.arrow && options.arrow.image; 263 arrow.w = options.arrow && options.arrow.width || arrow.width(); 264 arrow.h = options.arrow && options.arrow.height || arrow.height(); 265 bar.w = options.map && options.map.width || bar.width(); 266 bar.h = options.map && options.map.height || bar.height(); 267 // bind mousedown event 268 bar.bind('mousedown', mouseDown); 269 bind.call($this, draw); 270 }, 271 ColorValuePicker = // controls for all the input elements for the typing in color values 272 function (picker, color, bindedHex, alphaPrecision) { 273 var $this = this, // private properties and methods 274 inputs = picker.find('td.Text input'), 275 red = inputs.eq(3), 276 green = inputs.eq(4), 277 blue = inputs.eq(5), 278 alpha = inputs.length > 7 ? inputs.eq(6) : null, 279 hue = inputs.eq(0), 280 saturation = inputs.eq(1), 281 value = inputs.eq(2), 282 hex = inputs.eq(inputs.length > 7 ? 7 : 6), 283 ahex = inputs.length > 7 ? inputs.eq(8) : null, 284 keyDown = // input box key down - use arrows to alter color 285 function (e) { 286 if (e.target.value == '' && e.target != hex.get(0) && (bindedHex != null && e.target != bindedHex.get(0) || bindedHex == null)) return; 287 if (!validateKey(e)) return e; 288 switch (e.target) { 289 case red.get(0): 290 switch (e.keyCode) { 291 case 38: 292 red.val(setValueInRange.call($this, (red.val() << 0) + 1, 0, 255)); 293 color.val('r', red.val(), e.target); 294 return false; 295 case 40: 296 red.val(setValueInRange.call($this, (red.val() << 0) - 1, 0, 255)); 297 color.val('r', red.val(), e.target); 298 return false; 299 } 300 break; 301 case green.get(0): 302 switch (e.keyCode) { 303 case 38: 304 green.val(setValueInRange.call($this, (green.val() << 0) + 1, 0, 255)); 305 color.val('g', green.val(), e.target); 306 return false; 307 case 40: 308 green.val(setValueInRange.call($this, (green.val() << 0) - 1, 0, 255)); 309 color.val('g', green.val(), e.target); 310 return false; 311 } 312 break; 313 case blue.get(0): 314 switch (e.keyCode) { 315 case 38: 316 blue.val(setValueInRange.call($this, (blue.val() << 0) + 1, 0, 255)); 317 color.val('b', blue.val(), e.target); 318 return false; 319 case 40: 320 blue.val(setValueInRange.call($this, (blue.val() << 0) - 1, 0, 255)); 321 color.val('b', blue.val(), e.target); 322 return false; 323 } 324 break; 325 case alpha && alpha.get(0): 326 switch (e.keyCode) { 327 case 38: 328 alpha.val(setValueInRange.call($this, parseFloat(alpha.val()) + 1, 0, 100)); 329 color.val('a', Math.precision((alpha.val() * 255) / 100, alphaPrecision), e.target); 330 return false; 331 case 40: 332 alpha.val(setValueInRange.call($this, parseFloat(alpha.val()) - 1, 0, 100)); 333 color.val('a', Math.precision((alpha.val() * 255) / 100, alphaPrecision), e.target); 334 return false; 335 } 336 break; 337 case hue.get(0): 338 switch (e.keyCode) { 339 case 38: 340 hue.val(setValueInRange.call($this, (hue.val() << 0) + 1, 0, 360)); 341 color.val('h', hue.val(), e.target); 342 return false; 343 case 40: 344 hue.val(setValueInRange.call($this, (hue.val() << 0) - 1, 0, 360)); 345 color.val('h', hue.val(), e.target); 346 return false; 347 } 348 break; 349 case saturation.get(0): 350 switch (e.keyCode) { 351 case 38: 352 saturation.val(setValueInRange.call($this, (saturation.val() << 0) + 1, 0, 100)); 353 color.val('s', saturation.val(), e.target); 354 return false; 355 case 40: 356 saturation.val(setValueInRange.call($this, (saturation.val() << 0) - 1, 0, 100)); 357 color.val('s', saturation.val(), e.target); 358 return false; 359 } 360 break; 361 case value.get(0): 362 switch (e.keyCode) { 363 case 38: 364 value.val(setValueInRange.call($this, (value.val() << 0) + 1, 0, 100)); 365 color.val('v', value.val(), e.target); 366 return false; 367 case 40: 368 value.val(setValueInRange.call($this, (value.val() << 0) - 1, 0, 100)); 369 color.val('v', value.val(), e.target); 370 return false; 371 } 372 break; 373 } 374 }, 375 keyUp = // input box key up - validate value and set color 376 function (e) { 377 if (e.target.value == '' && e.target != hex.get(0) && (bindedHex != null && e.target != bindedHex.get(0) || bindedHex == null)) return; 378 if (!validateKey(e)) return e; 379 switch (e.target) { 380 case red.get(0): 381 red.val(setValueInRange.call($this, red.val(), 0, 255)); 382 color.val('r', red.val(), e.target); 383 break; 384 case green.get(0): 385 green.val(setValueInRange.call($this, green.val(), 0, 255)); 386 color.val('g', green.val(), e.target); 387 break; 388 case blue.get(0): 389 blue.val(setValueInRange.call($this, blue.val(), 0, 255)); 390 color.val('b', blue.val(), e.target); 391 break; 392 case alpha && alpha.get(0): 393 alpha.val(setValueInRange.call($this, alpha.val(), 0, 100)); 394 color.val('a', Math.precision((alpha.val() * 255) / 100, alphaPrecision), e.target); 395 break; 396 case hue.get(0): 397 hue.val(setValueInRange.call($this, hue.val(), 0, 360)); 398 color.val('h', hue.val(), e.target); 399 break; 400 case saturation.get(0): 401 saturation.val(setValueInRange.call($this, saturation.val(), 0, 100)); 402 color.val('s', saturation.val(), e.target); 403 break; 404 case value.get(0): 405 value.val(setValueInRange.call($this, value.val(), 0, 100)); 406 color.val('v', value.val(), e.target); 407 break; 408 case hex.get(0): 409 hex.val(hex.val().replace(/[^a-fA-F0-9]/g, '').toLowerCase().substring(0, 6)); 410 bindedHex && bindedHex.val(hex.val()); 411 color.val('hex', hex.val() != '' ? hex.val() : null, e.target); 412 break; 413 case bindedHex && bindedHex.get(0): 414 bindedHex.val(bindedHex.val().replace(/[^a-fA-F0-9]/g, '').toLowerCase().substring(0, 6)); 415 hex.val(bindedHex.val()); 416 color.val('hex', bindedHex.val() != '' ? bindedHex.val() : null, e.target); 417 break; 418 case ahex && ahex.get(0): 419 ahex.val(ahex.val().replace(/[^a-fA-F0-9]/g, '').toLowerCase().substring(0, 2)); 420 color.val('a', ahex.val() != null ? parseInt(ahex.val(), 16) : null, e.target); 421 break; 422 } 423 }, 424 blur = // input box blur - reset to original if value empty 425 function (e) { 426 if (color.val() != null) { 427 switch (e.target) { 428 case red.get(0): red.val(color.val('r')); break; 429 case green.get(0): green.val(color.val('g')); break; 430 case blue.get(0): blue.val(color.val('b')); break; 431 case alpha && alpha.get(0): alpha.val(Math.precision((color.val('a') * 100) / 255, alph
431aPrecision)); break; 432 case hue.get(0): hue.val(color.val('h')); break; 433 case saturation.get(0): saturation.val(color.val('s')); break; 434 case value.get(0): value.val(color.val('v')); break; 435 case hex.get(0): 436 case bindedHex && bindedHex.get(0): 437 hex.val(color.val('hex')); 438 bindedHex && bindedHex.val(color.val('hex')); 439 break; 440 case ahex && ahex.get(0): ahex.val(color.val('ahex').substring(6)); break; 441 } 442 } 443 }, 444 validateKey = // validate key 445 function (e) { 446 switch (e.keyCode) { 447 case 9: 448 case 16: 449 case 29: 450 case 37: 451 case 39: 452 return false; 453 case 'c'.charCodeAt(): 454 case 'v'.charCodeAt(): 455 if (e.ctrlKey) return false; 456 } 457 return true; 458 }, 459 setValueInRange = // constrain value within range 460 function (value, min, max) { 461 if (value == '' || isNaN(value)) return min; 462 if (value > max) return max; 463 if (value < min) return min; 464 return value; 465 }, 466 colorChanged = 467 function (ui, context) { 468 var all = ui.val('all'); 469 if (context != red.get(0)) red.val(all != null ? all.r : ''); 470 if (context != green.get(0)) green.val(all != null ? all.g : ''); 471 if (context != blue.get(0)) blue.val(all != null ? all.b : ''); 472 if (alpha && context != alpha.get(0)) alpha.val(all != null ? Math.precision((all.a * 100) / 255, alph
472aPrecision) : ''); 473 if (context != hue.get(0)) hue.val(all != null ? all.h : ''); 474 if (context != saturation.get(0)) saturation.val(all != null ? all.s : ''); 475 if (context != value.get(0)) value.val(all != null ? all.v : ''); 476 if (context != hex.get(0) && (bindedHex && context != bindedHex.get(0) || !bindedHex)) hex.val(all != null ? all.hex : ''); 477 if (bindedHex && context != bindedHex.get(0) && context != hex.get(0)) bindedHex.val(all != null ? all.hex : ''); 478 if (ahex && context != ahex.get(0)) ahex.val(all != null ? all.ahex.substring(6) : ''); 479 }, 480 destroy = 481 function () { 482 // unbind all events and null objects 483 red.add(green).add(blue).add(alpha).add(hue).add(saturation).add(value).add(hex).add(bindedHex).add(ahex).unbind('keyup', keyUp).unbind('blur', blur); 484 red.add(green).add(blue).add(alpha).add(hue).add(saturation).add(value).unbind('keydown', keyDown); 485 color.unbind(colorChanged); 486 red = null; 487 green = null; 488 blue = null; 489 alpha = null; 490 hue = null; 491 saturation = null; 492 value = null; 493 hex = null; 494 ahex = null; 495 }; 496 $.extend(true, $this, // public properties and methods 497 { 498 destroy: destroy 499 }); 500 red.add(green).add(blue).add(alpha).add(hue).add(saturation).add(value).add(hex).add(bindedHex).add(ahex).bind('keyup', keyUp).bind('blur', blur); 501 red.add(green).add(blue).add(alpha).add(hue).add(saturation).add(value).bind('keydown', keyDown); 502 color.bind(colorChanged); 503 }; 504 $.jPicker = 505 { 506 List: [], // array holding references to each active instance of the control 507 Color: // color object - we will be able to assign by any color space type or retrieve any color space info 508 // we want this public so we can optionally assign new color objects to initial values using inputs other than a string hex value (also supported) 509 function (init) { 510 var $this = this, 511 r, 512 g, 513 b, 514 a, 515 h, 516 s, 517 v, 518 changeEvents = new Array(), 519 fireChangeEvents = 520 function (context) { 521 for (var i = 0; i < changeEvents.length; i++) changeEvents[i].call($this, $this, context); 522 }, 523 val = 524 function (name, value, context) { 525 var set = value !== undefined; 526 if (!set) { 527 if (name === undefined || name == null || name == '') name = 'all'; 528 if (r == null) return null; 529 switch (name.toLowerCase()) { 530 case 'ahex': return ColorMethods.rgbaToHex({ r: r, g: g, b: b, a: a }); 531 case 'hex': return val('ahex').substring(0, 6); 532 case 'all': return { r: r, g: g, b: b, a: a, h: h, s: s, v: v, hex: val.call($this, 'hex'), ahex: val.call($this, 'ahex') }; 533 default: 534 var ret = {}; 535 for (var i = 0; i < name.length; i++) { 536 switch (name.charAt(i)) { 537 case 'r': 538 if (name.length == 1) ret = r; 539 else ret.r = r; 540 break; 541 case 'g': 542 if (name.length == 1) ret = g; 543 else ret.g = g; 544 break; 545 case 'b': 546 if (name.length == 1) ret = b; 547 else ret.b = b; 548 break; 549 case 'a': 550 if (name.length == 1) ret = a; 551 else ret.a = a; 552 break; 553 case 'h': 554 if (name.length == 1) ret = h; 555 else ret.h = h; 556 break; 557 case 's': 558 if (name.length == 1) ret = s; 559 else ret.s = s; 560 break; 561 case 'v': 562 if (name.length == 1) ret = v; 563 else ret.v = v; 564 break; 565 } 566 } 567 return ret == {} ? val.call($this, 'all') : ret; 568 break; 569 } 570 } 571 if (context != null && context == $this) return; 572 var changed = false; 573 if (name == null) name = ''; 574 if (value == null) { 575 if (r != null) { 576 r = null; 577 changed = true; 578 } 579 if (g != null) { 580 g = null; 581 changed = true; 582 } 583 if (b != null) { 584 b = null; 585 changed = true; 586 } 587 if (a != null) { 588 a = null; 589 changed = true; 590 } 591 if (h != null) { 592 h = null; 593 changed = true; 594 } 595 if (s != null) { 596 s = null; 597 changed = true; 598 } 599 if (v != null) { 600 v = null; 601 changed = true; 602 } 603 changed && fireChangeEvents.call($this, context || $this); 604 return; 605 } 606 switch (name.toLowerCase()) { 607 case 'ahex': 608 case 'hex': 609 var ret = ColorMethods.hexToRgba(value && (value.ahex || value.hex) || value || '00000000'); 610 val.call($this, 'rgba', { r: ret.r, g: ret.g, b: ret.b, a: name == 'ahex' ? ret.a : a != null ? a : 255 }, context); 611 break; 612 default: 613 if (value && (value.ahex != null || value.hex != null)) { 614 val.call($this, 'ahex', value.ahex || value.hex || '00000000', context); 615 return; 616 } 617 var newV = {}, rgb = false, hsv = false; 618 if (value.r !== undefined && !name.indexOf('r') == -1) name += 'r'; 619 if (value.g !== undefined && !name.indexOf('g') == -1) name += 'g'; 620 if (value.b !== undefined && !name.indexOf('b') == -1) name += 'b'; 621 if (value.a !== undefined && !name.indexOf('a') == -1) name += 'a'; 622 if (value.h !== undefined && !name.indexOf('h') == -1) name += 'h'; 623 if (value.s !== undefined && !name.indexOf('s') == -1) name += 's'; 624 if (value.v !== undefined && !name.indexOf('v') == -1) name += 'v'; 625 for (var i = 0; i < name.length; i++) { 626 switch (name.charAt(i)) { 627 case 'r': 628 if (hsv) continue; 629 rgb = true; 630 newV.r = value && value.r && value.r | 0 || value && value | 0 || 0; 631 if (newV.r < 0) newV.r = 0; 632 else if (newV.r > 255) newV.r = 255; 633 if (r != newV.r) { 634 r = newV.r; 635 changed = true; 636 } 637 break; 638 case 'g': 639 if (hsv) continue; 640 rgb = true; 641 newV.g = value && value.g && value.g | 0 || value && value | 0 || 0; 642 if (newV.g < 0) newV.g = 0; 643 else if (newV.g > 255) newV.g = 255; 644 if (g != newV.g) { 645 g = newV.g; 646 changed = true; 647 } 648 break; 649 case 'b': 650 if (hsv) continue; 651 rgb = true; 652 newV.b = value && value.b && value.b | 0 || value && value | 0 || 0; 653 if (newV.b < 0) newV.b = 0; 654 else if (newV.b > 255) newV.b = 255; 655 if (b != newV.b) { 656 b = newV.b; 657 changed = true; 658 } 659 break; 660 case 'a': 661 newV.a = value && value.a != null ? value.a | 0 : value != null ? value | 0 : 255; 662 if (newV.a < 0) newV.a = 0; 663 else if (newV.a > 255) newV.a = 255; 664 if (a != newV.a) { 665 a = newV.a; 666 changed = true; 667 } 668 break; 669 case 'h': 670 if (rgb) continue; 671 hsv = true; 672 newV.h = value && value.h && value.h | 0 || value && value | 0 || 0; 673 if (newV.h < 0) newV.h = 0; 674 else if (newV.h > 360) newV.h = 360; 675 if (h != newV.h) { 676 h = newV.h; 677 changed = true; 678 } 679 break; 680 case 's': 681 if (rgb) continue; 682 hsv = true; 683 newV.s = value && value.s != null ? value.s | 0 : value != null ? value | 0 : 100; 684 if (newV.s < 0) newV.s = 0; 685 else if (newV.s > 100) newV.s = 100; 686 if (s != newV.s) { 687 s = newV.s; 688 changed = true; 689 } 690 break; 691 case 'v': 692 if (rgb) continue; 693 hsv = true; 694 newV.v = value && value.v != null ? value.v | 0 : value != null ? value | 0 : 100; 695 if (newV.v < 0) newV.v = 0; 696 else if (newV.v > 100) newV.v = 100; 697 if (v != newV.v) { 698 v = newV.v; 699 changed = true; 700 } 701 break; 702 } 703 } 704 if (changed) { 705 if (rgb) { 706 r = r || 0; 707 g = g || 0; 708 b = b || 0; 709 var ret = ColorMethods.rgbToHsv({ r: r, g: g, b: b }); 710 h = ret.h; 711 s = ret.s; 712 v = ret.v; 713 } 714 else if (hsv) { 715 h = h || 0; 716 s = s != null ? s : 100; 717 v = v != null ? v : 100; 718 var ret = ColorMethods.hsvToRgb({ h: h, s: s, v: v }); 719 r = ret.r; 720 g = ret.g; 721 b = ret.b; 722 } 723 a = a != null ? a : 255; 724 fireChangeEvents.call($this, context || $this); 725 } 726 break; 727 } 728 }, 729 bind = 730 function (callback) { 731 if ($.isFunction(callback)) changeEvents.push(callback); 732 }, 733 unbind = 734 function (callback) { 735 if (!$.isFunction(callback)) return; 736 var i; 737 while ((i = $.inArray(callback, changeEvents)) != -1) changeEvents.splice(i, 1); 738 }, 739 destroy = 740 function () { 741 changeEvents = null; 742 } 743 $.extend(true, $this, // public properties and methods 744 { 745 val: val, 746 bind: bind, 747 unbind: unbind, 748 destroy: destroy 749 }); 750 if (init) { 751 if (init.ahex != null) val('ahex', init); 752 else if (init.hex != null) val((init.a != null ? 'a' : '') + 'hex', init.a != null ? { ahex: init.hex + ColorMethods.intToHex(init.a)} : init); 753 else if (init.r != null && init.g != null && init.b != null) val('rgb' + (init.a != null ? 'a' : ''), init); 754 else if (init.h != null && init.s != null && init.v != null) val('hsv' + (init.a != null ? 'a' : ''), init); 755 } 756 }, 757 ColorMethods: // color conversion methods - make public to give use to external scripts 758 { 759 hexToRgba: 760 function (hex) { 761 hex = this.validateHex(hex); 762 if (hex == '') return { r: null, g: null, b: null, a: null }; 763 var r = '00', g = '00', b = '00', a = '255'; 764 if (hex.length == 6) hex += 'ff'; 765 if (hex.length > 6) { 766 r = hex.substring(0, 2); 767 g = hex.substring(2, 4); 768 b = hex.substring(4, 6); 769 a = hex.substring(6, hex.length); 770 } 771 else { 772 if (hex.length > 4) { 773 r = hex.substring(4, hex.length); 774 hex = hex.substring(0, 4); 775 } 776 if (hex.length > 2) { 777 g = hex.substring(2, hex.length); 778 hex = hex.substring(0, 2); 779 } 780 if (hex.length > 0) b = hex.substr
780ing(0, hex.length); 781 } 782 return { r: this.hexToInt(r), g: this.hexToInt(g), b: this.hexToInt(b), a: this.hexToInt(a) }; 783 }, 784 validateHex: 785 function (hex) { 786 hex = hex.toLowerCase().replace(/[^a-f0-9]/g, ''); 787 if (hex.length > 8) hex = hex.substring(0, 8); 788 return hex; 789 }, 790 rgbaToHex: 791 function (rgba) { 792 return this.intToHex(rgba.r) + this.intToHex(rgba.g) + this.intToHex(rgba.b) + this.intToHex(rgba.a); 793 }, 794 intToHex: 795 function (dec) { 796 var result = (dec | 0).toString(16); 797 if (result.length == 1) result = ('0' + result); 798 return result.toLowerCase(); 799 }, 800 hexToInt: 801 function (hex) { 802 return parseInt(hex, 16); 803 }, 804 rgbToHsv: 805 function (rgb) { 806 var r = rgb.r / 255, g = rgb.g / 255, b = rgb.b / 255, hsv = { h: 0, s: 0, v: 0 }, min = 0, max = 0, delta; 807 if (r >= g && r >= b) { 808 max = r; 809 min = g > b ? b : g; 810 } 811 else if (g >= b && g >= r) { 812 max = g; 813 min = r > b ? b : r; 814 } 815 else { 816 max = b; 817 min = g > r ? r : g; 818 } 819 hsv.v = max; 820 hsv.s = max ? (max - min) / max : 0; 821 if (!hsv.s) hsv.h = 0; 822 else { 823 delta = max - min; 824 if (r == max) hsv.h = (g - b) / delta; 825 else if (g == max) hsv.h = 2 + (b - r) / delta; 826 else hsv.h = 4 + (r - g) / delta; 827 hsv.h = parseInt(hsv.h * 60); 828 if (hsv.h < 0) hsv.h += 360; 829 } 830 hsv.s = (hsv.s * 100) | 0; 831 hsv.v = (hsv.v * 100) | 0; 832 return hsv; 833 }, 834 hsvToRgb: 835 function (hsv) { 836 var rgb = { r: 0, g: 0, b: 0, a: 100 }, h = hsv.h, s = hsv.s, v = hsv.v; 837 if (s == 0) { 838 if (v == 0) rgb.r = rgb.g = rgb.b = 0; 839 else rgb.r = rgb.g = rgb.b = (v * 255 / 100) | 0; 840 } 841 else { 842 if (h == 360) h = 0; 843 h /= 60; 844 s = s / 100; 845 v = v / 100; 846 var i = h | 0, 847 f = h - i, 848 p = v * (1 - s), 849 q = v * (1 - (s * f)), 850 t = v * (1 - (s * (1 - f))); 851 switch (i) { 852 case 0: 853 rgb.r = v; 854 rgb.g = t; 855 rgb.b = p; 856 break; 857 case 1: 858 rgb.r = q; 859 rgb.g = v; 860 rgb.b = p; 861 break; 862 case 2: 863 rgb.r = p; 864 rgb.g = v; 865 rgb.b = t; 866 break; 867 case 3: 868 rgb.r = p; 869 rgb.g = q; 870 rgb.b = v; 871 break; 872 case 4: 873 rgb.r = t; 874 rgb.g = p; 875 rgb.b = v; 876 break; 877 case 5: 878 rgb.r = v; 879 rgb.g = p; 880 rgb.b = q; 881 break; 882 } 883 rgb.r = (rgb.r * 255) | 0; 884 rgb.g = (rgb.g * 255) | 0; 885 rgb.b = (rgb.b * 255) | 0; 886 } 887 return rgb; 888 } 889 } 890}; 891var Color = $.jPicker.Color, List = $.jPicker.List, ColorMethods = $.jPicker.ColorMethods; // local copies for YUI compressor 892$.fn.jPicker = 893 function (options) { 894 var $arguments = arguments; 895 return this.each( 896 function () { 897 var $this = this, settings = $.extend(true, {}, $.fn.jPicker.defaults, options); // local copies for YUI compressor 898 if ($($this).get(0).nodeName.toLowerCase() == 'input') // Add color picker icon if binding to an input element and bind the events to the input 899 { 900 $.extend(true, settings, 901 { 902 window: 903 { 904 bindToInput: true, 905 expandable: true, 906 input: $($this) 907 } 908 }); 909 if ($($this).val() == '') { 910 settings.color.active = new Color({ hex: null });
911 settings.color.current = new Color({ hex: null }); 912 } 913 else if (ColorMethods.validateHex($($this).val())) { 914 settings.color.active = new Color({ hex: $($this).val(), a: settings.color.active.val('a') }); 915 settings.color.current = new Color({ hex: $($this).val(), a: settings.color.active.val('a') }); 916 } 917 } 918 if (settings.window.expandable) 919 $($this).after('<span class="jPicker"><span class="Icon"><span class="Color"> </span><span class="Alpha"> </span><span class="Image" title="Click To Open Color Picker"> </span><span class="Container"> </span></span></span>'); 920 else settings.window.liveUpdate = false; // Basic control binding for inline use - You will need to override the liveCallback or commitCallback function to retrieve results 921 var isLessThanIE7 = parseFloat(navigator.appVersion.split('MSIE')[1]) < 7 && document.body.filters, // needed to run the AlphaImageLoader function for IE6 922 container = null, 923 colorMapDiv = null, 924 colorBarDiv = null, 925 colorMapL1 = null, // different layers of colorMap and colorBar 926 colorMapL2 = null, 927 colorMapL3 = null, 928 colorBarL1 = null, 929 colorBarL2 = null, 930 colorBarL3 = null, 931 colorBarL4 = null, 932 colorBarL5 = null, 933 colorBarL6 = null, 934 colorMap = null, // color maps 935 colorBar = null, 936 colorPicker = null, 937 elementStartX = null, // Used to record the starting css positions for dragging the control 938 elementStartY = null, 939 pageStartX = null, // Used to record the mousedown coordinates for dragging the control 940 pageStartY = null, 941 activePreview = null, // color boxes above the radio buttons 942 currentPreview = null, 943 okButton = null, 944 cancelButton = null, 945 grid = null, // preset colors grid 946 iconColor = null, // iconColor for popup icon 947 iconAlpha = null, // iconAlpha for popup icon 948 iconImage = null, // iconImage popup icon 949 moveBar = null, // drag bar 950 setColorMode = // set color mode and update visuals for the new color mode 951 function (colorMode) { 952 var active = color.active, // local copies for YUI compressor 953 clientPath = images.clientPath, 954 hex = active.val('hex'), 955 rgbMap, 956 rgbBar; 957 settings.color.mode = colorMode; 958 switch (colorMode) { 959 case 'h': 960 setTimeout( 961 function () { 962 setBG.call($this, colorMapDiv, 'transparent'); 963 setImgLoc.call($this, colorMapL1, 0); 964 setAlpha.call($this, colorMapL1, 100); 965 setImgLoc.call($this, colorMapL2, 260); 966 setAlpha.call($this, colorMapL2, 100); 967 setBG.call($this, colorBarDiv, 'transparent'); 968 setImgLoc.call($this, colorBarL1, 0); 969 setAlpha.call($this, colorBarL1, 100); 970 setImgLoc.call($this, colorBarL2, 260); 971 setAlpha.call($this, colorBarL2, 100); 972 setImgLoc.call($this, colorBarL3, 260); 973 setAlpha.call($this, colorBarL3, 100); 974 setImgLoc.call($this, colorBarL4, 260); 975 setAlpha.call($this, colorBarL4, 100); 976 setImgLoc.call($this, colorBarL6, 260); 977 setAlpha.call($this, colorBarL6, 100); 978 }, 0); 979 colorMap.range('all', { minX: 0, maxX: 100, minY: 0, maxY: 100 }); 980 colorBar.range('rangeY', { minY: 0, maxY: 360 }); 981 if (active.val('ahex') == null) break; 982 colorMap.val('xy', { x: active.val('s'), y: 100 - active.val('v') }, colorMap); 983 colorBar.val('y', 360 - active.val('h'), colorBar); 984 break; 985 case 's': 986 setTimeout( 987 function () { 988 setBG.call($this, colorMapDiv, 'transparent'); 989 setImgLoc.call($this, colorMapL1, -260); 990 setImgLoc.call($this, colorMapL2, -520); 991 setImgLoc.call($this, colorBarL1, -260); 992 setImgLoc.call($this, colorBarL2, -520); 993 setImgLoc.call($this, colorBarL6, 260);
994 setAlpha.call($this, colorBarL6, 100); 995 }, 0); 996 colorMap.range('all', { minX: 0, maxX: 360, minY: 0, maxY: 100 }); 997 colorBar.range('rangeY', { minY: 0, maxY: 100 }); 998 if (active.val('ahex') == null) break; 999 colorMap.val('xy', { x: active.val('h'), y: 100 - active.val('v') }, colorMap); 1000 colorBar.val('y', 100 - active.val('s'), colorBar); 1001 break; 1002 case 'v': 1003 setTimeout( 1004 function () { 1005 setBG.call($this, colorMapDiv, '000000'); 1006 setImgLoc.call($this, colorMapL1, -780); 1007 setImgLoc.call($this, colorMapL2, 260); 1008 setBG.call($this, colorBarDiv, hex); 1009 setImgLoc.call($this, colorBarL1, -520); 1010 setImgLoc.call($this, colorBarL2, 260); 1011 setAlpha.call($this, colorBarL2, 100); 1012 setImgLoc.call($this, colorBarL6, 260); 1013 setAlpha.call($this, colorBarL6, 100); 1014 }, 0); 1015 colorMap.range('all', { minX: 0, maxX: 360, minY: 0, maxY: 100 }); 1016 colorBar.range('rangeY', { minY: 0, maxY: 100 }); 1017 if (active.val('ahex') == null) break; 1018 colorMap.val('xy', { x: active.val('h'), y: 100 - active.val('s') }, colorMap); 1019 colorBar.val('y', 100 - active.val('v'), colorBar); 1020 break; 1021 case 'r': 1022 rgbMap = -1040; 1023 rgbBar = -780; 1024 colorMap.range('all', { minX: 0, maxX: 255, minY: 0, maxY: 255 }); 1025 colorBar.range('rangeY', { minY: 0, maxY: 255 }); 1026 if (active.val('ahex') == null) break; 1027 colorMap.val('xy', { x: active.val('b'), y: 255 - active.val('g') }, colorMap); 1028 colorBar.val('y', 255 - active.val('r'), colorBar); 1029 break; 1030 case 'g': 1031 rgbMap = -1560; 1032 rgbBar = -1820; 1033 colorMap.range('all', { minX: 0, maxX: 255, minY: 0, maxY: 255 }); 1034 colorBar.range('rangeY', { minY: 0, maxY: 255 }); 1035 if (active.val('ahex') == null) break; 1036 colorMap.val('xy', { x: active.val('b'), y: 255 - active.val('r') }, colorMap); 1037 colorBar.val('y', 255 - active.val('g'), colorBar); 1038 break; 1039 case 'b': 1040 rgbMap = -2080; 1041 rgbBar = -2860; 1042 colorMap.range('all', { minX: 0, maxX: 255, minY: 0, maxY: 255 }); 1043 colorBar.range('rangeY', { minY: 0, maxY: 255 }); 1044 if (active.val('ahex') == null) break; 1045 colorMap.val('xy', { x: active.val('r'), y: 255 - active.val('g') }, colorMap); 1046 colorBar.val('y', 255 - active.val('b'), colorBar); 1047 break; 1048 case 'a': 1049 setTimeout( 1050 function () { 1051 setBG.call($this, colorMapDiv, 'transparent'); 1052 setImgLoc.call($this, colorMapL1, -260); 1053 setImgLoc.call($this, colorMapL2, -520); 1054 setImgLoc.call($this, colorBarL1, 260); 1055 setImgLoc.call($this, colorBarL2, 260); 1056 setAlpha.call($this, colorBarL2, 100); 1057 setImgLoc.call($this, colorBarL6, 0); 1058 setAlpha.call($this, colorBarL6, 100); 1059 }, 0); 1060 colorMap.range('all', { minX: 0, maxX: 360, minY: 0, maxY: 100 }); 1061 colorBar.range('rangeY', { minY: 0, maxY: 255 }); 1062 if (active.val('ahex') == null) break; 1063 colorMap.val('xy', { x: active.val('h'), y: 100 - active.val('v') }, colorMap); 1064 colorBar.val('y', 255 - active.val('a'), colorBar); 1065 break; 1066 default: 1067 throw ('Invalid Mode'); 1068 break; 1069 } 1070 switch (colorMode) { 1071 case 'h': 1072 break; 1073 case 's': 1074 case 'v': 1075 case 'a': 1076 setTimeout( 1077 function () { 1078 setAlpha.call($this, colorMapL1, 100); 1079 setAlpha.call($this, colorBarL1, 100); 1080 setImgLoc.call($this, colorBarL3, 260); 1081 setAlpha.call($this, colorBarL3, 100); 1082 setImgLoc.call($this, colorBarL4, 260); 1083 setAlpha.call($this, colorBarL4, 100); 1084 }, 0); 1085 break; 1086 case 'r': 1087 case 'g': 1088 case 'b': 1089 setTimeout( 1090 function () { 1091 setBG.call($this, colorMapDiv, 'transparent'); 1092 setBG.call($this, colorBarDiv, 'transparent'); 1093 setAlpha.call($this, colorBarL1, 100); 1094 setAlpha.call($this, colorMapL1, 100); 1095 setImgLoc.call($this, colorMapL1, rgbMap); 1096 setImgLoc.call($this, colorMapL2, rgbMap - 260); 1097 setImgLoc.call($this, colorBarL1, rgbBar - 780); 1098 setImgLoc.call($this, colorBarL2, rgbBar - 520); 1099 setImgLoc.call($this, colorBarL3, rgbBar); 1100 setImgLoc.call($this, colorBarL4, rgbBar - 260); 1101 setImgLoc.call($this, colorBarL6, 260);
1102 setAlpha.call($this, colorBarL6, 100); 1103 }, 0); 1104 break; 1105 } 1106 if (active.val('ahex') == null) return; 1107 activeColorChanged.call($this, active); 1108 }, 1109 activeColorChanged = // Update color when user changes text values 1110 function (ui, context) { 1111 if (context == null || (context != colorBar && context != colorMap)) positionMapAndBarArrows.call($this, ui, context); 1112 setTimeout( 1113 function () { 1114 updatePreview.call($this, ui); 1115 updateMapVisuals.call($this, ui); 1116 updateBarVisuals.call($this, ui); 1117 }, 0); 1118 }, 1119 mapValueChanged = // user has dragged the ColorMap pointer 1120 function (ui, context) { 1121 var active = color.active; 1122 if (context != colorMap && active.val() == null) return; 1123 var xy = ui.val('all'); 1124 switch (settings.color.mode) { 1125 case 'h': 1126 active.val('sv', { s: xy.x, v: 100 - xy.y }, context); 1127 break; 1128 case 's': 1129 case 'a': 1130 active.val('hv', { h: xy.x, v: 100 - xy.y }, context); 1131 break; 1132 case 'v': 1133 active.val('hs', { h: xy.x, s: 100 - xy.y }, context); 1134 break; 1135 case 'r': 1136 active.val('gb', { g: 255 - xy.y, b: xy.x }, context); 1137 break; 1138 case 'g': 1139 active.val('rb', { r: 255 - xy.y, b: xy.x }, context); 1140 break; 1141 case 'b': 1142 active.val('rg', { r: xy.x, g: 255 - xy.y }, context); 1143 break; 1144 } 1145 }, 1146 colorBarValueChanged = // user has dragged the ColorBar slider 1147 function (ui, context) { 1148 var active = color.active; 1149 if (context != colorBar && active.val() == null) return; 1150 switch (settings.color.mode) { 1151 case 'h': 1152 active.val('h', { h: 360 - ui.val('y') }, context); 1153 break; 1154 case 's': 1155 active.val('s', { s: 100 - ui.val('y') }, context); 1156 break; 1157 case 'v': 1158 active.val('v', { v: 100 - ui.val('y') }, context); 1159 break; 1160 case 'r': 1161 active.val('r', { r: 255 - ui.val('y') }, context); 1162 break; 1163 case 'g': 1164 active.val('g', { g: 255 - ui.val('y') }, context); 1165 break; 1166 case 'b': 1167 active.val('b', { b: 255 - ui.val('y') }, context); 1168 break; 1169 case 'a': 1170 active.val('a', 255 - ui.val('y'), context); 1171 break; 1172 } 1173 }, 1174 positionMapAndBarArrows = // position map and bar arrows to match current color 1175 function (ui, context) { 1176 if (context != colorMap) { 1177 switch (settings.color.mode) { 1178 case 'h': 1179 var sv = ui.val('sv'); 1180 colorMap.val('xy', { x: sv != null ? sv.s : 100, y: 100 - (sv != null ? sv.v : 100) }, context); 1181 break; 1182 case 's': 1183 case 'a': 1184 var hv = ui.val('hv'); 1185 colorMap.val('xy', { x: hv && hv.h || 0, y: 100 - (hv != null ? hv.v : 100) }, context); 1186 break; 1187 case 'v': 1188 var hs = ui.val('hs'); 1189 colorMap.val('xy', { x: hs && hs.h || 0, y: 100 - (hs != null ? hs.s : 100) }, context); 1190 break; 1191 case 'r': 1192 var bg = ui.val('bg'); 1193 colorMap.val('xy', { x: bg && bg.b || 0, y: 255 - (bg && bg.g || 0) }, context); 1194 break; 1195 case 'g': 1196 var br = ui.val('br'); 1197 colorMap.val('xy', { x: br && br.b || 0, y: 255 - (br && br.r || 0) }, context); 1198 break; 1199 case 'b': 1200 var rg = ui.val('rg'); 1201 colorMap.val('xy', { x: rg && rg.r || 0, y: 255 - (rg && rg.g || 0) }, context); 1202 break; 1203 } 1204 } 1205 if (context != colorBar) { 1206 switch (settings.color.mode) { 1207 case 'h': 1208 colorBar.val('y', 360 - (ui.val('h') || 0), context); 1209 break; 1210 case 's': 1211 var s = ui.val('s'); 1212 colorBar.val('y', 100 - (s != null ? s : 100), context); 1213 break; 1214 case 'v': 1215 var v = ui.val('v'); 1216 colorBar.val('y', 100 - (v != null ? v : 100), context); 1217 break; 1218 case 'r': 1219 colorBar.val('y', 255 - (ui.val('r') || 0), context); 1220 break; 1221 case 'g': 1222 colorBar.val('y', 255 - (ui.val('g') || 0), context); 1223 break; 1224 case 'b': 1225 colorBar.val('y', 255 - (ui.val('b') || 0), context); 1226 break; 1227 case 'a': 1228 var a = ui.val('a'); 1229 colorBar.val('y', 255 - (a != null ? a : 255), context); 1230 break; 1231 } 1232 } 1233 }, 1234 updatePreview = 1235 function (ui) { 1236 try { 1237 var all = ui.val('all'); 1238 activePreview.css({ backgroundColor: all && '#' + all.hex || 'transparent' }); 1239 setAlpha.call($this, activePreview, all && Math.precision((all.a * 100) / 255, 4) || 0); 1240 } 1241 catch (e) { } 1242 }, 1243 updateMapVisuals = 1244 function (ui) { 1245 switch (settings.color.mode) { 1246 case 'h': 1247 setBG.call($this, colorMapDiv, new Color({ h: ui.val('h') || 0, s: 100, v: 100 }).val('hex')); 1248 break; 1249 case 's': 1250 case 'a': 1251 var s = ui.val('s'); 1252 setAlpha.call($this, colorMapL2, 100 - (s != null ? s : 100)); 1253 break; 1254 case 'v': 1255 var v = ui.val('v'); 1256 setAlpha.call($this, colorMapL1, v != null ? v : 100); 1257 break; 1258 case 'r': 1259 setAlpha.call($this, colorMapL2, Math.precision((ui.val('r') || 0) / 255 * 100, 4)); 1260 break; 1261 case 'g': 1262 setAlpha.call($this, colorMapL2, Math.precision((ui.val('g') || 0) / 255 * 100, 4)); 1263 break; 1264 case 'b': 1265 setAlpha.call($this, colorMapL2, Math.precision((ui.val('b') || 0) / 255 * 100)); 1266 break; 1267 } 1268 var a = ui.val('a'); 1269 setAlpha.call($this, colorMapL3, Math.precision(((255 - (a || 0)) * 100) / 255, 4)); 1270 }, 1271 updateBarVisuals = 1272 function (ui) { 1273 switch (settings.color.mode) { 1274 case 'h': 1275 var a = ui.val('a'); 1276 setAlpha.call($this, colorBarL5, Math.precision(((255 - (a || 0)) * 100) / 255, 4)); 1277 break; 1278 case 's': 1279 var hva = ui.val('hva'), 1280 saturatedColor = new Color({ h: hva && hva.h || 0, s: 100, v: hva != null ? hva.v : 100 }); 1281 setBG.call($this, colorBarDiv, saturatedColor.val('hex')); 1282 setAlpha.call($this, colorBarL2, 100 - (hva != null ? hva.v : 100)); 1283 setAlpha.call($this, colorBarL5, Math.precision(((255 - (hva && hva.a || 0)) * 100) / 255, 4)); 1284 break; 1285 case 'v': 1286 var hsa = ui.val('hsa'), 1287 valueColor = new Color({ h: hsa && hsa.h || 0, s: hsa != null ? hsa.s : 100, v: 100 }); 1288 setBG.call($this, colorBarDiv, valueColor.val('hex')); 1289 setAlpha.call($this, colorBarL5, Math.precision(((255 - (hsa && hsa.a || 0)) * 100) / 255, 4)); 1290 break; 1291 case 'r': 1292 case 'g': 1293 case 'b': 1294 var hValue = 0, vValue = 0, rgba = ui.val('rgba'); 1295 if (settings.color.mode == 'r') { 1296 hValue = rgba && rgba.b || 0; 1297 vValue = rgba && rgba.g || 0; 1298 } 1299 else if (settings.color.mode == 'g') { 1300 hValue = rgba && rgba.b || 0; 1301 vValue = rgba && rgba.r || 0; 1302 } 1303 else if (settings.color.mode == 'b') { 1304 hValue = rgba && rgba.r || 0; 1305 vValue = rgba && rgba.g || 0; 1306 } 1307 var middle = vValue > hValue ? hValue : vValue; 1308 setAlpha.call($this, colorBarL2, hValue > vValue ? Math.precision(((hValue - vValue) / (255 - vValue)) * 100, 4) : 0); 1309 setAlpha.call($this, colorBarL3, vValue > hValue ? Math.precision(((vValue - hValue) / (255 - hValue)) * 100, 4) : 0); 1310 setAlpha.call($this, colorBarL4, Math.precision((middle / 255) * 100, 4)); 1311 setAlpha.call($this, colorBarL5, Math.precision(((255 - (rgba && rgba.a || 0)) * 100) / 255, 4)); 1312 break; 1313 case 'a': 1314 var a = ui.val('a'); 1315 setBG.call($this, colorBarDiv, ui.val('hex') || '000000'); 1316 setAlpha.call($this, colorBarL5, a != null ? 0 : 100); 1317 setAlpha.call($this, colorBarL6, a != null ? 100 : 0); 1318 break; 1319 } 1320 }, 1321 setBG = 1322 function (el, c) { 1323 el.css({ backgroundColor: c && c.length == 6 && '#' + c || 'transparent' }); 1324 }, 1325 setImg = 1326 function (img, src) { 1327 if (isLessThanIE7 && (src.indexOf('AlphaBar.png') != -1 || src.indexOf('Bars.png') != -1 || src.indexOf('Maps.png') != -1)) { 1328 img.attr('pngSrc', src); 1329 img.css({ backgroundImage: 'none', filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src + '\', sizingMethod=\'scale\')' });
1330 } 1331 else img.css({ backgroundImage: 'url(\'' + src + '\')' }); 1332 }, 1333 setImgLoc = 1334 function (img, y) { 1335 img.css({ top: y + 'px' }); 1336 }, 1337 setAlpha = 1338 function (obj, alpha) { 1339 obj.css({ visibility: alpha > 0 ? 'visible' : 'hidden' }); 1340 if (alpha > 0 && alpha < 100) { 1341 if (isLessThanIE7) { 1342 var src = obj.attr('pngSrc'); 1343 if (src != null && (src.indexOf('AlphaBar.png') != -1 || src.indexOf('Bars.png') != -1 || src.indexOf('Maps.png') != -1)) 1344 obj.css({ filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src + '\', sizingMethod=\'scale\') progid:DXImageTransform.Microsoft.Alpha(opacity=' + alpha + ')' }); 1345 else obj.css({ opacity: Math.precision(alpha / 100, 4) }); 1346 } 1347 else obj.css({ opacity: Math.precision(alpha / 100, 4) }); 1348 } 1349 else if (alpha == 0 || alpha == 100) { 1350 if (isLessThanIE7) { 1351 var src = obj.attr('pngSrc'); 1352 if (src != null && (src.indexOf('AlphaBar.png') != -1 || src.indexOf('Bars.png') != -1 || src.indexOf('Maps.png') != -1)) 1353 obj.css({ filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src + '\', sizingMethod=\'scale\')' }); 1354 else obj.css({ opacity: '' }); 1355 } 1356 else obj.css({ opacity: '' }); 1357 } 1358 }, 1359 revertColor = // revert color to original color when opened 1360 function () { 1361 color.active.val('ahex', color.current.val('ahex')); 1362 }, 1363 commitColor = // commit the color changes 1364 function () { 1365 color.current.val('ahex', color.active.val('ahex')); 1366 }, 1367 radioClicked = 1368 function (e) { 1369 $(this).parents('tbody:first').find('input:radio[value!="' + e.target.value + '"]').removeAttr('checked'); 1370 setColorMode.call($this, e.target.value); 1371 }, 1372 currentClicked = 1373 function () { 1374 revertColor.call($this); 1375 }, 1376 cancelClicked = 1377 function () { 1378 revertColor.call($this); 1379 settings.window.expandable && hide.call($this); 1380 $.isFunction(cancelCallback) && cancelCallback.call($this, color.active, cancelButton); 1381 }, 1382 okClicked = 1383 function () { 1384 commitColor.call($this); 1385 settings.window.expandable && hide.call($this); 1386 $.isFunction(commitCallback) && commitCallback.call($this, color.active, okButton); 1387 }, 1388 iconImageClicked = 1389 function () { 1390 show.call($this); 1391 }, 1392 currentColorChanged = 1393 function (ui, context) { 1394 var hex = ui.val('hex'); 1395 currentPreview.css({ backgroundColor: hex && '#' + hex || 'transparent' }); 1396 setAlpha.call($this, currentPreview, Math.precision(((ui.val('a') || 0) * 100) / 255, 4)); 1397 }, 1398 expandableColorChanged = 1399 function (ui, context) { 1400 var hex = ui.val('hex'); 1401 var va = ui.val('va'); 1402 iconColor.css({ backgroundColor: hex && '#' + hex || 'transparent' }); 1403 setAlpha.call($this, iconAlpha, Math.precision(((255 - (va && va.a || 0)) * 100) / 255, 4)); 1404 if (settings.window.bindToInput && settings.window.updateInputColor) 1405 settings.window.input.css( 1406 { 1407 backgroundColor: hex && '#' + hex || 'transparent', 1408 color: va == null || va.v > 75 ? '#000000' : '#ffffff' 1409 }); 1410 }, 1411 moveBarMouseDown = 1412 function (e) { 1413 var element = settings.window.element, // local copies for YUI compressor 1414 page = settings.window.page; 1415 elementStartX = parseInt(container.css('left')); 1416 elementStartY = parseInt(container.css('top')); 1417 pageStartX = e.pageX; 1418 pageStartY = e.pageY; 1419 // bind events to document to move window - we will unbind these on mouseup 1420 $(document).bind('mousemove', documentMouseMove).bind('mouseup', documentMouseUp); 1421 e.preventDefault(); // prevent attempted dragging of the column 1422 }, 1423 documentMouseMove = 1424 function (e) { 1425 container.css({ left: elementStartX - (pageStartX - e.pageX) + 'px', top: elementStartY - (pageStartY - e.pageY) + 'px' });
1426 if (settings.window.expandable && !$.support.boxModel) container.prev().css({ left: container.css("left"), top: container.css("top") }); 1427 e.stopPropagation(); 1428 e.preventDefault(); 1429 return false; 1430 }, 1431 documentMouseUp = 1432 function (e) { 1433 $(document).unbind('mousemove', documentMouseMove).unbind('mouseup', documentMouseUp); 1434 e.stopPropagation(); 1435 e.preventDefault(); 1436 return false; 1437 }, 1438 quickPickClicked = 1439 function (e) { 1440 e.preventDefault(); 1441 e.stopPropagation(); 1442 color.active.val('ahex', $(this).attr('title') || null, e.target); 1443 return false; 1444 }, 1445 commitCallback = $.isFunction($arguments[1]) && $arguments[1] || null, 1446 liveCallback = $.isFunction($arguments[2]) && $arguments[2] || null, 1447 cancelCallback = $.isFunction($arguments[3]) && $arguments[3] || null, 1448 show = 1449 function () { 1450 color.current.val('ahex', color.active.val('ahex')); 1451 var attachIFrame = function () { 1452 if (!settings.window.expandable || $.support.boxModel) return; 1453 var table = container.find('table:first'); 1454 container.before('<iframe/>'); 1455 container.prev().css({ width: table.width(), height: container.height(), opacity: 0, position: 'absolute', left: container.css("left"), top: container.css("top") }); 1456 }; 1457 if (settings.window.expandable) { 1458 $(document.body).children('div.jPicker.Container').css({ zIndex: 10 }); 1459 container.css({ zIndex: zIndexNewValue }); 1460 } 1461 switch (settings.window.effects.type) { 1462 case 'fade': 1463 container.fadeIn(settings.window.effects.speed.show, attachIFrame); 1464 break; 1465 case 'slide': 1466 container.slideDown(settings.window.effects.speed.show, attachIFrame); 1467 break; 1468 case 'show': 1469 default: 1470 container.show(settings.window.effects.speed.show, attachIFrame); 1471 break; 1472 } 1473 }, 1474 hide = 1475 function () { 1476 var removeIFrame = function () { 1477 if (settings.window.expandable) container.css({ zIndex: 10 }); 1478 if (!settings.window.expandable || $.support.boxModel) return; 1479 container.prev().remove(); 1480 }; 1481 switch (settings.window.effects.type) { 1482 case 'fade': 1483 container.fadeOut(settings.window.effects.speed.hide, removeIFrame); 1484 break; 1485 case 'slide': 1486 container.slideUp(settings.window.effects.speed.hide, removeIFrame); 1487 break; 1488 case 'show': 1489 default: 1490 container.hide(settings.window.effects.speed.hide, removeIFrame); 1491 break; 1492 } 1493 }, 1494 initialize = 1495 function () { 1496 var win = settings.window, 1497 popup = win.expandable ? $($this).next().find('.Container:first') : null; 1498 container = win.expandable ? $('<div/>') : $($this); 1499 container.addClass('jPicker Container'); 1500 if (win.expandable) container.hide(); 1501 container.get(0).onselectstart = function (event) { if (event.target.nodeName.toLowerCase() !== 'input') return false; }; 1502 // inject html source code - we are using a single table for this control - I know tables are considered bad, but it takes care of equal height columns and 1503 // this control really is tabular data, so I believe it is the right move 1504 var all = color.active.val('all'); 1505 if (win.alphaPrecision < 0) win.alphaPrecision = 0; 1506 else if (win.alphaPrecision > 2) win.alphaPrecision = 2; 1507 var controlHtml = '<table class="jPicker" cellpadding="0" cellspacing="0"><tbody>' + (win.expandable ? '<tr><td class="Move" colspan="5"> </td></tr>' : '') + '<tr><td rowspan="9"><h2 class="Title">' + (win.title || localization.text.title) + '</h2><div class="Map"><span class="Map1"> </span><span class="Map2"> </span><span class="Map3"> </span><img src="' + images.clientPath + images.colorMap.arrow.file + '" class="Arrow"/></div></td><td rowspan="9"><div class="Bar"><span class="Map1"> </span><span class="Map2"> </span><span class="Map3"> </span><span class="Map4"> </span><span class="Map5"> </span><span class="Map6"> </span><img src="' + images.clientPath + images.colorBar.arrow.file + '" class="Arrow"/></div></td><td colspan="2" class="Preview">' + localization.text.newColor + '<div><span class="Active" title="' + localization.tooltips.colors.newColor + '"> </span><span class="Current" title="' + localization.tooltips.colors.currentColor + '"> </span></div>' + localization.text.currentColor + '</td><td rowspan="9" class="Button"><input type="button" class="Ok" value="' + localization.text.ok + '" title="' + localization.tooltips.buttons.ok + '"/><input type="button" class="Cancel" value="' + localization.text.cancel + '" title="' + localization.tooltips.buttons.cancel + '"/><hr/><div class="Grid"> </div></td></tr><tr class="Hue"><td class="Radio"><label title="' + localization.tooltips.hue.radio + '"><input type="radio" value="h"' + (settings.color.mode == 'h' ? ' checked="checked"' : '') + '/>H:</label></td><td class="Text"><input type="text" maxlength="3" value="' + (all != null ? all.h : '') + '" title="' + localization.tooltips.hue.textbox + '"/> °</td></tr><tr class="Saturation"><td class="Radio"><label title="' + localization.tooltips.saturation.radio + '"><input type="radio" value="s"' + (settings.color.mode == 's' ? ' checked="checked"' : '') + '/>S:</label></td><td class="Text"><input type="text" maxlength="3" value="' + (all != null ? all.s : '') + '" title="' + localization.tooltips.saturation.textbox + '"/> %</td></tr><tr class="Value"><td class="Radio"><label title="' + localization.tooltips.value.radio + '"><input type="radio" value="v"' + (settings.color.mode == 'v' ? ' checked="checked"' : '') + '/>V:</label><br/><br/></td><td class="Text"><input type="text" maxlength="3" value="' + (all != null ? all.v : '') + '" title="' + localization.tooltips.value.textbox + '"/> %<br/><br/></td></tr><tr class="Red"><td class="Radio"><label title="' + localization.tooltips.red.radio + '"><input type="radio" value="r"' + (settings.color.mode == 'r' ? ' checked="checked"' : '') + '/>R:</label></td><td class="Text"><input type="text" maxlength="3" value="' + (all != null ? all.r : '') + '" title="' + localization.tooltips.red.textbox + '"/></td></tr><tr class="Green"><td class="Radio"><label title="' + localization.tooltips.green.radio + '"><input type="radio" value="g"' + (settings.color.mode == 'g' ? ' checked="checked"' : '') + '/>G:</label></td><td class="Text"><input type="text" maxlength="3" value="' + (all != null ? all.g : '') + '" title="' + localization.tooltips.green.textbox + '"/></td></tr><tr class="Blue"><td class="Radio"><label title="' + localization.tooltips.blue.radio + '"><input type="radio" value="b"' + (settings.color.mode == 'b' ? ' checked="checked"' : '') + '/>B:</label></td><td class="Text"><input type="text" maxlength="3" value="' + (all != null ? all.b : '') + '" title="' + localization.tooltips.blue.textbox + '"/></td></tr><tr class="Alpha"><td class="Radio">' + (win.alphaSupport ? '<label title="' + localization.tooltips.alpha.radio + '"><input type="radio" value="a"' + (settings.color.mode == 'a' ? ' checked="checked"' : '') + '/>A:</label>' : ' ') + '</td><td class="Text">' + (win.alphaSupport ? '<input type="text" maxlength="' + (3 + win.alphaPrecision) + '" value="' + (all != null ? Math.precision((all.a * 100) / 255, win.alphaPrecision) : '') + '" title="' + localization.tooltips.alpha.textbox + '"/> %' : ' ') + '</td></tr><tr class="Hex"><td colspan="2" class="Text"><label title="' + localization.tooltips.hex.textbox + '">#:<input type="text" maxlength="6" class="Hex" value="' + (all != null ? all.hex : '') + '"/></label>' + (win.alphaSupport ? '<input type="text" maxlength="2" class="AHex" value="' + (all != null ? all.ahex.substring(6) : '') + '" title="' + localization.tooltips.hex.alpha + '"/></td>' : ' ') + '</tr></tbody></table>'; 1508 if (win.expandable) { 1509 container.html(controlHtml); 1510 if ($(document.body).children('div.jPicker.Container').length == 0) $(document.body).prepend(container); 1511 else $(document.body).children('div.jPicker.Container:last').after(container); 1512 container.mousedown( 1513 function () { 1514 $(document.body).children('div.jPicker.Container').css({ zIndex: 10 }); 1515 container.css({ zIndex: zIndexNewValue });
1516 }); 1517 container.css( // positions must be set and display set to absolute before source code injection or IE will size the container to fit the window 1518 { 1519 left: 1520 win.position.x == 'left' ? (popup.offset().left - 530 - (win.position.y == 'center' ? 25 : 0)) + 'px' : 1521 win.position.x == 'center' ? (popup.offset().left - 260) + 'px' : 1522 win.position.x == 'right' ? (popup.offset().left - 10 + (win.position.y == 'center' ? 25 : 0)) + 'px' : 1523 win.position.x == 'screenCenter' ? (($(document).width() >> 1) - 260) + 'px' : (popup.offset().left + parseInt(win.position.x)) + 'px', 1524 position: 'absolute', 1525 top: win.position.y == 'top' ? (popup.offset().top - 312) + 'px' : 1526 win.position.y == 'center' ? (popup.offset().top - 156) + 'px' : 1527 win.position.y == 'bottom' ? (popup.offset().top + 25) + 'px' : (popup.offset().top + parseInt(win.position.y)) + 'px' 1528 }); 1529 } 1530 else { 1531 container = $($this); 1532 container.html(controlHtml); 1533 } 1534 // initialize the objects to the source code just injected 1535 var tbody = container.find('tbody:first'); 1536 colorMapDiv = tbody.find('div.Map:first'); 1537 colorBarDiv = tbody.find('div.Bar:first'); 1538 var MapMaps = colorMapDiv.find('span'), 1539 BarMaps = colorBarDiv.find('span'); 1540 colorMapL1 = MapMaps.filter('.Map1:first'); 1541 colorMapL2 = MapMaps.filter('.Map2:first'); 1542 colorMapL3 = MapMaps.filter('.Map3:first'); 1543 colorBarL1 = BarMaps.filter('.Map1:first'); 1544 colorBarL2 = BarMaps.filter('.Map2:first'); 1545 colorBarL3 = BarMaps.filter('.Map3:first'); 1546 colorBarL4 = BarMaps.filter('.Map4:first'); 1547 colorBarL5 = BarMaps.filter('.Map5:first'); 1548 colorBarL6 = BarMaps.filter('.Map6:first'); 1549 // create color pickers and maps 1550 colorMap = new Slider(colorMapDiv, 1551 { 1552 map: 1553 { 1554 width: images.colorMap.width, 1555 height: images.colorMap.height 1556 }, 1557 arrow: 1558 { 1559 image: images.clientPath + images.colorMap.arrow.file, 1560 width: images.colorMap.arrow.width, 1561 height: images.colorMap.arrow.height 1562 } 1563 }); 1564 colorMap.bind(mapValueChanged); 1565 colorBar = new Slider(colorBarDiv, 1566 { 1567 map: 1568 { 1569 width: images.colorBar.width, 1570 height: images.colorBar.height 1571 }, 1572 arrow: 1573 { 1574 image: images.clientPath + images.colorBar.arrow.file, 1575 width: images.colorBar.arrow.width, 1576 height: images.colorBar.arrow.height 1577 } 1578 }); 1579 colorBar.bind(colorBarValueChanged); 1580 colorPicker = new ColorValuePicker(tbody, color.active, win.expandable && win.bindToInput ? win.input : null, win.alphaPrecision); 1581 var hex = all != null ? all.hex : null, 1582 preview = tbody.find('.Preview'), 1583 button = tbody.find('.Button'); 1584 activePreview = preview.find('.Active:first').css({ backgroundColor: hex && '#' + hex || 'transparent' }); 1585 currentPreview = preview.find('.Current:first').css({ backgroundColor: hex && '#' + hex || 'transparent' }).bind('click', currentClicked); 1586 setAlpha.call($this, currentPreview, Math.precision(color.current.val('a') * 100) / 255, 4); 1587 okButton = button.find('.Ok:first').bind('click', okClicked); 1588 cancelButton = button.find('.Cancel:first').bind('click', cancelClicked); 1589 grid = button.find('.Grid:first'); 1590 setTimeout( 1591 function () { 1592 setImg.call($this, colorMapL1, images.clientPath + 'Maps.png'); 1593 setImg.call($this, colorMapL2, images.clientPath + 'Maps.png'); 1594 setImg.call($this, colorMapL3, images.clientPath + 'map-opacity.png'); 1595 setImg.call($this, colorBarL1, images.clientPath + 'Bars.png'); 1596 setImg.call($this, colorBarL2, images.clientPath + 'Bars.png'); 1597 setImg.call($this, colorBarL3, images.clientPath + 'Bars.png'); 1598 setImg.call($this, colorBarL4, images.clientPath + 'Bars.png'); 1599 setImg.call($this, colorBarL5, images.clientPath + 'bar-opacity.png'); 1600 setImg.call($this, colorBarL6, images.clientPath + 'AlphaBar.png'); 1601 setImg.call($this, preview.find('div:first'), images.clientPath + 'preview-opacity.png'); 1602 }, 0); 1603 tbody.find('td.Radio input').bind('click', radioClicked); 1604 // initialize quick list 1605 if (color.quickList && color.quickList.length > 0) { 1606 var html = ''; 1607 for (i = 0; i < color.quickList.length; i++) { 1608 /* if default colors are hex strings, change them to color objects */ 1609 if ((typeof (color.quickList[i])).toString().toLowerCase() == 'string') color.quickList[i] = new Color({ hex: color.quickList[i] }); 1610 var alpha = color.quickList[i].val('a'); 1611 var ahex = color.quickList[i].val('ahex'); 1612 if (!win.alphaSupport && ahex) ahex = ahex.substring(0, 6) + 'ff'; 1613 var quickHex = color.quickList[i].val('hex'); 1614 html += '<span class="QuickColor"' + (ahex && ' title="#' + ahex + '"' || '') + ' style="background-color:' + (quickHex && '#' + quickHex || '') + ';' + (quickHex ? '' : 'background-image:url(' + images.clientPath + 'N
1614oColor.png)') + (win.alphaSupport && alpha && alpha < 255 ? ';opacity:' + Math.precision(alpha / 255, 4) + ';filter:Alpha(opacity=' + Math.precision(alpha / 2.55, 4) + ')' : '') + '"> </span>'; 1615 } 1616 setImg.call($this, grid, images.clientPath + 'bar-opacity.png'); 1617 grid.html(html); 1618 grid.find('.QuickColor').click(quickPickClicked); 1619 } 1620 setColorMode.call($this, settings.color.mode); 1621 color.active.bind(activeColorChanged); 1622 $.isFunction(liveCallback) && color.active.bind(liveCallback); 1623 color.current.bind(currentColorChanged); 1624 // bind to input 1625 if (win.expandable) { 1626 $this.icon = popup.parents('.Icon:first'); 1627 iconColor = $this.icon.find('.Color:first').css({ backgroundColor: hex && '#' + hex || 'transparent' }); 1628 iconAlpha = $this.icon.find('.Alpha:first'); 1629 setImg.call($this, iconAlpha, images.clientPath + 'bar-opacity.png'); 1630 setAlpha.call($this, iconAlpha, Math.precision(((255 - (all != null ? all.a : 0)) * 100) / 255, 4)); 1631 iconImage = $this.icon.find('.Image:first').css( 1632 { 1633 backgroundImage: 'url(\'' + images.clientPath + images.picker.file + '\')' 1634 }).bind('click', iconImageClicked); 1635 if (win.bindToInput && win.updateInputColor) 1636 win.input.css( 1637 { 1638 backgroundColor: hex && '#' + hex || 'transparent', 1639 color: all == null || all.v > 75 ? '#000000' : '#ffffff' 1640 }); 1641 moveBar = tbody.find('.Move:first').bind('mousedown', moveBarMouseDown); 1642 color.active.bind(expandableColorChanged); 1643 } 1644 else show.call($this); 1645 }, 1646 destroy = 1647 function () { 1648 container.find('td.Radio input').unbind('click', radioClicked); 1649 currentPreview.unbind('click', currentClicked); 1650 cancelButton.unbind('click', cancelClicked); 1651 okButton.unbind('click', okClicked); 1652 if (settings.window.expandable) { 1653 iconImage.unbind('click', iconImageClicked); 1654 moveBar.unbind('mousedown', moveBarMouseDown); 1655 $this.icon = null; 1656 } 1657 container.find('.QuickColor').unbind('click', quickPickClicked); 1658 colorMapDiv = null; 1659 colorBarDiv = null; 1660 colorMapL1 = null; 1661 colorMapL2 = null; 1662 colorMapL3 = null; 1663 colorBarL1 = null; 1664 colorBarL2 = null; 1665 colorBarL3 = null; 1666 colorBarL4 = null; 1667 colorBarL5 = null; 1668 colorBarL6 = null; 1669 colorMap.destroy(); 1670 colorMap = null; 1671 colorBar.destroy(); 1672 colorBar = null; 1673 colorPicker.destroy(); 1674 colorPicker = null; 1675 activePreview = null; 1676 currentPreview = null; 1677 okButton = null; 1678 cancelButton = null; 1679 grid = null; 1680 commitCallback = null; 1681 cancelCallback = null; 1682 liveCallback = null; 1683 container.html(''); 1684 for (i = 0; i < List.length; i++) if (List[i] == $this) List.splice(i, 1); 1685 }, 1686 images = settings.images, // local copies for YUI compressor 1687 localization = settings.localization, 1688 color = 1689 { 1690 active: (typeof (settings.color.active)).toString().toLowerCase() == 'string' ? new Color({ ahex: !settings.window.alphaSupport && settings.color.active ? settings.color.active.substring(0, 6) + 'ff' : settings.color.active }) : new Color({ ahex: !settings.window.alphaSupport && settings.color.active.val('ahex') ? settings.color.active.val('ahex').substring(0, 6) + 'ff' : settings.color.active.val('ahex') }),
1691 current: (typeof (settings.color.active)).toString().toLowerCase() == 'string' ? new Color({ ahex: !settings.window.alphaSupport && settings.color.active ? settings.color.active.substring(0, 6) + 'ff' : settings.color.active }) : new Color({ ahex: !settings.window.alphaSupport && settings.color.active.val('ahex') ? settings.color.active.val('ahex').substring(0, 6) + 'ff' : settings.color.active.val('ahex') }), 1692 quickList: settings.color.quickList 1693 }; 1694 $.extend(true, $this, // public properties, methods, and callbacks 1695 { 1696 commitCallback: commitCallback, // commitCallback function can be overridden to return the selected color to a method you specify when the user clicks "OK" 1697 liveCallback: liveCallback, // liveCallback function can be overridden to return the selected color to a method you specify in live mode (continuous update) 1698 cancelCallback: cancelCallback, // cancelCallback function can be overridden to a method you specify when the user clicks "Cancel" 1699 color: color, 1700 show: show, 1701 hide: hide, 1702 destroy: destroy // destroys this control entirely, removing all events and objects, and removing itself from the List 1703 }); 1704 List.push($this); 1705 setTimeout( 1706 function () { 1707 initialize.call($this); 1708 }, 0); 1709 }); 1710}; 1711$.fn.jPicker.defaults = /* jPicker defaults - you can change anything in this section (such as the clientPath to your images) without fear of breaking the program */ 1712 { 1713 window: 1714 { 1715 title: null, /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */ 1716 effects: 1717 { 1718 type: 'slide', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */ 1719 speed: 1720 { 1721 show: 'slow', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */ 1722 hide: 'fast' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */ 1723 } 1724 }, 1725 position: 1726 { 1727 x: 'screenCenter', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */ 1728 y: 'top' /* acceptable values "top", "bottom", "center", or relative px value */ 1729 }, 1730 expandable: false, /* default to large static picker - set to true to make an expandable picker (small icon with popup) - set automatically when binded to input element */ 1731 liveUpdate: true, /* set false if you want the user to have to click "OK" before the binded input box updates values (always "true" for expandable picker) */ 1732 alphaSupport: false, /* set to true to enable alpha picking */ 1733 alphaPrecision: 0, /* set decimal precision for alpha percentage display - hex codes do not map directly to percentage integers - range 0-2 */ 1734 updateInputColor: true /* set to false to prevent binded input colors from changing */ 1735 }, 1736 color: 1737 { 1738 mode: 'h', /* acceptabled values "h" (hue), "s" (saturation), "v" (value), "r" (red), "g" (green), "b" (blue), "a" (alpha) */ 1739 active: new Color({ ahex: '#ffcc00ff' }), /* acceptable values are any declared $.jPicker.Color object or string HEX value (e.g. #ffc000) WITH OR WITHOUT the "#" prefix */ 1740 quickList: /* the quick pick color list */ 1741 [ 1742 new Color({ h: 360, s: 33, v: 100 }), /* acceptable values are any declared $.jPicker.Color object or string HEX value (e.g. #ffc000) WITH OR WITHOUT the "#" prefix */ 1743 new Color({ h: 360, s: 66, v: 100 }), 1744 new Color({ h: 360, s: 100, v: 100 }), 1745 new Color({ h: 360, s: 100, v: 75 }), 1746 new Color({ h: 360, s: 100, v: 50 }), 1747 new Color({ h: 180, s: 0, v: 100 }), 1748 new Color({ h: 30, s: 33, v: 100 }), 1749 new Color({ h: 30, s: 66, v: 100 }), 1750 new Color({ h: 30, s: 100, v: 100 }), 1751 new Color({ h: 30, s: 100, v: 75 }), 1752 new Color({ h: 30, s: 100, v: 50 }), 1753 new Color({ h: 180, s: 0, v: 90 }), 1754 new Color({ h: 60, s: 33, v: 100 }), 1755 new Color({ h: 60, s: 66, v: 100 }), 1756 new Color({ h: 60, s: 100, v: 100 }), 1757 new Color({ h: 60, s: 100, v: 75 }), 1758 new Color({ h: 60, s: 100, v: 50 }), 1759 new Color({ h: 180, s: 0, v: 80 }), 1760 new Color({ h: 90, s: 33, v: 100 }), 1761 new Color({ h: 90, s: 66, v: 100 }), 1762 new Color({ h: 90, s: 100, v: 100 }), 1763 new Color({ h: 90, s: 100, v: 75 }), 1764 new Color({ h: 90, s: 100, v: 50 }), 1765 new Color({ h: 180, s: 0, v: 70 }), 1766 new Color({ h: 120, s: 33, v: 100 }), 1767 new Color({ h: 120, s: 66, v: 100 }), 1768 new Color({ h: 120, s: 100, v: 100 }), 1769 new Color({ h: 120, s: 100, v: 75 }), 1770 new Color({ h: 120, s: 100, v: 50 }), 1771 new Color({ h: 180, s: 0, v: 60 }), 1772 new Color({ h: 150, s: 33, v: 100 }), 1773 new Color({ h: 150, s: 66, v: 100 }), 1774 new Color({ h: 150, s: 100, v: 100 }), 1775 new Color({ h: 150, s: 100, v: 75 }), 1776 new Color({ h: 150, s: 100, v: 50 }), 1777 new Color({ h: 180, s: 0, v: 50 }), 1778 new Color({ h: 180, s: 33, v: 100 }), 1779 new Color({ h: 180, s: 66, v: 100 }), 1780 new Color({ h: 180, s: 100, v: 100 }), 1781 new Color({ h: 180, s: 100, v: 75 }), 1782 new Color({ h: 180, s: 100, v: 50 }), 1783 new Color({ h: 180, s: 0, v: 40 }), 1784 new Color({ h: 210, s: 33, v: 100 }), 1785 new Color({ h: 210, s: 66, v: 100 }), 1786 new Color({ h: 210, s: 100, v: 100 }), 1787 new Color({ h: 210, s: 100, v: 75 }), 1788 new Color({ h: 210, s: 100, v: 50 }), 1789 new Color({ h: 180, s: 0, v: 30 }), 1790 new Color({ h: 240, s: 33, v: 100 }), 1791 new Color({ h: 240, s: 66, v: 100 }), 1792 new Color({ h: 240, s: 100, v: 100 }), 1793 new Color({ h: 240, s: 100, v: 75 }), 1794 new Color({ h: 240, s: 100, v: 50 }), 1795 new Color({ h: 180, s: 0, v: 20 }), 1796 new Color({ h: 270, s: 33, v: 100 }), 1797 new Color({ h: 270, s: 66, v: 100 }), 1798 new Color({ h: 270, s: 100, v: 100 }), 1799 new Color({ h: 270, s: 100, v: 75 }), 1800 new Color({ h: 270, s: 100, v: 50 }), 1801 new Color({ h: 180, s: 0, v: 10 }), 1802 new Color({ h: 300, s: 33, v: 100 }), 1803 new Color({ h: 300, s: 66, v: 100 }), 1804 new Color({ h: 300, s: 100, v: 100 }), 1805 new Color({ h: 300, s: 100, v: 75 }), 1806 new Color({ h: 300, s: 100, v: 50 }), 1807 new Color({ h: 180, s: 0, v: 0 }), 1808 new Color({ h: 330, s: 33, v: 100 }), 1809 new Color({ h: 330, s: 66, v: 100 }), 1810 new Color({ h: 330, s: 100, v: 100 }), 1811 new Color({ h: 330, s: 100, v: 75 }), 1812 new Color({ h: 330, s: 100, v: 50 }), 1813 new Color() 1814 ] 1815 }, 1816 images: 1817 { 1818 clientPath: '/jPicker/images/', /* Path to image files */ 1819 colorMap: 1820 { 1821 width: 256, 1822 height: 256, 1823 arrow: 1824 { 1825 file: 'mappoint.gif', /* ColorMap arrow icon */ 1826 width: 15, 1827 height: 15 1828 } 1829 }, 1830 colorBar: 1831 { 1832 width: 20, 1833 height: 256, 1834 arrow: 1835 { 1836 file: 'rangearrows.gif', /* ColorBar arrow icon */ 1837 width: 20, 1838 height: 7 1839 } 1840 }, 1841 picker: 1842 { 1843 file: 'picker.gif', /* Color Picker icon */ 1844 width: 25, 1845 height: 24 1846 } 1847 }, 1848 localization: /* alter these to change the text presented by the picker (e.g. different language) */ 1849 { 1850 text: 1851 { 1852 title: 'Drag Markers To Pick A Color', 1853 newColor: 'new', 1854 currentColor: 'current', 1855 ok: 'OK', 1856 cancel: 'Cancel' 1857 }, 1858 tooltips: 1859 { 1860 colors: 1861 { 1862 newColor: 'New Color - Press “OK” To Commit', 1863 currentColor: 'Click To Revert To Original Color' 1864 }, 1865 buttons: 1866 { 1867 ok: 'Commit To This Color Selection', 1868 cancel: 'Cancel And Revert To Original Color' 1869 }, 1870 hue: 1871 { 1872 radio: 'Set To “Hue”
1872 Color Mode', 1873 textbox: 'Enter A “Hue” Value (0-360°)' 1874 }, 1875 saturation: 1876 { 1877 radio: 'Set To “Saturation” Color Mode', 1878 textbox: 'Enter A “Saturation” Value (0-100%)' 1879 }, 1880 value: 1881 { 1882 radio: 'Set To “Value” Color Mode', 1883 textbox: 'Enter A “Value” Value (0-100%)' 1884 }, 1885 red: 1886 { 1887 radio: 'Set To “Red” Color Mode', 1888 textbox: 'Enter A “Red” Value (0-255)' 1889 }, 1890 green: 1891 { 1892 radio: 'Set To “Green” Color Mode', 1893 textbox: 'Enter A “Green” Value (0-255)' 1894 }, 1895 blue: 1896 { 1897 radio: 'Set To “Blue” Color Mode', 1898 textbox: 'Enter A “Blue” Value (0-255)' 1899 }, 1900 alpha: 1901 { 1902 radio: 'Set To “Alpha” Color Mode', 1903 textbox: 'Enter A “Alpha” Value (0-100)' 1904 }, 1905 hex: 1906 { 1907 textbox: 'Enter A “Hex” Color Value (#000000-#ffffff)', 1908 alpha: 'Enter A “Alpha” Value (#00-#ff)' 1909 } 1910 } 1911 } 1912 }; 1913})(jQuery, '1.1.6');; 1914//this file is not used anymore but kept here for further usages which may come 1915var isIframeApp = false; 1916if (location.href.indexOf('loginForm') > 0) { 1917 isIframeApp = true; 1918} 1919function addToList(list, items) { 1920 if (items != null) 1921 for (var i = 0, n = items.length; i < n; i++) 1922 list.append('<option value="' + items[i].Id + '" title="' + ((items[i].Description == null) ? '' : items[i].Description) + '">' + items[i].Name + '</option>'); 1923 1924 var options = list.find("option"); 1925 1926 options.sort(function (a, b) { 1927 if (a.text > b.text) return 1; 1928 else if (a.text < b.text) return -1; 1929 else return 0; 1930 }); 1931 1932 list.empty().append(options); 1933} 1934 1935function move(source, dest, all) { 1936 var selected = source.find("option" + (all ? "" : ":selected")); 1937 1938 addToList(dest, selected.map(function () { 1939 var i = $(this); 1940 1941 return { 1942 Id: i.val(), 1943 Name: i.text(), 1944 Description: i.attr("title") 1945 }; 1946 })); 1947 1948 selected.each(function () { $(this).remove(); }); 1949} 1950 1951function getList(list) { 1952 var result = []; 1953 1954 list.find("option").each(function () { 1955 var i = $(this); 1956 1957 result.push({ 1958 Id: i.val(), 1959 Name: i.text(), 1960 Description: i.attr("title") 1961 }); 1962 }); 1963 1964 return result; 1965} 1966 1967function getListValues(list) { 1968 var result = []; 1969 1970 list.find("option").each(function () { 1971 var i = $(this); 1972 1973 result.push(i.val()); 1974 }); 1975 1976 return result; 1977}; 1978(function ($) { 1979 $.fn.semaphore = function (options) { 1980 var defaults = { 1981 images: ["semaphore_blank", "semaphore_gray", "semaphore_yellow", "semaphore_blue", "semaphore_green", "semaphore_red"], 1982 mappings: [-1, 1, 2, 3, 4], 1983 imgIdxIntVal: 0 1984 }; 1985 1986 var parameters = $.extend(defaults, options); 1987 1988 return this.each(function () { 1989 var bubbles = new Array(); 1990 var valImgIdxInt; 1991 1992 //init start 1993 bubbles = defaults.images; 1994 1995 var initValImgIdx = $(this).val(); 1996 1997 if (initValImgIdx == "") { 1998 valImgIdxInt = defaults.imgIdxIntVal; 1999 $(this).val(defaults.mappings[valImgIdxInt]); 2000 } 2001 else { 2002 valImgIdxInt = defaults.mappings.indexOf(parseInt(initValImgIdx)); 2003 } 2004 // init stop 2005 2006 $(this).hide(); 2007 2008 var imgBubbleId = this.id + '_img'; 2009 var imgBubble = '<div class="' + bubbles[valImgIdxInt] + '" id="' + imgBubbleId + '" img_Idx="' + valImgIdxInt + '" inputContainer="' + this.id + '" />'; 2010 2011 if ($(this).attr('test') != this.id + '_img_bubble') { 2012 $(this).after(imgBubble); 2013 $(this).attr('test', this.id + '_img_bubble') 2014 } 2015 else { 2016 var valImgIdx = $(this).val(); 2017 valImgIdxInt = defaults.mappings.indexOf(parseInt(initValImgIdx)); 2018 2019 $("#" + this.id + "_img").attr("img_Idx", valImgIdxInt); 2020 $("#" + this.id + "_img").attr("class", bubbles[valImgIdxInt]); 2021 2022 $(this).change(); 2023 2024 $("#" + this.id + "_img").off(); 2025 } 2026 2027 $("#" + this.id + "_img").bind('click', function (ev) { 2028 if (ev.target.id == this.id) { 2029 var valImgIdx = $(ev.target).attr('img_idx'); 2030 var valImgIdxInt = parseInt(valImgIdx); 2031 var inputContainer = '#' + $(ev.target).attr('inputContainer'); 2032 2033 if (valImgIdxInt < bubbles.length - 1) 2034 valImgIdxInt += 1; 2035 else 2036 valImgIdxInt = 0; 2037 2038 $(this).attr("img_Idx", valImgIdxInt); 2039 $(this).attr("class", bubbles[valImgIdxInt]); 2040 2041 $(inputContainer).val(defaults.mappings[valImgIdxInt]); 2042 $(inputContainer).change(); 2043 } 2044 }); 2045 }); 2046 }; 2047})(jQuery);; 2048(function($){ 2049 2050 $.fn.TimeLinePlugin = function(options){ 2051 2052 var defaults = { 2053 2054 'monthVal': 0,
2055 'yearVal': 2013, 2056 'eventsVal': [], 2057 'monthsVal': ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], 2058 'typeVal': 0, 2059 'clickOnEventFunc': function(val) {alert('Has event on ' + val);}, 2060 'clickOnNoEventFunc': function(val) {alert('Has no event on ' + val);} 2061 }; 2062 2063 var parameters = $.extend(defaults,options); 2064 2065 2066 return this.each(function(){ 2067 var s; 2068 var divId = this.id; 2069 var events = new Array(); 2070 var months = []; 2071 2072 //start init 2073 m = defaults.monthVal; 2074 y = defaults.yearVal; 2075 events = defaults.eventsVal 2076 months = defaults.monthsVal; 2077 type = defaults.typeVal; 2078 //stop init 2079 2080 2081 if(type == 0) 2082 s = drawTimelineDays(m, y); 2083 else if(type == 1) 2084 s = drawTimelineMonths(y); 2085 else if (type == 2) 2086 s = drawTimelineYears(y); 2087 else 2088 s = drawTimeline10Years(y); 2089 2090 $(this).html(s); 2091 2092 2093 $(this).bind('click',function(ev){ 2094 //debugger; 2095 //if(ev.target == "#eventBtn"){ 2096 //alert('button[id^=#eventBtn]'); 2097 //alert('ev.target.id=' + ev.target.id); 2098 //var v = $('button[id^=#eventBtn]'); 2099 //alert(ev.target.id); 2100 divId = this.id; 2101 2102 var date_nr_y = ev.target.attributes['date_event'].value; 2103 var date_nr_m = ev.target.attributes['date_event_m'].value; 2104 var curTlT = ev.target.attributes['cTlT'].value; 2105 var year = parseInt(date_nr_y); 2106 var month = parseInt(date_nr_m); 2107 var currentType = parseInt(curTlT); 2108 var day = ev.target.attributes['date_event_d'].value; 2109 //var s; 2110 2111 if(ev.target.id.indexOf(divId + "_eventBtn") != -1){ 2112 if(currentType == -1){ 2113 //alert("event"); 2114 if(parameters.clickOnEventFunc) { 2115 2116 parameters.clickOnEventFunc(day + ' ' + months[month] + ' ' + year); 2117 } 2118 } 2119 else if(currentType == 0){ 2120 s = drawTimelineDays(month, year); 2121 } 2122 else if(currentType == 1){ 2123 s = drawTimelineMonths(year); 2124 } 2125 else if(currentType == 2){ 2126 s = drawTimelineYears(year); 2127 } 2128 else if(currentType == 3){ 2129 s = drawTimeline10Years(year); 2130 } 2131 } 2132 2133 if(ev.target.id.indexOf(divId + "_noeventBtn") != -1){ 2134 if(currentType == -1){ 2135 //alert("noevent"); 2136 if(parameters.clickOnNoEventFunc) 2137 parameters.clickOnNoEventFunc(day + ' ' + months[month] + ' ' + year); 2138 } 2139 else if(currentType == 0){ 2140 s = drawTimelineDays(month, year); 2141 } 2142 else if(currentType == 1){ 2143 s = drawTimelineMonths(year); 2144 } 2145 else if(currentType == 2){ 2146 s = drawTimelineYears(year); 2147 } 2148 else if(currentType == 3){ 2149 s = drawTimeline10Years(year); 2150 } 2151 } 2152 2153 if(ev.target.id.indexOf(divId + "_prevBtn") != -1){ 2154 s = drawTimelinePreviousNext(month, year, -1, currentType); 2155 } 2156 2157 if(ev.target.id.indexOf(divId + "_nextBtn") != -1){ 2158 s = drawTimelinePreviousNext(month, year, 1, currentType); 2159 } 2160 2161 if(ev.target.id.indexOf(divId + "_header") != -1){ 2162 if(currentType == 1){ 2163 s = drawTimelineMonths(year); 2164 } 2165 else if(currentType == 2){ 2166 s = drawTimelineYears(year); 2167 } 2168 else if(currentType == 3){ 2169 s = drawTimeline10Years(year); 2170 } 2171 } 2172 2173 if(ev.target.id.indexOf(divId + "_img") != -1){ 2174 if(currentType == -1){ 2175 if(parameters.clickOnEventFunc) 2176 parameters.clickOnEventFunc(day + ' ' + months[month] + ' ' + year); 2177 } 2178 else if(currentType == 0){ 2179 s = drawTimelineDays(month, year); 2180 } 2181 else if(currentType == 1){ 2182 s = drawTimelineMonths(year); 2183 } 2184 else if(currentType == 2){ 2185 s = drawTimelineYears(year); 2186 } 2187 else if(currentType == 3){ 2188 s = drawTimeline10Years(year); 2189 } 2190 } 2191 2192 $(this).html(s); 2193 }); 2194 2195 2196 function drawTimelineDays(month, year) { 2197 2198 if (!isYearValid(year)) 2199 return; 2200 2201 var s = '<a class="k-button" id="' + divId + '_header" date_event=' + year + ' date_event_m=' + 0 + ' date_event_d=' + date_str + ' cTlT=' + 1 + '>' + 2202 months[month] + ' ' + year + '</a><div style="height: 10px;"></div><div class="timeline-scroller"><table border="0" cellspacing="0" cellpadding="0">'; 2203 2204 s += '<tr>'; 2205 2206 var cDate = new Date(year, month, 1); 2207 2208 var endDate = new Date(cDate.getFullYear(), cDate.getMonth() + 1, 0); 2209 2210 s += '<td><button class="k-button" id="' + divId + '_prevBtn" date_event=' + year + ' date_event_m=' + month + ' date_event_d=' + date_str + ' cTlT=' + 0 + ' ><</button></td>'; 2211 2212 while (cDate <= endDate) { 2213 var date_str = cDate.getDate(); 2214 var hasEvent = false; 2215 2216 for (var i = 0, n = events.length; i < n; i++) 2217 if (events[i].getTime() == cDate.getTime()) { 2218 hasEvent = true; 2219 break; 2220 } 2221 2222 s += '<td style="text-align: center" colspan="2" valign="top">' + 2223 (hasEvent ? 2224 ('<button id="' + divId + '_eventBtn" style="width:46px" class="k-button" date_event=' + cDate.getFullYear() + ' date_event_m=' + month + ' date_event_d=' + date_str + ' cTlT=-1 >' + date_str + '</button>') : 2225 ('<button id="' + divId + '_noeventBtn" style="width:46px" class="k-button k-state-disabled" date_event=' + cDate.getFullYear() + ' date_event_m=' + month + ' date_event_d=' + date_str +' cTlT=-1 >' + date_str + '</button>') 2226 ) + 2227 '──┼──<br/>' + 2228 (hasEvent ? ('<img id="'+ divId + '_img " src="Content/Images/event-marker.png" style="border: none;" date_event=' + cDate.getFullYear() + ' date_event_m=' + month + ' date_event_d=' + date_str + ' cTlT=-1 />') : '') + 2229 '</td>'; 2230 cDate.setDate(cDate.getDate() + 1); 2231 } 2232 2233 s += '<td><button class="k-button" id="' + divId + '_nextBtn" date_event=' + year + ' date_event_m=' + month + ' date_event_d=' + date_str + ' cTlT=' + 0 + ' >></button></td>'; 2234 2235 s += '</tr></table></div>'; 2236 2237 return s; 2238 } 2239 2240 function drawTimelineMonths(year) { 2241 2242 if (!isYearValid(year)) 2243 return; 2244 2245 var s = '<a class="k-button" id="' + divId + '_header" style="display: block;" date_event=' + year + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 2 + ' >' + 2246 year + '</a><div style="height: 10px;"></div><div class="timeline-scroller"><table border="0" cellspacing="0" cellpadding="0">'; 2247 2248 s += '<tr>'; 2249 2250 s += '<td><button class="k-button" id="' + divId + '_prevBtn" date_event=' + year + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 1 + ' ><</button></td>'; 2251 2252 for (var m = 0; m < 12; m++) { 2253 var date_str = months[m]; 2254 var cDate = new Date(year, m, 1); 2255 var hasEvent = false; 2256 2257 for (var i = 0, n = events.length; i < n; i++) 2258 if ((events[i].getYear() == cDate.getYear()) && (events[i].getMonth() == cDate.getMonth())) { 2259 hasEvent = true; 2260 break; 2261 } 2262 2263 s += '<td style="text-align: center" colspan="2" valign="top">' + 2264 (hasEvent ? 2265 ('<button id="' + divId + '_eventBtn" class="k-button" date_event_m =' + (m) + ' date_event = ' + year + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 0 + ' >' + date_str + '</button>') : 2266 ('<button id="' + divId + '_noeventBtn" class="k-button k-state-disabled" date_event_m =' + (m) + ' date_event=' + year + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 0 + '>' + date_str + '</button>') 2267 ) + 2268 '─────┼─────<br/>' + 2269 (hasEvent ? ('<img id="'+ divId + '_img " src="Content/Images/event-marker.png" style="border: none;" date_event_m =' + (m) + ' date_event =' + year + ' date_event_d=' + 1 + ' cTlT=' + 0 + ' />') : '') + 2270 '</td>'; 2271 cDate.setDate(cDate.getDate() + 1); 2272 } 2273 2274 s += '<td><button class="k-button" id="' + divId + '_nextBtn" date_event=' + year + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 1 + '>></button></td>'; 2275 2276 s += '</tr></table></div>'; 2277 2278 return s; 2279 } 2280 2281 function drawTimelineYears(year) { 2282 2283 if (!isYearValid(year)) 2284 return; 2285 2286 var startYear = (year / 10).toFixed(0) * 10; 2287 var endYear = startYear + 9; 2288 2289 var s = '<a class="k-button" id="' + divId + '_header" style="display: block;" date_event=' + year + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 3 + '>' + 2290 startYear + ' - ' + endYear + '</a><div style="height: 10px;"></div><div class="timeline-scroller"><table border="0" cellspacing="0" cellpadding="0">'; 2291 2292 s += '<tr>'; 2293 2294 s += '<td><button class="k-button" id="' + divId + '_prevBtn" date_event=' + year + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 2 + '><</button></td>'; 2295 2296 for (var y = startYear; y <= endYear; y++) { 2297 var date_str = y; 2298 var cDate = new Date(y, 0, 1); 2299 var hasEvent = false; 2300 2301 for (var i = 0, n = events.length; i < n; i++) 2302 if (events[i].getYear() == cDate.getYear()) { 2303 hasEvent = true; 2304 break; 2305 } 2306 2307 s += '<td style="text-align: center" colspan="2" valign="top">' + 2308 (hasEvent ? 2309 ('<button id="' + divId + '_eventBtn" class="k-button" date_event=' + y + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 1 + ' >' + date_str + '</button>') : 2310 ('<button id="' + divId + '_noeventBtn" class="k-button k-state-disabled" date_event=' + y + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 1 + ' >' + date_str + '</button>') 2311 ) + 2312 '───┼───<br/>' + 2313 (hasEvent ? ('<img id="'+ divId + '_img " src="Content/Images/event-marker.png" style="border: none;" date_event=' + y + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 1 + ' />') : '') + 2314 '</td>'; 2315 cDate.setDate(cDate.getDate() + 1); 2316 } 2317 2318 s += '<td><button class="k-button" id="' + divId + '_nextBtn" date_event=' + year + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 2 + ' >></button></td>'; 2319 2320 s += '</tr></table></div>'; 2321 2322 return s; 2323 } 2324 2325 function drawTimeline10Years(year) { 2326 2327 if (!isYearValid(year)) 2328 return; 2329 2330 var startYear = (year / 100).toFixed(0) * 100; 2331 var endYear = startYear + 99; 2332 var s = '<a class="k-button k-state-disabled" id="' + divId + '_header" style="display: block;" date_event="" date_event_m="" cTlT="">' + 2333 startYear + ' - ' + endYear + '</a><div style="height: 10px;"></div><div class="timeline-scroller"><table border="0" cellspacing="0" cellpadding="0">'; 2334 2335 s += '<tr>'; 2336 2337 s += '<td><button class="k-button" id="' + divId + '_prevBtn" date_event=' + year + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 3 + '><</button></td>'; 2338 2339 for (var y = startYear; y <= endYear; y += 10) { 2340 var date_str = y + "-" + (y + 9); 2341 var cDate = new Date(y, 1, 1); 2342 var hasEvent = false; 2343 2344 for (var i = 0, n = events.length; i < n; i++) 2345 if ((events[i].getYear() >= cDate.getYear()) && (events[i].getYear() <= cDate.getYear() + 9)) { 2346 hasEvent = true; 2347 break; 2348 } 2349 2350 s += '<td style="text-align: center" colspan="2" valign="top">' + 2351 (hasEvent ? 2352 ('<button id="' + divId + '_eventBtn" class="k-button" date_event=' + y + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 2 + ' >' + date_str + '</button>') : 2353 ('<button id="' + divId + '_noeventBtn" class="k-button k-state-disabled" date_event=' + y + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 2 + ' >' + date_str + '</button>') 2354 ) + 2355 '─────┼─────<br/>' + 2356 (hasEvent ? ('<img id="'+ divId + '_img " src="Content/Images/event-marker.png" style="border: none;" date_event=' + y + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 2 + ' >') : '') + 2357 '</td>'; 2358 cDate.setDate(cDate.getDate() + 1); 2359 } 2360 2361 s += '<td><button class="k-button" id="' + divId + '_nextBtn" date_event=' + year + ' date_event_m=' + 0 + ' date_event_d=' + 1 + ' cTlT=' + 3 + ' >></button></td>'; 2362 2363 s += '</tr></table></div>'; 2364 2365 return s; 2366 } 2367 2368 //type -> 0 = month, 1 = year, 2 = 10 years, 3 = 100 years; 2369 //direction -> 0 = previous, 1 = next 2370 //val -> month or year value 2371 function drawTimelinePreviousNext(month, year, direction, type) { 2372 2373 var startDate = new Date(year, month, 1) 2374 2375 if (type == 0) { 2376 if (direction == -1) 2377 startDate = new Date(startDate.getFullYear(), startDate.getMonth() - 1, 1); 2378 else 2379 startDate = new Date(startDate.getFullYear(), startDate.getMonth() + 1, 1); 2380 2381 return drawTimelineDays(startDate.getMonth(), startDate.getFullYear()); 2382 } 2383 else if (type == 1) { 2384 if (direction == -1)
2385 year = year - 1; 2386 else 2387 year = year + 1; 2388 2389 return drawTimelineMonths(year); 2390 } 2391 else if (type == 2) { 2392 if (direction == -1) 2393 year = year - 10; 2394 else 2395 year = year + 10; 2396 2397 return drawTimelineYears(year); 2398 } 2399 else { 2400 if (direction == -1) 2401 year = year - 100; 2402 else 2403 year = year + 100; 2404 2405 return drawTimeline10Years(year); 2406 } 2407 } 2408 2409 function isYearValid(year) { 2410 2411 if (year < 1900 || year > 2099) 2412 return false; 2413 else 2414 return true; 2415 } 2416 2417 }); 2418 }; 2419 2420 })(jQuery);; 2421/* 2422 json2.js 2423 2012-10-08 2424 2425 Public Domain. 2426 2427 NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. 2428 2429 See http://www.JSON.org/js.html 2430 2431 2432 This code should be minified before deployment. 2433 See http://javascript.crockford.com/jsmin.html 2434 2435 USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO 2436 NOT CONTROL. 2437 2438 2439 This file creates a global JSON object containing two methods: stringify 2440 and parse. 2441 2442 JSON.stringify(value, replacer, space) 2443 value any JavaScript value, usually an object or array. 2444 2445 replacer an optional parameter that determines how object 2446 values are stringified for objects. It can be a 2447 function or an array of strings. 2448 2449 space an optional parameter that specifies the indentation 2450 of nested structures. If it is omitted, the text will 2451 be packed without extra whitespace. If it is a number, 2452 it will specify the number of spaces to indent at each 2453 level. If it is a string (such as '\t' or ' '), 2454 it contains the characters used to indent at each level. 2455 2456 This method produces a JSON text from a JavaScript value. 2457 2458 When an object value is found, if the object contains a toJSON 2459 method, its toJSON method will be called and the result will be 2460 stringified. A toJSON method does not serialize: it returns the 2461 value represented by the name/value pair that should be serialized, 2462 or undefined if nothing should be serialized. The toJSON method 2463 will be passed the key associated with the value, and this will be 2464 bound to the value 2465 2466 For example, this would serialize Dates as ISO strings. 2467 2468 Date.prototype.toJSON = function (key) { 2469 function f(n) { 2470 // Format integers to have at least two digits. 2471 return n < 10 ? '0' + n : n; 2472 } 2473 2474 return this.getUTCFullYear() + '-' + 2475 f(this.getUTCMonth() + 1) + '-' + 2476 f(this.getUTCDate()) + 'T' + 2477 f(this.getUTCHours()) + ':' + 2478 f(this.getUTCMinutes()) + ':' + 2479 f(this.getUTCSeconds()) + 'Z'; 2480 }; 2481 2482 You can provide an optional replacer method. It will be passed the 2483 key and value of each member, with this bound to the containing 2484 object. The value that is returned from your method will be 2485 serialized. If your method returns undefined, then the member will 2486 be excluded from the serialization. 2487 2488 If the replacer parameter is an array of strings, then it will be 2489 used to select the members to be serialized. It filters the results 2490 such that only members with keys listed in the replacer array are 2491 stringified. 2492 2493 Values that do not have JSON representations, such as undefined or 2494 functions, will not be serialized. Such values in objects will be 2495 dropped; in arrays they will be replaced with null. You can use 2496 a replacer function to replace those with JSON values. 2497 JSON.stringify(undefined) returns undefined. 2498 2499 The optional space parameter produces a stringification of the 2500 value that is filled with line breaks and indentation to make it 2501 easier to read. 2502 2503 If the space parameter is a non-empty string, then that string will 2504 be used for indentation. If the space parameter is a number, then 2505 the indentation will be that many spaces. 2506 2507 Example: 2508 2509 text = JSON.stringify(['e', {pluribus: 'unum'}]); 2510 // text is '["e",{"pluribus":"unum"}]' 2511 2512 2513 text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); 2514 // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' 2515 2516 text = JSON.stringify([new Date()], function (key, value) { 2517 return this[key] instanceof Date ? 2518 'Date(' + this[key] + ')' : value; 2519 }); 2520 // text is '["Date(---current time---)"]' 2521 2522 2523 JSON.parse(text, reviver) 2524 This method parses a JSON text to produce an object or array. 2525 It can throw a SyntaxError exception. 2526 2527 The optional reviver parameter is a function that can filter and 2528 transform the results. It receives each of the keys and values, 2529 and its return value is used instead of the original value. 2530 If it returns what it received, then the structure is not modified. 2531 If it returns undefined then the member is deleted. 2532 2533 Example: 2534 2535 // Parse the text. Values that look like ISO date strings will 2536 // be converted to Date objects. 2537 2538 myData = JSON.parse(text, function (key, value) { 2539 var a; 2540 if (typeof value === 'string') { 2541 a = 2542/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); 2543 if (a) { 2544 return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], 2545 +a[5], +a[6])); 2546 } 2547 } 2548 return value; 2549 }); 2550 2551 myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { 2552 var d; 2553 if (typeof value === 'string' && 2554 value.slice(0, 5) === 'Date(' && 2555 value.slice(-1) === ')') { 2556 d = new Date(value.slice(5, -1)); 2557 if (d) { 2558 return d; 2559 } 2560 } 2561 return value; 2562 }); 2563 2564 2565 This is a reference implementation. You are free to copy, modify, or 2566 redistribute. 2567*/ 2568 2569/*jslint evil: true, regexp: true */ 2570 2571/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, 2572 call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, 2573 getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, 2574 lastIndex, length, parse, prototype, push, replace, slice, stringify, 2575 test, toJSON, toString, valueOf 2576*/ 2577 2578 2579// Create a JSON object only if one does not already exist. We create the 2580// methods in a closure to avoid creating global variables. 2581 2582if (typeof JSON !== 'object') { 2583 JSON = {}; 2584} 2585 2586(function () { 2587 'use strict'; 2588 2589 function f(n) { 2590 // Format integers to have at least two digits. 2591 return n < 10 ? '0' + n : n; 2592 } 2593 2594 if (typeof Date.prototype.toJSON !== 'function') { 2595 2596 Date.prototype.toJSON = function (key) { 2597 2598 return isFinite(this.valueOf()) 2599 ? this.getUTCFullYear() + '-' + 2600 f(this.getUTCMonth() + 1) + '-' + 2601 f(this.getUTCDate()) + 'T' + 2602 f(this.getUTCHours()) + ':' + 2603 f(this.getUTCMinutes()) + ':' + 2604 f(this.getUTCSeconds()) + 'Z' 2605 : null; 2606 }; 2607 2608 String.prototype.toJSON = 2609 Number.prototype.toJSON = 2610 Boolean.prototype.toJSON = function (key) { 2611 return this.valueOf(); 2612 }; 2613 } 2614 2615 var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, 2616 escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, 2617 gap, 2618 indent, 2619 meta = { // table of character substitutions 2620 '\b': '\\b', 2621 '\t': '\\t', 2622 '\n': '\\n', 2623 '\f': '\\f', 2624 '\r': '\\r', 2625 '"' : '\\"', 2626 '\\': '\\\\' 2627 }, 2628 rep; 2629 2630 2631 function quote(string) { 2632
vendor: 9,237 bytes, lines 2633-2890
2633// If the string contains no control characters, no quote characters, and no 2634// backslash characters, then we can safely slap some quotes around it. 2635// Otherwise we must also replace the offending characters with safe escape 2636// sequences. 2637 2638 escapable.lastIndex = 0; 2639 return escapable.test(string) ? '"' + string.replace(escapable, function (a) { 2640 var c = meta[a]; 2641 return typeof c === 'string' 2642 ? c 2643 : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); 2644 }) + '"' : '"' + string + '"'; 2645 } 2646 2647 2648 function str(key, holder) { 2649 2650// Produce a string from holder[key]. 2651 2652 var i, // The loop counter. 2653 k, // The member key. 2654 v, // The member value. 2655 length, 2656 mind = gap, 2657 partial, 2658 value = holder[key]; 2659 2660// If the value has a toJSON method, call it to obtain a replacement value. 2661 2662 if (value && typeof value === 'object' && 2663 typeof value.toJSON === 'function') { 2664 value = value.toJSON(key); 2665 } 2666 2667// If we were called with a replacer function, then call the replacer to 2668// obtain a replacement value. 2669 2670 if (typeof rep === 'function') { 2671 value = rep.call(holder, key, value); 2672 } 2673 2674// What happens next depends on the value's type. 2675 2676 switch (typeof value) { 2677 case 'string': 2678 return quote(value); 2679 2680 case 'number': 2681 2682// JSON numbers must be finite. Encode non-finite numbers as null. 2683 2684 return isFinite(value) ? String(value) : 'null'; 2685 2686 case 'boolean': 2687 case 'null': 2688 2689// If the value is a boolean or null, convert it to a string. Note: 2690// typeof null does not produce 'null'. The case is included here in 2691// the remote chance that this gets fixed someday. 2692 2693 return String(value); 2694 2695// If the type is 'object', we might be dealing with an object or an array or 2696// null. 2697 2698 case 'object': 2699 2700// Due to a specification blunder in ECMAScript, typeof null is 'object', 2701// so watch out for that case. 2702 2703 if (!value) { 2704 return 'null'; 2705 } 2706 2707// Make an array to hold the partial results of stringifying this object value. 2708 2709 gap += indent; 2710 partial = []; 2711 2712// Is the value an array? 2713 2714 if (Object.prototype.toString.apply(value) === '[object Array]') { 2715 2716// The value is an array. Stringify every element. Use null as a placeholder 2717// for non-JSON values. 2718 2719 length = value.length; 2720 for (i = 0; i < length; i += 1) { 2721 partial[i] = str(i, value) || 'null'; 2722 } 2723 2724// Join all of the elements together, separated with commas, and wrap them in 2725// brackets. 2726 2727 v = partial.length === 0 2728 ? '[]' 2729 : gap 2730 ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' 2731 : '[' + partial.join(',') + ']'; 2732 gap = mind; 2733 return v; 2734 } 2735 2736// If the replacer is an array, use it to select the members to be stringified. 2737 2738 if (rep && typeof rep === 'object') { 2739 length = rep.length; 2740 for (i = 0; i < length; i += 1) { 2741 if (typeof rep[i] === 'string') { 2742 k = rep[i]; 2743 v = str(k, value); 2744 if (v) { 2745 partial.push(quote(k) + (gap ? ': ' : ':') + v); 2746 } 2747 } 2748 } 2749 } else { 2750 2751// Otherwise, iterate through all of the keys in the object. 2752 2753 for (k in value) { 2754 if (Object.prototype.hasOwnProperty.call(value, k)) { 2755 v = str(k, value); 2756 if (v) { 2757 partial.push(quote(k) + (gap ? ': ' : ':') + v); 2758 } 2759 } 2760 } 2761 } 2762 2763// Join all of the member texts together, separated with commas, 2764// and wrap them in braces. 2765 2766 v = partial.length === 0 2767 ? '{}' 2768 : gap 2769 ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' 2770 : '{' + partial.join(',') + '}'; 2771 gap = mind; 2772 return v; 2773 } 2774 } 2775 2776// If the JSON object does not yet have a stringify method, give it one. 2777 2778 if (typeof JSON.stringify !== 'function') { 2779 JSON.stringify = function (value, replacer, space) { 2780 2781// The stringify method takes a value and an optional replacer, and an optional 2782// space parameter, and returns a JSON text. The replacer can be a function 2783// that can replace values, or an array of strings that will select the keys. 2784// A default replacer method can be provided. Use of the space parameter can 2785// produce text that is more easily readable. 2786 2787 var i; 2788 gap = ''; 2789 indent = ''; 2790 2791// If the space parameter is a number, make an indent string containing that 2792// many spaces. 2793 2794 if (typeof space === 'number') { 2795 for (i = 0; i < space; i += 1) { 2796 indent += ' '; 2797 } 2798 2799// If the space parameter is a string, it will be used as the indent string. 2800 2801 } else if (typeof space === 'string') { 2802 indent = space; 2803 } 2804 2805// If there is a replacer, it must be a function or an array. 2806// Otherwise, throw an error. 2807 2808 rep = replacer; 2809 if (replacer && typeof replacer !== 'function' && 2810 (typeof replacer !== 'object' || 2811 typeof replacer.length !== 'number')) { 2812 throw new Error('JSON.stringify'); 2813 } 2814 2815// Make a fake root object containing our value under the key of ''. 2816// Return the result of stringifying the value. 2817 2818 return str('', {'': value}); 2819 }; 2820 } 2821 2822 2823// If the JSON object does not yet have a parse method, give it one. 2824 2825 if (typeof JSON.parse !== 'function') { 2826 JSON.parse = function (text, reviver) { 2827 2828// The parse method takes a text and an optional reviver function, and returns 2829// a JavaScript value if the text is a valid JSON text. 2830 2831 var j; 2832 2833 function walk(holder, key) { 2834 2835// The walk method is used to recursively walk the resulting structure so 2836// that modifications can be made. 2837 2838 var k, v, value = holder[key]; 2839 if (value && typeof value === 'object') { 2840 for (k in value) { 2841 if (Object.prototype.hasOwnProperty.call(value, k)) { 2842 v = walk(value, k); 2843 if (v !== undefined) { 2844 value[k] = v; 2845 } else { 2846 delete value[k]; 2847 } 2848 } 2849 } 2850 } 2851 return reviver.call(holder, key, value); 2852 } 2853 2854 2855// Parsing happens in four stages. In the first stage, we replace certain 2856// Unicode characters with escape sequences. JavaScript handles many characters 2857// incorrectly, either silently deleting them, or treating them as line endings. 2858 2859 text = String(text); 2860 cx.lastIndex = 0; 2861 if (cx.test(text)) { 2862 text = text.replace(cx, function (a) { 2863 return '\\u' + 2864 ('0000' + a.charCodeAt(0).toString(16)).slice(-4); 2865 }); 2866 } 2867 2868// In the second stage, we run the text against regular expressions that look 2869// for non-JSON patterns. We are especially concerned with '()' and 'new' 2870// because they can cause invocation, and '=' because it can cause mutation. 2871// But just to be safe, we want to reject all unexpected forms. 2872 2873// We split the second stage into 4 regexp operations in order to work around 2874// crippling inefficiencies in IE's and Safari's regexp engines. First we 2875// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we 2876// replace all simple value tokens with ']' characters. Third, we delete all 2877// open brackets that follow a colon or comma or that begin the text. Finally, 2878// we look to see that the remaining characters are only whitespace or ']' or 2879// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. 2880 2881 if (/^[\],:{}\s]*$/ 2882 .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@') 2883 .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') 2884 .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { 2885 2886// In the third stage we use the eval function to compile the text into a 2887// JavaScript structure. The '{' operator is subject to a syntactic ambiguity 2888// in JavaScript: it can begin a block or an object literal. We wrap the text 2889// in parens to eliminate the ambiguity. 2890
2891 j = eval('(' + text + ')'); 2892 2893// In the optional fourth stage, we recursively walk the new structure, passing 2894// each name/value pair to a reviver function for possible transformation. 2895 2896 return typeof reviver === 'function' 2897 ? walk({'': j}, '') 2898 : j; 2899 } 2900 2901// If the text is not JSON parseable, then a SyntaxError is thrown. 2902 2903 throw new SyntaxError('JSON.parse'); 2904 }; 2905 } 2906}()); 2907; 2908var showDownloadStartMessage = false; 2909var showDownloadEndMessage = false; 2910 2911//not used anymore 2912function createUUID() { 2913 // http://www.ietf.org/rfc/rfc4122.txt 2914 var s = []; 2915 var hexDigits = "0123456789abcdef"; 2916 for (var i = 0; i < 36; i++) { 2917 s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); 2918 } 2919 s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 2920 s[19] = hexDigits.substr(s[19] & 0x3 | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 2921 s[8] = s[13] = s[18] = s[23] = ""; 2922 2923 var uuid = s.join(""); 2924 return uuid; 2925} 2926 2927 2928function nothing() { 2929} 2930 2931 2932//get outer html 2933$.fn.outerHTML = function () { 2934 // IE, Chrome & Safari will comply with the non-standard outerHTML, all others (FF) will have a fall-back for cloning 2935 return !this.length ? this : this[0].outerHTML || ( 2936 function (el) { 2937 var div = document.createElement('div'); 2938 div.appendChild(el.cloneNode(true)); 2939 var contents = div.innerHTML; 2940 div = null; 2941 return contents; 2942 })(this[0]); 2943}; 2944 2945//get messages from db 2946function getMessages(componentId, allIds, nonAlert) { 2947 var ids = ""; 2948 if (allIds) { 2949 if (allIds.length == 0) { 2950 return; 2951 } 2952 2953 for (var i = 0; i < allIds.length; i++) { 2954 ids = ids + allIds[i].Id + ";"; 2955 } 2956 } 2957 else { 2958 ids = null; 2959 } 2960 log("getMessages(" + componentId + ", " + ids + ")"); 2961 if (componentId) 2962 ajaxCall((isIframeApp? "/":"") + 'Desktop/GetMessages/' + componentId, null, getMessagesCallback, componentId, allIds); 2963 else 2964 ajaxCall((isIframeApp? "/":"") + 'Desktop/GetMessages/', null, getMessagesCallback, componentId, allIds); 2965} 2966 2967////logout 2968//function logout() { 2969// $('#logouta')[0].click() 2970//} 2971 2972//var messagesAlreadySended = []; 2973//receive messsages and if interval 0 show them in the bottom part or alert if interval > 0 2974function getMessagesCallback(data, compId, allIds) { 2975 var winId = compId; 2976 if (allIds && allIds.length > 0) { 2977 winId = allIds[0].Id; 2978 } 2979 2980 var messagesArray = []; 2981 for (var i = 0; i < data.length; i++) { 2982 if (data[i].IntervalDB > 0) { 2983 messagesArray.push({ id: data[i].Id, text: data[i].MessageText }); 2984 } 2985 } 2986 2987 if (messagesArray.length > 0) 2988 showInstantMessages(messagesArray, winId); 2989 2990 if (allIds) { 2991 for (var j = 0; j < allIds.length; j++) { 2992 winId = allIds[j].Id; 2993 var text = ""; 2994 let i = 0; 2995 for ( i = 0; i < data.length; i++) { 2996 if (data[i].IntervalDB == 0) { 2997 if (data[i].MessageText == "LOGOUT_USER") { 2998 setTimeout("logout()", parseInt(timeOutUntilLogout) * 60 * 1000); 2999 confirmPrompt(logoutMessageText, function () { });
3000 ajaxCall((isIframeApp ? "/" : "") + 'Desktop/ConfirmMessage/' + data[i].Id + "?onlyLastSendDate=false", null, confirmMessageCallback); 3001 } 3002 else 3003 if (data[i].MessageText == "RELOAD_START_MENU") { 3004 getStartMenu(); 3005 ajaxCall((isIframeApp ? "/" : "") + 'Desktop/ConfirmMessage/' + data[i].Id + "?onlyLastSendDate=false", null, confirmMessageCallback); 3006 } 3007 else { 3008 if (text.length > 0) { 3009 text += '</br>' + data[i].MessageText; 3010 } 3011 else { 3012 text += data[i].MessageText; 3013 } 3014 } 3015 } 3016 } 3017 3018 appendMesagesDiv(winId, text); 3019 } 3020 } 3021} 3022 3023//alert from messages 3024function showInstantMessages(messagesArray, componentId) { 3025 var yes = function () { 3026 ajaxCall((isIframeApp ? "/" : "") + 'Desktop/ConfirmMessage/' + messagesArray[0].id + "?onlyLastSendDate=false", null, confirmMessageCallback); 3027 messagesArray.splice(0, 1); 3028 if (messagesArray.length > 0) { 3029 showInstantMessages(messagesArray); 3030 } 3031 }; 3032 3033 var noEmpty = function () { 3034 messagesArray.splice(0, 1); 3035 if (messagesArray.length > 0) { 3036 showInstantMessages(messagesArray); 3037 } 3038 }; 3039 3040 var no = function () { 3041 ajaxCall((isIframeApp ? "/" : "") + 'Desktop/ConfirmMessage/' + messagesArray[0].id + "?onlyLastSendDate=true", null, confirmMessageCallback); 3042 messagesArray.splice(0, 1); 3043 if (messagesArray.length > 0) { 3044 showInstantMessages(messagesArray); 3045 } 3046 }; 3047 if (!desktopInitilizing) { 3048 ajaxCall((isIframeApp ? "/" : "") + 'Desktop/ConfirmMessage/' + messagesArray[0].id + "?onlyLastSendDate=true", null, confirmMessageCallback); 3049 confirmPrompt(messagesArray[0].text, yes, noEmpty); 3050 } 3051 else 3052 if (componentId == null) { 3053 confirmPrompt(messagesArray[0].text, yes, no); 3054 } 3055} 3056 3057function confirmMessageCallback(data) { 3058 log("Message confirmed successfully"); 3059} 3060 3061var initialExportButtonTitle = ''; 3062function changeExportButton(btnClass, setCancel) { 3063 $('.' + btnClass).removeClass('cancelExportGrid'); 3064 $('.' + btnClass).attr('title', initialExportButtonTitle); 3065 if (setCancel) { 3066 $('.' + btnClass).attr('title', cancelDownloadText); 3067 $('.' + btnClass).addClass('cancelExportGrid'); 3068 } 3069} 3070 3071//export data (for now only in sms) 3072function exportData(urlSession, url, gridName, btnExportClass) { 3073 var obj = null; 3074 if (getFilterObjForSession) 3075 obj = getFilterObjForSession(gridName); 3076 if (showDownloadStartMessage) { 3077 confirmPrompt(downloadStartedtext, function () { });
3078 } 3079 3080 //send information on server and store in SESSION 3081 ajaxCall(urlSession, JSON.stringify(obj), exportDataCallback, url, gridName, btnExportClass); 3082} 3083 3084function exportDataCallback(data, url, gridName, btnExportClass) { 3085 var obj = null; 3086 3087 var download = function () { 3088 if (btnExportClass) { 3089 initialExportButtonTitle = $('.' + btnExportClass).attr('title'); 3090 changeExportButton(btnExportClass, true); 3091 } 3092 $.fileDownload(url, 3093 { 3094 successCallback: function () { 3095 if (showDownloadEndMessage) { 3096 confirmPrompt(downloadFinishtext, function () { }); 3097 } 3098 if (btnExportClass) { 3099 changeExportButton(btnExportClass, false); 3100 } 3101 }, 3102 failCallback: function () { 3103 if (downloadCancelByUser) { 3104 downloadCancelByUser = null; 3105 confirmPrompt(downloadStoppedtext, function () { });
3106 } 3107 else { 3108 confirmPrompt(downloadFailedtext, function () { }); 3109 } 3110 3111 if (btnExportClass) { 3112 changeExportButton(btnExportClass, false); 3113 } 3114 }, 3115 httpMethod: "GET", 3116 data: obj 3117 } 3118 ); 3119 }; 3120 3121 //if (url.indexOf("PDFExportFormatter") > 0 && obj.verifyMaxColumns) { 3122 // var columns = obj.columnNames.split("~"); 3123 // if (columns.length > maxColumnsInExport) 3124 // confirmPrompt(exportMultipleColumns, download, null); 3125 // else 3126 // download(); 3127 //} 3128 //else 3129 download(); 3130} 3131 3132function exportDataReport(url, getObj) { 3133 var obj = null; 3134 if (getObj) 3135 obj = getObj(); 3136 var download = function () { 3137 $.fileDownload(url, 3138 { 3139 successCallback: function () { 3140 confirmPrompt(downloadFinishtext, function () { });
3141 }, 3142 failCallback: function () { 3143 confirmPrompt(downloadFailedtext, function () { }); 3144 }, 3145 httpMethod: "GET", 3146 data: obj 3147 } 3148 ); 3149 }; 3150 download(); 3151 3152} 3153 3154function exportDataReportCallback(data) { 3155 log("data exported with report succesfully"); 3156} 3157 3158function DateFmt(fstr) { 3159 this.formatString = fstr; 3160 3161 var mthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; 3162 var dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; 3163 var zeroPad = function (number) { 3164 return ("0" + number).substr(-2, 2); 3165 }; 3166 3167 var dateMarkers = { 3168 d: ['getDate', function(v) { return zeroPad(v); }], 3169 m: ['getMonth', function(v) { return zeroPad(v + 1); }], 3170 n: ['getMonth', function (v) { return mthNames[v]; }], 3171 w: ['getDay', function (v) { return dayNames[v]; }], 3172 y: ['getFullYear'], 3173 H: ['getHours', function(v) { return zeroPad(v); }], 3174 M: ['getMinutes', function(v) { return zeroPad(v); }], 3175 S: ['getSeconds', function(v) { return zeroPad(v); }], 3176 i: ['toISOString'] 3177 }; 3178 3179 this.format = function (date) { 3180 var dateTxt = this.formatString.replace(/%(.)/g, function (m, p) { 3181 var rv = date[dateMarkers[p][0]](); 3182 3183 if (dateMarkers[p][1] != null){ 3184 rv = dateMarkers[p][1](rv); 3185 } 3186 return rv; 3187 3188 }); 3189 return dateTxt; 3190 }; 3191} 3192 3193function dateTimePicker(control) { 3194 $(control).kendoDateTimePicker({ 3195 format: "dd/MM/yyyy HH:mm:ss", 3196 timeFormat: "HH:mm:ss" 3197 }); 3198} 3199 3200function timePicker(control) { 3201 $(control).kendoTimePicker({ 3202 format: "HH:mm:ss", 3203 type: "time" 3204 }); 3205} 3206 3207 3208//do not delete the following function 3209function emptyFilter() { 3210 return { filterId: "" }; 3211} 3212 3213// formatiert aktuelles Datum + Zeit für Rapid-Interface 3214function getFormattedDate(date) { 3215 date = date || new Date(); 3216 3217 let year = date.getFullYear(); 3218 let month = formatDateNumber(date.getMonth() + 1); 3219 let day = formatDateNumber(date.getDate()); 3220 3221 let hours = formatDateNumber(date.getHours() + 1); 3222 let min = formatDateNumber(date.getMinutes()); 3223 let sec = formatDateNumber(date.getSeconds()); 3224 3225 return year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + sec; 3226} 3227 3228function formatDateNumber(number) { 3229 if (!number && number !== 0) { 3230 return ''; 3231 } 3232 3233 let str = number; 3234 if (typeof number === 'number') { 3235 str = number.toString(); 3236 } 3237 3238 while (str.length < 2) { 3239 str = '0' + str; 3240 } 3241 3242 return str; 3243} 3244 3245/** 3246 * @param {number} val Number to be rounded. 3247 * @param {number} fracDig Number of fractional digits after rounding. 3248 * @return {number} The rounded number, with fracDig fractional digits 3249 */ 3250function round(val, fracDig) { 3251 fracDig = fracDig || 0; 3252 if (fracDig === 0) { 3253 return Math.round(val); 3254 } 3255 3256 let pow = Math.pow(10, fracDig); 3257 3258 return Math.round(val * pow) / pow; 3259} 3260 3261// Stringify, das 'circular references' beachtet 3262function saveStringify(o) { 3263 let ret = ''; 3264 if (o) { 3265 let cache = []; 3266 ret = JSON.stringify(o, function(key, value) { 3267 if (typeof value === 'object' && value !== null) { 3268 if (cache.indexOf(value) !== -1) { 3269 // Circular reference found, discard key; 3270 return; 3271 } 3272 // Store value 3273 cache.push(value); 3274 } 3275 return value; 3276 }); 3277 cache = null; 3278 } 3279 return ret; 3280} 3281 3282// TODO bessere art den fehler mitzuteilen 3283function checkForSoapFault(node) { 3284 if (typeof node == 'string') { 3285 node = parseXml(node); 3286 } 3287 3288 if (node) { 3289 let fcarr = node.getElementsByTagName('faultcode'); 3290 let fsarr = node.getElementsByTagName('faultstring'); 3291 3292 if (fcarr.length > 0 && fsarr.length > 0) { 3293 let fc, fs; 3294 if (fcarr[0]) { 3295 fc = fcarr[0].nodeValue || fcarr[0].textContent; 3296 } 3297 3298 if (fsarr[0]) { 3299 fs = fsarr[0].nodeValue || fsarr[0].textContent; 3300 } 3301 3302 if (fs || fc) { 3303 let err = (fc + ' - ' || '') + (fs || 'Fehler im Soap-Request'); 3304 console.log(err); 3305 displayErrorInStatusInfo(err, "Vwc.Panel.Datatable"); 3306 return true; 3307 } 3308 } 3309 } 3310 3311 return false; 3312} 3313 3314function degToRad(angle) { 3315 return angle / 180 * Math.PI; 3316} 3317 3318function radToDeg(rad) { 3319 return rad * 180 / Math.PI; 3320} 3321 3322function getAvailableFonts() { 3323 /** 3324 * JavaScript code to detect available availability of a 3325 * particular font in a browser using JavaScript and CSS. 3326 * 3327 * Author : Lalit Patel 3328 * Website: http://www.lalit.org/lab/javascript-css-font-detect/ 3329 * License: Apache Software License 2.0 3330 * http://www.apache.org/licenses/LICENSE-2.0 3331 * Version: 0.15 (21 Sep 2009) 3332 * Changed comparision font to default from sans-default-default, 3333 * as in FF3.0 font of child element didn't fallback 3334 * to parent element if the font is missing. 3335 * Version: 0.2 (04 Mar 2012) 3336 * Comparing font against all the 3 generic font families ie, 3337 * 'monospace', 'sans-serif' and 'sans'. If it doesn't match all 3 3338 * then that font is 100% not available in the system 3339 * Version: 0.3 (24 Mar 2012) 3340 * Replaced sans with serif in the list of baseFonts 3341 */ 3342 let Detector = function() { 3343 // a font will be compared against all the three default fonts. 3344 // and if it doesn't match all 3 then that font is not available. 3345 let baseFonts = ['monospace', 'sans-serif', 'serif']; 3346 3347 //we use m or w because these two characters take up the maximum width. 3348 // And we use a LLi so that the same matching fonts can get separated 3349 let testString = "mmmmmmmmmmlli"; 3350 3351 //we test using 72px font size, we may use any size. I guess larger the better. 3352 let testSize = '72px'; 3353 3354 let h = document.getElementsByTagName("body")[0]; 3355 3356 // create a SPAN in the document to get the width of the text we use to test 3357 let s = document.createElement("span"); 3358 s.style.fontSize = testSize; 3359 s.innerHTML = testString; 3360 let defaultWidth = {}; 3361 let defaultHeight = {}; 3362 for (let index in baseFonts) { 3363 //get the default width for the three base fonts 3364 s.style.fontFamily = baseFonts[index]; 3365 h.appendChild(s); 3366 defaultWidth[baseFonts[index]] = s.offsetWidth; //width for the default font 3367 defaultHeight[baseFonts[index]] = s.offsetHeight; //height for the defualt font 3368 h.removeChild(s); 3369 } 3370 3371 function detect(font) { 3372 let detected = false; 3373 for (let index in baseFonts) { 3374 s.style.fontFamily = font + ',' + baseFonts[index]; // name of the font along with the base font for fallback. 3375 h.appendChild(s); 3376 let matched = s.offsetWidth != defaultWidth[baseFonts[index]] || s.offsetHeight != defaultHeight[baseFonts[index]]; 3377 h.removeChild(s); 3378 detected = detected || matched; 3379 } 3380 return detected; 3381 } 3382 3383 this.detect = detect; 3384 }; 3385 3386 let ret = []; 3387 // from https://www.w3schools.com/cssref/css_websafe_fonts.asp 3388 let fontFamilies = [ 3389 // serif fonts 3390 'Georgia', 3391 'Palatino Linotype', 3392 'Book Antiqua', 3393 'Palatino', 3394 'Times New Roman', 3395 'Times', 3396 // sans-serif fonts 3397 'Arial', 3398 'Helvetica', 3399 'Arial Black', 3400 'Gadget', 3401 'Comic Sans MS', 3402 'Impact', 3403 'Charcoal', 3404 'Lucida Sans Unicode', 3405 'Lucida Grande', 3406 'Tahoma', 3407 'Geneva', 3408 'Trebuchet MS', 3409 'Verdana', 3410 // monospace fonts 3411 'Courier New', 3412 'Courier', 3413 'Lucida Console', 3414 'Monaco' 3415 ]; 3416 let detector = new Detector(); 3417 for (let i = 0; i < fontFamilies.length; ++i) { 3418 let ff = fontFamilies[i];
3419 let detected = detector.detect(ff); 3420 if (detected) { 3421 ret.push(ff); 3422 } 3423 } 3424 detector = null; 3425 return ret; 3426} 3427 3428function parseXml(obj) { 3429 return new DOMParser().parseFromString(obj, 'application/xml'); 3430} 3431 3432function parseKilometerToStationResponse(xml, hasBlockNr) { 3433 return parseKilometrierungResponse(xml, hasBlockNr ? 'station' : 'stationen'); 3434} 3435 3436function parseKilometrierungResponse(xml, tagName) { 3437 let ret = {}; 3438 if (xml) { 3439 if (typeof xml === 'string') { 3440 xml = parseXml(xml); 3441 } 3442 if (checkForSoapFault(xml)) { 3443 // fehler im soap-request 3444 return null; 3445 } 3446 3447 let elements = xml.getElementsByTagName(tagName); 3448 if (elements && elements.length > 0) { 3449 let stationElement = elements[0]; 3450 if (stationElement && stationElement.hasChildNodes()) { 3451 let children = stationElement.childNodes; 3452 for (let i = 0; i < children.length; ++i) { 3453 let child = children[i]; 3454 let ln = child.localName; 3455 let val = child.nodeValue || child.textContent; 3456 switch (ln) { 3457 case 'VST': 3458 case 'BST': { 3459 if (typeof val === 'string') { 3460 val = Number.parseInt(val); 3461 } 3462 ret.station = val; 3463 break; 3464 } 3465 case 'LEN': { 3466 ret.len = val; 3467 break; 3468 } 3469 case 'vonKartenblatt': { 3470 ret.vonKartenblatt = val; 3471 break; 3472 } 3473 case 'vonNkLfd': { 3474 ret.vonNkLfd = val; 3475 break; 3476 } 3477 case 'vonZusatz': { 3478 ret.vonZusatz = val === 'O' ? '' : val; 3479 break; 3480 } 3481 case 'nachKartenblatt': { 3482 ret.nachKartenblatt = val; 3483 break; 3484 } 3485 case 'nachNkLfd': { 3486 ret.nachNkLfd = val; 3487 break; 3488 } 3489 case 'nachZusatz': { 3490 ret.nachZusatz = val === 'O' ? '' : val; 3491 break; 3492 } 3493 case 'inStatRi': { 3494 ret.inRichtung = val == 'true'; 3495 break; 3496 } 3497 case 'kilometer': { 3498 if (typeof val === 'string') { 3499 val = parseFloat(val); 3500 } 3501 ret.kilometer = val; 3502 } 3503 } 3504 } 3505 } 3506 } 3507 } 3508 ret.vnk = getNk(ret.vonKartenblatt, ret.vonNkLfd, ret.vonZusatz); 3509 ret.nnk = getNk(ret.nachKartenblatt, ret.nachNkLfd, ret.nachZusatz); 3510 3511 return ret; 3512} 3513 3514function parseStationToKilometerResponse(xml) { 3515 let ret = {}; 3516 if (xml) { 3517 if (typeof xml === 'string') { 3518 xml = parseXml(xml); 3519 } 3520 if (checkForSoapFault(xml)) { 3521 // fehler im soap-request 3522 return null; 3523 } 3524 3525 let elements = xml.getElementsByTagName('kilometer'); 3526 if (elements && elements.length > 0) { 3527 let kilometerElement = elements[0]; 3528 ret = kilometerElement.nodeValue || kilometerElement.textContent; 3529 } 3530 } 3531 3532 return ret; 3533} 3534 3535function getNk(kartenblatt, lfd, zusatz) { 3536 kartenblatt = typeof kartenblatt === 'number' ? kartenblatt.toString() : kartenblatt; 3537 lfd = typeof lfd === 'number' ? lfd.toString() : lfd; 3538 zusatz = typeof zusatz === 'number' ? zusatz.toString() : zusatz; 3539 3540 let nk = kartenblatt; 3541 3542 while (lfd.length < 3) { 3543 lfd = '0' + lfd; 3544 } 3545 nk += lfd; 3546 3547 if (zusatz || zusatz == '0') { 3548 nk += zusatz; 3549 } 3550 3551 return nk; 3552} 3553 3554function getPartsFromNk(nk) { 3555 let ret = {}; 3556 3557 ret.kartenblatt = nk.substring(0, 4); 3558 if (ret.kartenblatt) { 3559 ret.kartenblatt = Number.parseInt(ret.kartenblatt); 3560 } 3561 ret.lfd = nk.substring(4, 7); 3562 if (ret.lfd) { 3563 ret.lfd = Number.parseInt(ret.lfd); 3564 } 3565 ret.zusatz = nk.substring(7, 8); 3566 3567 return ret; 3568} 3569 3570function enterWaitState() { 3571 Vwc.temp.cursor = $('html, body').css('cursor'); 3572 $('html, body').css('cursor', 'wait'); 3573} 3574 3575function leaveWaitState() { 3576 $('html, body').css('cursor', Vwc.temp.cursor || 'default'); 3577};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.