Changeset 223 for trunk/demo/public
- Timestamp:
- 08/26/07 19:29:18 (1 year ago)
- Files:
-
- trunk/demo/public/javascripts/controls.js (modified) (12 diffs)
- trunk/demo/public/javascripts/dragdrop.js (modified) (14 diffs)
- trunk/demo/public/javascripts/effects.js (modified) (19 diffs)
- trunk/demo/public/javascripts/prototype.js (modified) (52 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/public/javascripts/controls.js
r169 r223 1 // Copyright (c) 2005 , 2006Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)2 // (c) 2005 , 2006Ivan Krstic (http://blogs.law.harvard.edu/ivan)3 // (c) 2005 , 2006Jon Tirsen (http://www.tirsen.com)1 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 2 // (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan) 3 // (c) 2005-2007 Jon Tirsen (http://www.tirsen.com) 4 4 // Contributors: 5 5 // Richard Livsey … … 42 42 Autocompleter.Base.prototype = { 43 43 baseInitialize: function(element, update, options) { 44 this.element = $(element); 44 element = $(element) 45 this.element = element; 45 46 this.update = $(update); 46 47 this.hasFocus = false; … … 82 83 Element.hide(this.update); 83 84 84 Event.observe(this.element, "blur", this.onBlur.bindAsEventListener(this)); 85 Event.observe(this.element, "keypress", this.onKeyPress.bindAsEventListener(this)); 85 Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this)); 86 Event.observe(this.element, 'keypress', this.onKeyPress.bindAsEventListener(this)); 87 88 // Turn autocomplete back on when the user leaves the page, so that the 89 // field's value will be remembered on Mozilla-based browsers. 90 Event.observe(window, 'beforeunload', function(){ 91 element.setAttribute('autocomplete', 'on'); 92 }); 86 93 }, 87 94 … … 89 96 if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update); 90 97 if(!this.iefix && 91 (navigator.appVersion.indexOf('MSIE')>0) && 92 (navigator.userAgent.indexOf('Opera')<0) && 98 (Prototype.Browser.IE) && 93 99 (Element.getStyle(this.update, 'position')=='absolute')) { 94 100 new Insertion.After(this.update, … … 140 146 this.markPrevious(); 141 147 this.render(); 142 if( navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);148 if(Prototype.Browser.WebKit) Event.stop(event); 143 149 return; 144 150 case Event.KEY_DOWN: 145 151 this.markNext(); 146 152 this.render(); 147 if( navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);153 if(Prototype.Browser.WebKit) Event.stop(event); 148 154 return; 149 155 } 150 156 else 151 157 if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN || 152 ( navigator.appVersion.indexOf('AppleWebKit')> 0 && event.keyCode == 0)) return;158 (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return; 153 159 154 160 this.changed = true; … … 196 202 Element.addClassName(this.getEntry(i),"selected") : 197 203 Element.removeClassName(this.getEntry(i),"selected"); 198 199 204 if(this.hasFocus) { 200 205 this.show(); … … 298 303 this.changed = false; 299 304 if(this.getToken().length>=this.options.minChars) { 300 this.startIndicator();301 305 this.getUpdatedChoices(); 302 306 } else { … … 339 343 340 344 getUpdatedChoices: function() { 341 entry = encodeURIComponent(this.options.paramName) + '=' + 345 this.startIndicator(); 346 347 var entry = encodeURIComponent(this.options.paramName) + '=' + 342 348 encodeURIComponent(this.getToken()); 343 349 … … 347 353 if(this.options.defaultParams) 348 354 this.options.parameters += '&' + this.options.defaultParams; 349 355 350 356 new Ajax.Request(this.url, this.options); 351 357 }, … … 476 482 paramName: "value", 477 483 okButton: true, 484 okLink: false, 478 485 okText: "ok", 486 cancelButton: false, 479 487 cancelLink: true, 480 488 cancelText: "cancel", 489 textBeforeControls: '', 490 textBetweenControls: '', 491 textAfterControls: '', 481 492 savingText: "Saving...", 482 493 clickToEditText: "Click to edit", … … 566 577 this.form.appendChild(br); 567 578 } 579 580 if (this.options.textBeforeControls) 581 this.form.appendChild(document.createTextNode(this.options.textBeforeControls)); 568 582 569 583 if (this.options.okButton) { 570 okButton = document.createElement("input");584 var okButton = document.createElement("input"); 571 585 okButton.type = "submit"; 572 586 okButton.value = this.options.okText; … … 574 588 this.form.appendChild(okButton); 575 589 } 590 591 if (this.options.okLink) { 592 var okLink = document.createElement("a"); 593 okLink.href = "#"; 594 okLink.appendChild(document.createTextNode(this.options.okText)); 595 okLink.onclick = this.onSubmit.bind(this); 596 okLink.className = 'editor_ok_link'; 597 this.form.appendChild(okLink); 598 } 599 600 if (this.options.textBetweenControls && 601 (this.options.okLink || this.options.okButton) && 602 (this.options.cancelLink || this.options.cancelButton)) 603 this.form.appendChild(document.createTextNode(this.options.textBetweenControls)); 604 605 if (this.options.cancelButton) { 606 var cancelButton = document.createElement("input"); 607 cancelButton.type = "submit"; 608 cancelButton.value = this.options.cancelText; 609 cancelButton.onclick = this.onclickCancel.bind(this); 610 cancelButton.className = 'editor_cancel_button'; 611 this.form.appendChild(cancelButton); 612 } 576 613 577 614 if (this.options.cancelLink) { 578 cancelLink = document.createElement("a");615 var cancelLink = document.createElement("a"); 579 616 cancelLink.href = "#"; 580 617 cancelLink.appendChild(document.createTextNode(this.options.cancelText)); 581 618 cancelLink.onclick = this.onclickCancel.bind(this); 582 cancelLink.className = 'editor_cancel ';619 cancelLink.className = 'editor_cancel editor_cancel_link'; 583 620 this.form.appendChild(cancelLink); 584 621 } 622 623 if (this.options.textAfterControls) 624 this.form.appendChild(document.createTextNode(this.options.textAfterControls)); 585 625 }, 586 626 hasHTMLLineBreaks: function(string) { trunk/demo/public/javascripts/dragdrop.js
r169 r223 1 // Copyright (c) 2005 , 2006Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)2 // (c) 2005 , 2006Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)1 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 2 // (c) 2005-2007 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz) 3 3 // 4 4 // script.aculo.us is freely distributable under the terms of an MIT-style license. … … 111 111 112 112 if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active)) 113 if (this.last_active.onDrop) 114 this.last_active.onDrop(element, this.last_active.element, event); 113 if (this.last_active.onDrop) { 114 this.last_active.onDrop(element, this.last_active.element, event); 115 return true; 116 } 115 117 }, 116 118 … … 244 246 zindex: 1000, 245 247 revert: false, 248 quiet: false, 246 249 scroll: false, 247 250 scrollSensitivity: 20, … … 304 307 // abort on form elements, fixes a Firefox issue 305 308 var src = Event.element(event); 306 if( src.tagName&& (307 src.tagName=='INPUT' ||308 src.tagName=='SELECT' ||309 src.tagName=='OPTION' ||310 src.tagName=='BUTTON' ||311 src.tagName=='TEXTAREA')) return;309 if((tag_name = src.tagName.toUpperCase()) && ( 310 tag_name=='INPUT' || 311 tag_name=='SELECT' || 312 tag_name=='OPTION' || 313 tag_name=='BUTTON' || 314 tag_name=='TEXTAREA')) return; 312 315 313 316 var pointer = [Event.pointerX(event), Event.pointerY(event)]; … … 352 355 updateDrag: function(event, pointer) { 353 356 if(!this.dragging) this.startDrag(event); 354 Position.prepare(); 355 Droppables.show(pointer, this.element); 357 358 if(!this.options.quiet){ 359 Position.prepare(); 360 Droppables.show(pointer, this.element); 361 } 362 356 363 Draggables.notify('onDrag', this, event); 357 364 … … 381 388 382 389 // fix AppleWebKit rendering 383 if( navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);390 if(Prototype.Browser.WebKit) window.scrollBy(0,0); 384 391 385 392 Event.stop(event); … … 388 395 finishDrag: function(event, success) { 389 396 this.dragging = false; 397 398 if(this.options.quiet){ 399 Position.prepare(); 400 var pointer = [Event.pointerX(event), Event.pointerY(event)]; 401 Droppables.show(pointer, this.element); 402 } 390 403 391 404 if(this.options.ghosting) { … … 395 408 } 396 409 397 if(success) Droppables.fire(event, this.element); 410 var dropped = false; 411 if(success) { 412 dropped = Droppables.fire(event, this.element); 413 if (!dropped) dropped = false; 414 } 415 if(dropped && this.options.onDropped) this.options.onDropped(this.element); 398 416 Draggables.notify('onEnd', this, event); 399 417 … … 403 421 var d = this.currentDelta(); 404 422 if(revert && this.options.reverteffect) { 405 this.options.reverteffect(this.element, 406 d[1]-this.delta[1], d[0]-this.delta[0]); 423 if (dropped == 0 || revert != 'failure') 424 this.options.reverteffect(this.element, 425 d[1]-this.delta[1], d[0]-this.delta[0]); 407 426 } else { 408 427 this.delta = d; … … 573 592 574 593 _findRootElement: function(element) { 575 while (element.tagName != "BODY") {594 while (element.tagName.toUpperCase() != "BODY") { 576 595 if(element.id && Sortable.sortables[element.id]) return element; 577 596 element = element.parentNode; … … 613 632 hoverclass: null, 614 633 ghosting: false, 634 quiet: false, 615 635 scroll: false, 616 636 scrollSensitivity: 20, 617 637 scrollSpeed: 15, 618 638 format: this.SERIALIZE_RULE, 639 640 // these take arrays of elements or ids and can be 641 // used for better initialization performance 642 elements: false, 643 handles: false, 644 619 645 onChange: Prototype.emptyFunction, 620 646 onUpdate: Prototype.emptyFunction … … 627 653 var options_for_draggable = { 628 654 revert: true, 655 quiet: options.quiet, 629 656 scroll: options.scroll, 630 657 scrollSpeed: options.scrollSpeed, … … 680 707 } 681 708 682 (this.findElements(element, options) || []).each( function(e) { 683 // handles are per-draggable 684 var handle = options.handle ? 685 $(e).down('.'+options.handle,0) : e; 709 (options.elements || this.findElements(element, options) || []).each( function(e,i) { 710 var handle = options.handles ? $(options.handles[i]) : 711 (options.handle ? $(e).getElementsByClassName(options.handle)[0] : e); 686 712 options.draggables.push( 687 713 new Draggable(e, Object.extend(options_for_draggable, { handle: handle }))); … … 920 946 } 921 947 922 Element.findChildren = function(element, only, recursive, tagName) { 948 Element.findChildren = function(element, only, recursive, tagName) { 923 949 if(!element.hasChildNodes()) return null; 924 950 tagName = tagName.toUpperCase(); trunk/demo/public/javascripts/effects.js
r169 r223 1 // Copyright (c) 2005 , 2006Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)1 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 2 2 // Contributors: 3 3 // Justin Palmer (http://encytemedia.com/) … … 44 44 element = $(element); 45 45 element.setStyle({fontSize: (percent/100) + 'em'}); 46 if( navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);46 if(Prototype.Browser.WebKit) window.scrollBy(0,0); 47 47 return element; 48 48 } 49 49 50 Element.getOpacity = function(element){ 51 element = $(element); 52 var opacity; 53 if (opacity = element.getStyle('opacity')) 54 return parseFloat(opacity); 55 if (opacity = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/)) 56 if(opacity[1]) return parseFloat(opacity[1]) / 100; 57 return 1.0; 58 } 59 60 Element.setOpacity = function(element, value){ 61 element= $(element); 62 if (value == 1){ 63 element.setStyle({ opacity: 64 (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 65 0.999999 : 1.0 }); 66 if(/MSIE/.test(navigator.userAgent) && !window.opera) 67 element.setStyle({filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')}); 68 } else { 69 if(value < 0.00001) value = 0; 70 element.setStyle({opacity: value}); 71 if(/MSIE/.test(navigator.userAgent) && !window.opera) 72 element.setStyle( 73 { filter: element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'') + 74 'alpha(opacity='+value*100+')' }); 75 } 76 return element; 77 } 78 79 Element.getInlineOpacity = function(element){ 50 Element.getInlineOpacity = function(element){ 80 51 return $(element).style.opacity || ''; 81 } 52 } 82 53 83 54 Element.forceRerendering = function(element) { … … 109 80 110 81 var tagifyStyle = 'position:relative'; 111 if( /MSIE/.test(navigator.userAgent) && !window.opera) tagifyStyle += ';zoom:1';82 if(Prototype.Browser.IE) tagifyStyle += ';zoom:1'; 112 83 113 84 element = $(element); … … 172 143 }, 173 144 flicker: function(pos) { 174 return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4; 145 var pos = ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4; 146 return (pos > 1 ? 1 : pos); 175 147 }, 176 148 wobble: function(pos) { … … 199 171 initialize: function() { 200 172 this.effects = []; 201 this.interval = null; 173 this.interval = null; 202 174 }, 203 175 _each: function(iterator) { … … 233 205 this.effects.push(effect); 234 206 235 if(!this.interval) 236 this.interval = setInterval(this.loop.bind(this), 40);207 if(!this.interval) 208 this.interval = setInterval(this.loop.bind(this), 15); 237 209 }, 238 210 remove: function(effect) { … … 245 217 loop: function() { 246 218 var timePos = new Date().getTime(); 247 this.effects.invoke('loop', timePos); 219 for(var i=0, len=this.effects.length;i<len;i++) 220 this.effects[i] && this.effects[i].loop(timePos); 248 221 } 249 222 }); … … 265 238 transition: Effect.Transitions.sinoidal, 266 239 duration: 1.0, // seconds 267 fps: 25.0, // max. 25fps due to Effect.Queue implementation240 fps: 100, // 100= assume 66fps max. 268 241 sync: false, // true for combining 269 242 from: 0.0, … … 277 250 position: null, 278 251 start: function(options) { 252 function codeForEvent(options,eventName){ 253 return ( 254 (options[eventName+'Internal'] ? 'this.options.'+eventName+'Internal(this);' : '') + 255 (options[eventName] ? 'this.options.'+eventName+'(this);' : '') 256 ); 257 } 258 if(options.transition === false) options.transition = Effect.Transitions.linear; 279 259 this.options = Object.extend(Object.extend({},Effect.DefaultOptions), options || {}); 280 260 this.currentFrame = 0; 281 261 this.state = 'idle'; 282 262 this.startOn = this.options.delay*1000; 283 this.finishOn = this.startOn + (this.options.duration*1000); 263 this.finishOn = this.startOn+(this.options.duration*1000); 264 this.fromToDelta = this.options.to-this.options.from; 265 this.totalTime = this.finishOn-this.startOn; 266 this.totalFrames = this.options.fps*this.options.duration; 267 268 eval('this.render = function(pos){ '+ 269 'if(this.state=="idle"){this.state="running";'+ 270 codeForEvent(options,'beforeSetup')+ 271 (this.setup ? 'this.setup();':'')+ 272 codeForEvent(options,'afterSetup')+ 273 '};if(this.state=="running"){'+ 274 'pos=this.options.transition(pos)*'+this.fromToDelta+'+'+this.options.from+';'+ 275 'this.position=pos;'+ 276 codeForEvent(options,'beforeUpdate')+ 277 (this.update ? 'this.update(pos);':'')+ 278 codeForEvent(options,'afterUpdate')+ 279 '}}'); 280 284 281 this.event('beforeStart'); 285 282 if(!this.options.sync) … … 297 294 return; 298 295 } 299 var pos = (timePos - this.startOn) / (this.finishOn - this.startOn);300 var frame = Math.round(pos * this.options.fps * this.options.duration);296 var pos = (timePos - this.startOn) / this.totalTime, 297 frame = Math.round(pos * this.totalFrames); 301 298 if(frame > this.currentFrame) { 302 299 this.render(pos); 303 300 this.currentFrame = frame; 304 301 } 305 }306 },307 render: function(pos) {308 if(this.state == 'idle') {309 this.state = 'running';310 this.event('beforeSetup');311 if(this.setup) this.setup();312 this.event('afterSetup');313 }314 if(this.state == 'running') {315 if(this.options.transition) pos = this.options.transition(pos);316 pos *= (this.options.to-this.options.from);317 pos += this.options.from;318 this.position = pos;319 this.event('beforeUpdate');320 if(this.update) this.update(pos);321 this.event('afterUpdate');322 302 } 323 303 }, … … 333 313 }, 334 314 inspect: function() { 335 return '#<Effect:' + $H(this).inspect() + ',options:' + $H(this.options).inspect() + '>'; 315 var data = $H(); 316 for(property in this) 317 if(typeof this[property] != 'function') data[property] = this[property]; 318 return '#<Effect:' + data.inspect() + ',options:' + $H(this.options).inspect() + '>'; 336 319 } 337 320 } … … 374 357 if(!this.element) throw(Effect._elementDoesNotExistError); 375 358 // make this work on IE on elements without 'layout' 376 if( /MSIE/.test(navigator.userAgent) && !window.opera&& (!this.element.currentStyle.hasLayout))359 if(Prototype.Browser.IE && (!this.element.currentStyle.hasLayout)) 377 360 this.element.setStyle({zoom: 1}); 378 361 var options = Object.extend({ … … 514 497 if(this.element.getStyle('display')=='none') { this.cancel(); return; } 515 498 // Disable background image during the effect 516 this.oldStyle = { 517 backgroundImage: this.element.getStyle('background-image') }; 518 this.element.setStyle({backgroundImage: 'none'}); 499 this.oldStyle = {}; 500 if (!this.options.keepBackgroundImage) { 501 this.oldStyle.backgroundImage = this.element.getStyle('background-image'); 502 this.element.setStyle({backgroundImage: 'none'}); 503 } 519 504 if(!this.options.endcolor) 520 505 this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff'); … … 946 931 if(!this.element) throw(Effect._elementDoesNotExistError); 947 932 var options = Object.extend({ 948 style: ''933 style: {} 949 934 }, arguments[1] || {}); 935 if (typeof options.style == 'string') { 936 if(options.style.indexOf(':') == -1) { 937 var cssText = '', selector = '.' + options.style; 938 $A(document.styleSheets).reverse().each(function(styleSheet) { 939 if (styleSheet.cssRules) cssRules = styleSheet.cssRules; 940 else if (styleSheet.rules) cssRules = styleSheet.rules; 941 $A(cssRules).reverse().each(function(rule) { 942 if (selector == rule.selectorText) { 943 cssText = rule.style.cssText; 944 throw $break; 945 } 946 }); 947 if (cssText) throw $break; 948 }); 949 this.style = cssText.parseStyle(); 950 options.afterFinishInternal = function(effect){ 951 effect.element.addClassName(effect.options.style); 952 effect.transforms.each(function(transform) { 953 if(transform.style != 'opacity') 954 effect.element.style[transform.style] = ''; 955 }); 956 } 957 } else this.style = options.style.parseStyle(); 958 } else this.style = $H(options.style) 950 959 this.start(options); 951 960 }, … … 958 967 }); 959 968 } 960 this.transforms = this.options.style.parseStyle().map(function(property){ 961 var originalValue = this.element.getStyle(property[0]); 962 return $H({ 963 style: property[0], 964 originalValue: property[1].unit=='color' ? 965 parseColor(originalValue) : parseFloat(originalValue || 0), 966 targetValue: property[1].unit=='color' ? 967 parseColor(property[1].value) : property[1].value, 968 unit: property[1].unit 969 }); 969 this.transforms = this.style.map(function(pair){ 970 var property = pair[0], value = pair[1], unit = null; 971 972 if(value.parseColor('#zzzzzz') != '#zzzzzz') { 973 value = value.parseColor(); 974 unit = 'color'; 975 } else if(property == 'opacity') { 976 value = parseFloat(value); 977 if(Prototype.Browser.IE && (!this.element.currentStyle.hasLayout)) 978 this.element.setStyle({zoom: 1}); 979 } else if(Element.CSS_LENGTH.test(value)) { 980 var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/); 981 value = parseFloat(components[1]); 982 unit = (components.length == 3) ? components[2] : null; 983 } 984 985 var originalValue = this.element.getStyle(property); 986 return { 987 style: property.camelize(), 988 originalValue: unit=='color' ? parseColor(originalValue) : parseFloat(originalValue || 0), 989 targetValue: unit=='color' ? parseColor(value) : value, 990 unit: unit 991 }; 970 992 }.bind(this)).reject(function(transform){ 971 993 return ( … … 979 1001 }, 980 1002 update: function(position) { 981 var style = $H(), value = null; 982 this.transforms.each(function(transform){ 983 value = transform.unit=='color' ? 984 $R(0,2).inject('#',function(m,v,i){ 985 return m+(Math.round(transform.originalValue[i]+ 986 (transform.targetValue[i] - transform.originalValue[i])*position)).toColorPart() }) : 1003 var style = {}, transform, i = this.transforms.length; 1004 while(i--) 1005 style[(transform = this.transforms[i]).style] = 1006 transform.unit=='color' ? '#'+ 1007 (Math.round(transform.originalValue[0]+ 1008 (transform.targetValue[0]-transform.originalValue[0])*position)).toColorPart() + 1009 (Math.round(transform.originalValue[1]+ 1010 (transform.targetValue[1]-transform.originalValue[1])*position)).toColorPart() + 1011 (Math.round(transform.originalValue[2]+ 1012 (transform.targetValue[2]-transform.originalValue[2])*position)).toColorPart() : 987 1013 transform.originalValue + Math.round( 988 1014 ((transform.targetValue - transform.originalValue) * position) * 1000)/1000 + transform.unit; 989 style[transform.style] = value; 990 }); 991 this.element.setStyle(style); 1015 this.element.setStyle(style, true); 992 1016 } 993 1017 }); … … 1022 1046 }); 1023 1047 1024 Element.CSS_PROPERTIES = ['azimuth', 'backgroundAttachment', 'backgroundColor', 'backgroundImage', 1025 'backgroundPosition', 'backgroundRepeat', 'borderBottomColor', 'borderBottomStyle', 1026 'borderBottomWidth', 'borderCollapse', 'borderLeftColor', 'borderLeftStyle', 'borderLeftWidth', 1027 'borderRightColor', 'borderRightStyle', 'borderRightWidth', 'borderSpacing', 'borderTopColor', 1028 'borderTopStyle', 'borderTopWidth', 'bottom', 'captionSide', 'clear', 'clip', 'color', 'content', 1029 'counterIncrement', 'counterReset', 'cssFloat', 'cueAfter', 'cueBefore', 'cursor', 'direction', 1030 'display', 'elevation', 'emptyCells', 'fontFamily', 'fontSize', 'fontSizeAdjust', 'fontStretch', 1031 'fontStyle', 'fontVariant', 'fontWeight', 'height', 'left', 'letterSpacing', 'lineHeight', 1032 'listStyleImage', 'listStylePosition', 'listStyleType', 'marginBottom', 'marginLeft', 'marginRight', 1033 'marginTop', 'markerOffset', 'marks', 'maxHeight', 'maxWidth', 'minHeight', 'minWidth', 'opacity', 1034 'orphans', 'outlineColor', 'outlineOffset', 'outlineStyle', 'outlineWidth', 'overflowX', 'overflowY', 1035 'paddingBottom', 'paddingLeft', 'paddingRight', 'paddingTop', 'page', 'pageBreakAfter', 'pageBreakBefore', 1036 'pageBreakInside', 'pauseAfter', 'pauseBefore', 'pitch', 'pitchRange', 'position', 'quotes', 1037 'richness', 'right', 'size', 'speakHeader', 'speakNumeral', 'speakPunctuation', 'speechRate', 'stress', 1038 'tableLayout', 'textAlign', 'textDecoration', 'textIndent', 'textShadow', 'textTransform', 'top', 1039 'unicodeBidi', 'verticalAlign', 'visibility', 'voiceFamily', 'volume', 'whiteSpace', 'widows', 1040 'width', 'wordSpacing', 'zIndex']; 1048 Element.CSS_PROPERTIES = $w( 1049 'backgroundColor backgroundPosition borderBottomColor borderBottomStyle ' + 1050 'borderBottomWidth borderLeftColor borderLeftStyle borderLeftWidth ' + 1051 'borderRightColor borderRightStyle borderRightWidth borderSpacing ' + 1052 'borderTopColor borderTopStyle borderTopWidth bottom clip color ' + 1053 'fontSize fontWeight height left letterSpacing lineHeight ' + 1054 'marginBottom marginLeft marginRight marginTop markerOffset maxHeight '+ 1055 'maxWidth minHeight minWidth opacity outlineColor outlineOffset ' + 1056 'outlineWidth paddingBottom paddingLeft paddingRight paddingTop ' + 1057 'right textIndent top width wordSpacing zIndex'); 1041 1058 1042 1059 Element.CSS_LENGTH = /^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/; 1043 1060 1044 1061 String.prototype.parseStyle = function(){ 1045 var element = Element.extend(document.createElement('div'));1062 var element = document.createElement('div'); 1046 1063 element.innerHTML = '<div style="' + this + '"></div>'; 1047 var style = element. down().style, styleRules = $H();1064 var style = element.childNodes[0].style, styleRules = $H(); 1048 1065 1049 1066 Element.CSS_PROPERTIES.each(function(property){ 1050 if(style[property]) styleRules[property] = style[property];1067 if(style[property]) styleRules[property] = style[property]; 1051 1068 }); 1052 1053 var result = $H(); 1054 1055 styleRules.each(function(pair){ 1056 var property = pair[0], value = pair[1], unit = null; 1057 1058 if(value.parseColor('#zzzzzz') != '#zzzzzz') { 1059 value = value.parseColor(); 1060 unit = 'color'; 1061 } else if(Element.CSS_LENGTH.test(value)) 1062 var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/), 1063 value = parseFloat(components[1]), unit = (components.length == 3) ? components[2] : null; 1064 1065 result[property.underscore().dasherize()] = $H({ value:value, unit:unit }); 1066 }.bind(this)); 1067 1068 return result; 1069 if(Prototype.Browser.IE && this.indexOf('opacity') > -1) { 1070 styleRules.opacity = this.match(/opacity:\s*((?:0|1)?(?:\.\d*)?)/)[1]; 1071 } 1072 return styleRules; 1069 1073 }; 1070 1074 … … 1074 1078 }; 1075 1079 1076 [' setOpacity','getOpacity','getInlineOpacity','forceRerendering','setContentZoom',1080 ['getInlineOpacity','forceRerendering','setContentZoom', 1077 1081 'collectTextNodes','collectTextNodesIgnoreClass','morph'].each( 1078 1082 function(f) { Element.Methods[f] = Element[f]; } … … 1080 1084 1081 1085 Element.Methods.visualEffect = function(element, effect, options) { 1082 s = effect. gsub(/_/, '-').camelize();1086 s = effect.dasherize().camelize(); 1083 1087 effect_class = s.charAt(0).toUpperCase() + s.substring(1); 1084 1088 new Effect[effect_class](element, options); trunk/demo/public/javascripts/prototype.js
r169 r223 1 /* Prototype JavaScript framework, version 1.5. 01 /* Prototype JavaScript framework, version 1.5.1 2 2 * (c) 2005-2007 Sam Stephenson 3 3 * 4 4 * Prototype is freely distributable under the terms of an MIT-style license. 5 * For details, see the Prototype web site: http:// prototype.conio.net/5 * For details, see the Prototype web site: http://www.prototypejs.org/ 6 6 * 7 7 /*--------------------------------------------------------------------------*/ 8 8 9 9 var Prototype = { 10 Version: '1.5.0', 10 Version: '1.5.1', 11 12 Browser: { 13 IE: !!(window.attachEvent && !window.opera), 14 Opera: !!window.opera, 15 WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1, 16 Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1 17 }, 18 11 19 BrowserFeatures: { 12 XPath: !!document.evaluate 13 }, 14 15 ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)', 16 emptyFunction: function() {}, 20 XPath: !!document.evaluate, 21 ElementExtensions: !!window.HTMLElement, 22 SpecificElementExtensions: 23 (document.createElement('div').__proto__ !== 24 document.createElement('form').__proto__) 25 }, 26 27 ScriptFragment: '<script[^>]*>([\u0001-\uFFFF]*?)</script>', 28 JSONFilter: /^\/\*-secure-\s*(.*)\s*\*\/\s*$/, 29 30 emptyFunction: function() { }, 17 31 K: function(x) { return x } 18 32 } … … 47 61 }, 48 62 63 toJSON: function(object) { 64 var type = typeof object; 65 switch(type) { 66 case 'undefined': 67 case 'function': 68 case 'unknown': return; 69 case 'boolean': return object.toString(); 70 } 71 if (object === null) return 'null'; 72 if (object.toJSON) return object.toJSON(); 73 if (object.ownerDocument === document) return; 74 var results = []; 75 for (var property in object) { 76 var value = Object.toJSON(object[property]); 77 if (value !== undefined) 78 results.push(property.toJSON() + ': ' + value); 79 } 80 return '{' + results.join(', ') + '}'; 81 }, 82 49 83 keys: function(object) { 50 84 var keys = []; … … 76 110 var __method = this, args = $A(arguments), object = args.shift(); 77 111 return function(event) { 78 return __method.apply(object, [ ( event || window.event)].concat(args).concat($A(arguments)));112 return __method.apply(object, [event || window.event].concat(args)); 79 113 } 80 114 } … … 82 116 Object.extend(Number.prototype, { 83 117 toColorPart: function() { 84 var digits = this.toString(16); 85 if (this < 16) return '0' + digits; 86 return digits; 118 return this.toPaddedString(2, 16); 87 119 }, 88 120 … … 94 126 $R(0, this, true).each(iterator); 95 127 return this; 128 }, 129 130 toPaddedString: function(length, radix) { 131 var string = this.toString(radix || 10); 132 return '0'.times(length - string.length) + string; 133 }, 134 135 toJSON: function() { 136 return isFinite(this) ? this.toString() : 'null'; 96 137 } 97 138 }); 139 140 Date.prototype.toJSON = function() { 141 return '"' + this.getFullYear() + '-' + 142 (this.getMonth() + 1).toPaddedString(2) + '-' + 143 this.getDate().toPaddedString(2) + 'T' + 144 this.getHours().toPaddedString(2) + ':' + 145 this.getMinutes().toPaddedString(2) + ':' + 146 this.getSeconds().toPaddedString(2) + '"'; 147 }; 98 148 99 149 var Try = { … … 146 196 } 147 197 } 148 String.interpret = function(value){ 149 return value == null ? '' : String(value); 150 } 198 Object.extend(String, { 199 interpret: function(value) { 200 return value == null ? '' : String(value); 201 }, 202 specialChar: { 203 '\b': '\\b', 204 '\t': '\\t', 205 '\n': '\\n', 206 '\f': '\\f', 207 '\r': '\\r', 208 '\\': '\\\\' 209 } 210 }); 151 211 152 212 Object.extend(String.prototype, { … … 214 274 215 275 escapeHTML: function() { 216 var div = document.createElement('div'); 217 var text = document.createTextNode(this); 218 div.appendChild(text); 219 return div.innerHTML; 276 var self = arguments.callee; 277 self.text.data = this; 278 return self.div.innerHTML; 220 279 }, 221 280 … … 224 283 div.innerHTML = this.stripTags(); 225 284 return div.childNodes[0] ? (div.childNodes.length > 1 ? 226 $A(div.childNodes).inject('', function(memo,node){ return memo+node.nodeValue }) :285 $A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) : 227 286 div.childNodes[0].nodeValue) : ''; 228 287 }, … … 234 293 return match[1].split(separator || '&').inject({}, function(hash, pair) { 235 294 if ((pair = pair.split('='))[0]) { 236 var name = decodeURIComponent(pair[0]);237 var value = pair [1] ? decodeURIComponent(pair[1]) : undefined;238 239 if (hash[name] !== undefined) { 240 if (hash[name].constructor != Array)241 hash[name] = [hash[name]];242 if (value) hash[name].push(value);295 var key = decodeURIComponent(pair.shift()); 296 var value = pair.length > 1 ? pair.join('=') : pair[0]; 297 if (value != undefined) value = decodeURIComponent(value); 298 299 if (key in hash) { 300 if (hash[key].constructor != Array) hash[key] = [hash[key]]; 301 hash[key].push(value); 243 302 } 244 else hash[ name] = value;303 else hash[key] = value; 245 304 } 246 305 return hash; … … 257 316 }, 258 317 318 times: function(count) { 319 var result = ''; 320 for (var i = 0; i < count; i++) result += this; 321 return result; 322 }, 323 259 324 camelize: function() { 260 325 var parts = this.split('-'), len = parts.length; … … 271 336 }, 272 337 273 capitalize: function() {338 capitalize: function() { 274 339 return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase(); 275 340 }, … … 284 349 285 350 inspect: function(useDoubleQuotes) { 286 var escapedString = this.replace(/\\/g, '\\\\'); 287 if (useDoubleQuotes) 288 return '"' + escapedString.replace(/"/g, '\\"') + '"'; 289 else 290 return "'" + escapedString.replace(/'/g, '\\\'') + "'"; 351 var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) { 352 var character = String.specialChar[match[0]]; 353 return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16); 354 }); 355 if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"'; 356 return "'" + escapedString.replace(/'/g, '\\\'') + "'"; 357 }, 358 359 toJSON: function() { 360 return this.inspect(true); 361 }, 362 363 unfilterJSON: function(filter) { 364 return this.sub(filter || Prototype.JSONFilter, '#{1}'); 365 }, 366 367 evalJSON: function(sanitize) { 368 var json = this.unfilterJSON(); 369 try { 370 if (!sanitize || (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(json))) 371 return eval('(' + json + ')'); 372 } catch (e) { } 373 throw new SyntaxError('Badly formed JSON string: ' + this.inspect()); 374 }, 375 376 include: function(pattern) { 377 return this.indexOf(pattern) > -1; 378 }, 379 380 startsWith: function(pattern) { 381 return this.indexOf(pattern) === 0; 382 }, 383 384 endsWith: function(pattern) { 385 var d = this.length - pattern.length; 386 return d >= 0 && this.lastIndexOf(pattern) === d; 387 }, 388 389 empty: function() { 390 return this == ''; 391 }, 392 393 blank: function() { 394 return /^\s*$/.test(this); 395 } 396 }); 397 398 if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, { 399 escapeHTML: function() { 400 return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); 401 }, 402 unescapeHTML: function() { 403 return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); 291 404 } 292 405 }); … … 299 412 300 413 String.prototype.parseQuery = String.prototype.toQueryParams; 414 415 Object.extend(String.prototype.escapeHTML, { 416 div: document.createElement('div'), 417 text: document.createTextNode('') 418 }); 419 420 with (String.prototype.escapeHTML) div.appendChild(text); 301 421 302 422 var Template = Class.create(); … … 317 437 } 318 438 319 var $break = new Object(); 320 var $continue = new Object(); 439 var $break = {}, $continue = new Error('"throw $continue" is deprecated, use "return" instead'); 321 440 322 441 var Enumerable = { … … 325 444 try { 326 445 this._each(function(value) { 327 try { 328 iterator(value, index++); 329 } catch (e) { 330 if (e != $continue) throw e; 331 } 446 iterator(value, index++); 332 447 }); 333 448 } catch (e) { … … 531 646 } 532 647 648 if (Prototype.Browser.WebKit) { 649 $A = Array.from = function(iterable) { 650 if (!iterable) return []; 651 if (!(typeof iterable == 'function' && iterable == '[object NodeList]') && 652 iterable.toArray) { 653 return iterable.toArray(); 654 } else { 655 var results = []; 656 for (var i = 0, length = iterable.length; i < length; i++) 657 results.push(iterable[i]); 658 return results; 659 } 660 } 661 } 662 533 663 Object.extend(Array.prototype, Enumerable); 534 664 … … 589 719 }, 590 720 591 uniq: function() { 592 return this.inject([], function(array, value) { 593 return array.include(value) ? array : array.concat([value]); 721 uniq: function(sorted) { 722 return this.inject([], function(array, value, index) { 723 if (0 == index || (sorted ? array.last() != value : !array.include(value))) 724 array.push(value); 725 return array; 594 726 }); 595 727 }, … … 605 737 inspect: function() { 606 738 return '[' + this.map(Object.inspect).join(', ') + ']'; 739 }, 740 741 toJSON: function() { 742 var results = []; 743 this.each(function(object) { 744 var value = Object.toJSON(object); 745 if (value !== undefined) results.push(value); 746 }); 747 return '[' + results.join(', ') + ']'; 607 748 } 608 749 }); … … 610 751 Array.prototype.toArray = Array.prototype.clone; 611 752 612 function $w(string) {753 function $w(string) { 613 754 string = string.strip(); 614 755 return string ? string.split(/\s+/) : []; 615 756 } 616 757 617 if (window.ope
