Changeset 169
- Timestamp:
- 03/19/07 20:49:03 (2 years ago)
- Files:
-
- trunk/demo/app/models/shared_index1.rb (modified) (1 diff)
- trunk/demo/app/models/shared_index2.rb (modified) (1 diff)
- trunk/demo/config/boot.rb (modified) (3 diffs)
- trunk/demo/public/javascripts/controls.js (modified) (16 diffs)
- trunk/demo/public/javascripts/dragdrop.js (modified) (32 diffs)
- trunk/demo/public/javascripts/effects.js (modified) (33 diffs)
- trunk/demo/public/javascripts/prototype.js (modified) (76 diffs)
- trunk/demo/test/unit/comment_test.rb (modified) (1 diff)
- trunk/demo/test/unit/content_test.rb (modified) (3 diffs)
- trunk/demo/test/unit/ferret_result_test.rb (added)
- trunk/demo/test/unit/shared_index1_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/models/shared_index1.rb
r142 r169 1 1 class SharedIndex1 < ActiveRecord::Base 2 acts_as_ferret :single_index => true, :remote => ENV['AAF_REMOTE'] 2 # default field list for all classes sharing the index 3 DEFAULT_FIELDS = [ :name ] 4 acts_as_ferret( { :fields => { :name => { :store => :yes } }, 5 :single_index => true, 6 :remote => ENV['AAF_REMOTE'] }, 7 { :default_field => DEFAULT_FIELDS } ) 3 8 end trunk/demo/app/models/shared_index2.rb
r142 r169 1 1 class SharedIndex2 < ActiveRecord::Base 2 acts_as_ferret :single_index => true, :remote => ENV['AAF_REMOTE'] 2 acts_as_ferret( { :fields => { :name => { :store => :yes } }, 3 :single_index => true, 4 :remote => ENV['AAF_REMOTE'] }, 5 { :default_field => SharedIndex1::DEFAULT_FIELDS } ) 3 6 end trunk/demo/config/boot.rb
r28 r169 4 4 root_path = File.join(File.dirname(__FILE__), '..') 5 5 6 unless RUBY_PLATFORM =~ / mswin32/6 unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ 7 7 require 'pathname' 8 8 root_path = Pathname.new(root_path).cleanpath(true).to_s … … 23 23 24 24 if version = defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : rails_gem_version 25 rails_gem = Gem.cache.search('rails', "=#{version}").first 25 # Asking for 1.1.6 will give you 1.1.6.5206, if available -- makes it easier to use beta gems 26 rails_gem = Gem.cache.search('rails', "~>#{version}.0").sort_by { |g| g.version.version }.last 26 27 27 28 if rails_gem 28 require_gem "rails", "=#{version}"29 gem "rails", "=#{rails_gem.version.version}" 29 30 require rails_gem.full_gem_path + '/lib/initializer' 30 31 else 31 STDERR.puts %(Cannot find gem for Rails =#{version}:32 STDERR.puts %(Cannot find gem for Rails ~>#{version}.0: 32 33 Install the missing gem with 'gem install -v=#{version} rails', or 33 34 change environment.rb to define RAILS_GEM_VERSION with your desired version. … … 36 37 end 37 38 else 38 require_gem "rails"39 gem "rails" 39 40 require 'initializer' 40 41 end trunk/demo/public/javascripts/controls.js
r28 r169 1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)2 // (c) 2005 Ivan Krstic (http://blogs.law.harvard.edu/ivan)3 // (c) 2005 Jon Tirsen (http://www.tirsen.com)1 // Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 2 // (c) 2005, 2006 Ivan Krstic (http://blogs.law.harvard.edu/ivan) 3 // (c) 2005, 2006 Jon Tirsen (http://www.tirsen.com) 4 4 // Contributors: 5 5 // Richard Livsey … … 7 7 // Rob Wills 8 8 // 9 // See scriptaculous.js for full license. 9 // script.aculo.us is freely distributable under the terms of an MIT-style license. 10 // For details, see the script.aculo.us web site: http://script.aculo.us/ 10 11 11 12 // Autocompleter.Base handles all the autocompletion functionality … … 33 34 // useful when one of the tokens is \n (a newline), as it 34 35 // allows smart autocompletion after linebreaks. 36 37 if(typeof Effect == 'undefined') 38 throw("controls.js requires including script.aculo.us' effects.js library"); 35 39 36 40 var Autocompleter = {} … … 46 50 this.entryCount = 0; 47 51 48 if (this.setOptions)52 if(this.setOptions) 49 53 this.setOptions(options); 50 54 else … … 56 60 this.options.minChars = this.options.minChars || 1; 57 61 this.options.onShow = this.options.onShow || 58 function(element, update){ 59 if(!update.style.position || update.style.position=='absolute') { 60 update.style.position = 'absolute'; 61 Position.clone(element, update, {setHeight: false, offsetTop: element.offsetHeight}); 62 } 63 Effect.Appear(update,{duration:0.15}); 64 }; 62 function(element, update){ 63 if(!update.style.position || update.style.position=='absolute') { 64 update.style.position = 'absolute'; 65 Position.clone(element, update, { 66 setHeight: false, 67 offsetTop: element.offsetHeight 68 }); 69 } 70 Effect.Appear(update,{duration:0.15}); 71 }; 65 72 this.options.onHide = this.options.onHide || 66 function(element, update){ new Effect.Fade(update,{duration:0.15}) };67 68 if (typeof(this.options.tokens) == 'string')73 function(element, update){ new Effect.Fade(update,{duration:0.15}) }; 74 75 if(typeof(this.options.tokens) == 'string') 69 76 this.options.tokens = new Array(this.options.tokens); 70 77 … … 95 102 96 103 fixIEOverlapping: function() { 97 Position.clone(this.update, this.iefix );104 Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)}); 98 105 this.iefix.style.zIndex = 1; 99 106 this.update.style.zIndex = 2; … … 203 210 if(this.index > 0) this.index-- 204 211 else this.index = this.entryCount-1; 212 this.getEntry(this.index).scrollIntoView(true); 205 213 }, 206 214 … … 208 216 if(this.index < this.entryCount-1) this.index++ 209 217 else this.index = 0; 218 this.getEntry(this.index).scrollIntoView(false); 210 219 }, 211 220 … … 255 264 this.update.innerHTML = choices; 256 265 Element.cleanWhitespace(this.update); 257 Element.cleanWhitespace(this.update. firstChild);258 259 if(this.update.firstChild && this.update. firstChild.childNodes) {266 Element.cleanWhitespace(this.update.down()); 267 268 if(this.update.firstChild && this.update.down().childNodes) { 260 269 this.entryCount = 261 this.update. firstChild.childNodes.length;270 this.update.down().childNodes.length; 262 271 for (var i = 0; i < this.entryCount; i++) { 263 272 var entry = this.getEntry(i); … … 270 279 271 280 this.stopIndicator(); 272 273 281 this.index = 0; 274 this.render(); 282 283 if(this.entryCount==1 && this.options.autoSelect) { 284 this.selectEntry(); 285 this.hide(); 286 } else { 287 this.render(); 288 } 275 289 } 276 290 }, … … 460 474 461 475 this.options = Object.extend({ 476 paramName: "value", 462 477 okButton: true, 463 478 okText: "ok", … … 532 547 this.createForm(); 533 548 this.element.parentNode.insertBefore(this.form, this.element); 534 Field.scrollFreeActivate(this.editField);549 if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField); 535 550 // stop the event to avoid a page refresh in Safari 536 551 if (evt) { … … 591 606 textField.obj = this; 592 607 textField.type = "text"; 593 textField.name = "value";608 textField.name = this.options.paramName; 594 609 textField.value = text; 595 610 textField.style.backgroundColor = this.options.highlightcolor; … … 604 619 var textArea = document.createElement("textarea"); 605 620 textArea.obj = this; 606 textArea.name = "value";621 textArea.name = this.options.paramName; 607 622 textArea.value = this.convertHTMLLineBreaks(text); 608 623 textArea.rows = this.options.rows; … … 637 652 this.editField.disabled = false; 638 653 this.editField.value = transport.responseText.stripTags(); 654 Field.scrollFreeActivate(this.editField); 639 655 }, 640 656 onclickCancel: function() { … … 773 789 optionTag = document.createElement("option"); 774 790 optionTag.value = (e instanceof Array) ? e[0] : e; 791 if((typeof this.options.value == 'undefined') && 792 ((e instanceof Array) ? this.element.innerHTML == e[1] : e == optionTag.value)) optionTag.selected = true; 775 793 if(this.options.value==optionTag.value) optionTag.selected = true; 776 794 optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e)); trunk/demo/public/javascripts/dragdrop.js
r28 r169 1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)2 // (c) 2005 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)1 // Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 2 // (c) 2005, 2006 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz) 3 3 // 4 // See scriptaculous.js for full license. 5 6 /*--------------------------------------------------------------------------*/ 4 // script.aculo.us is freely distributable under the terms of an MIT-style license. 5 // For details, see the script.aculo.us web site: http://script.aculo.us/ 6 7 if(typeof Effect == 'undefined') 8 throw("dragdrop.js requires including script.aculo.us' effects.js library"); 7 9 8 10 var Droppables = { … … 146 148 147 149 activate: function(draggable) { 148 window.focus(); // allows keypress events if window isn't currently focused, fails for Safari 149 this.activeDraggable = draggable; 150 if(draggable.options.delay) { 151 this._timeout = setTimeout(function() { 152 Draggables._timeout = null; 153 window.focus(); 154 Draggables.activeDraggable = draggable; 155 }.bind(this), draggable.options.delay); 156 } else { 157 window.focus(); // allows keypress events if window isn't currently focused, fails for Safari 158 this.activeDraggable = draggable; 159 } 150 160 }, 151 161 … … 161 171 if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return; 162 172 this._lastPointer = pointer; 173 163 174 this.activeDraggable.updateDrag(event, pointer); 164 175 }, 165 176 166 177 endDrag: function(event) { 178 if(this._timeout) { 179 clearTimeout(this._timeout); 180 this._timeout = null; 181 } 167 182 if(!this.activeDraggable) return; 168 183 this._lastPointer = null; … … 191 206 if(o[eventName]) o[eventName](eventName, draggable, event); 192 207 }); 208 if(draggable.options[eventName]) draggable.options[eventName](draggable, event); 193 209 }, 194 210 … … 205 221 206 222 var Draggable = Class.create(); 223 Draggable._dragging = {}; 224 207 225 Draggable.prototype = { 208 226 initialize: function(element) { 209 var options = Object.extend({227 var defaults = { 210 228 handle: false, 211 starteffect: function(element) {212 new Effect.Opacity(element, {duration:0.2, from:1.0, to:0.7});213 },214 229 reverteffect: function(element, top_offset, left_offset) { 215 230 var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02; 216 element._revert = new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur}); 231 new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur, 232 queue: {scope:'_draggable', position:'end'} 233 }); 217 234 }, 218 endeffect: function(element) { 219 new Effect.Opacity(element, {duration:0.2, from:0.7, to:1.0}); 235 endeffect: function(element) { 236 var toOpacity = typeof element._opacity == 'number' ? element._opacity : 1.0; 237 new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity, 238 queue: {scope:'_draggable', position:'end'}, 239 afterFinish: function(){ 240 Draggable._dragging[element] = false 241 } 242 }); 220 243 }, 221 244 zindex: 1000, … … 224 247 scrollSensitivity: 20, 225 248 scrollSpeed: 15, 226 snap: false // false, or xy or [x,y] or function(x,y){ return [x,y] } 227 }, arguments[1] || {}); 249 snap: false, // false, or xy or [x,y] or function(x,y){ return [x,y] } 250 delay: 0 251 }; 252 253 if(!arguments[1] || typeof arguments[1].endeffect == 'undefined') 254 Object.extend(defaults, { 255 starteffect: function(element) { 256 element._opacity = Element.getOpacity(element); 257 Draggable._dragging[element] = true; 258 new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7}); 259 } 260 }); 261 262 var options = Object.extend(defaults, arguments[1] || {}); 228 263 229 264 this.element = $(element); 230 265 231 if(options.handle && (typeof options.handle == 'string')) { 232 var h = Element.childrenWithClassName(this.element, options.handle, true); 233 if(h.length>0) this.handle = h[0]; 234 } 266 if(options.handle && (typeof options.handle == 'string')) 267 this.handle = this.element.down('.'+options.handle, 0); 268 235 269 if(!this.handle) this.handle = $(options.handle); 236 270 if(!this.handle) this.handle = this.element; 237 271 238 if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) 272 if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) { 239 273 options.scroll = $(options.scroll); 274 this._isScrollChild = Element.childOf(this.element, options.scroll); 275 } 240 276 241 277 Element.makePositioned(this.element); // fix IE … … 263 299 264 300 initDrag: function(event) { 301 if(typeof Draggable._dragging[this.element] != 'undefined' && 302 Draggable._dragging[this.element]) return; 265 303 if(Event.isLeftClick(event)) { 266 304 // abort on form elements, fixes a Firefox issue … … 273 311 src.tagName=='TEXTAREA')) return; 274 312 275 if(this.element._revert) {276 this.element._revert.cancel();277 this.element._revert = null;278 }279 280 313 var pointer = [Event.pointerX(event), Event.pointerY(event)]; 281 314 var pos = Position.cumulativeOffset(this.element); … … 313 346 314 347 Draggables.notify('onStart', this, event); 348 315 349 if(this.options.starteffect) this.options.starteffect(this.element); 316 350 }, … … 321 355 Droppables.show(pointer, this.element); 322 356 Draggables.notify('onDrag', this, event); 357 323 358 this.draw(pointer); 324 359 if(this.options.change) this.options.change(this); … … 332 367 } else { 333 368 p = Position.page(this.options.scroll); 334 p[0] += this.options.scroll.scrollLeft ;335 p[1] += this.options.scroll.scrollTop ;369 p[0] += this.options.scroll.scrollLeft + Position.deltaX; 370 p[1] += this.options.scroll.scrollTop + Position.deltaY; 336 371 p.push(p[0]+this.options.scroll.offsetWidth); 337 372 p.push(p[1]+this.options.scroll.offsetHeight); … … 379 414 if(this.options.endeffect) 380 415 this.options.endeffect(this.element); 381 416 382 417 Draggables.deactivate(this); 383 418 Droppables.reset(); … … 399 434 draw: function(point) { 400 435 var pos = Position.cumulativeOffset(this.element); 436 if(this.options.ghosting) { 437 var r = Position.realOffset(this.element); 438 pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY; 439 } 440 401 441 var d = this.currentDelta(); 402 442 pos[0] -= d[0]; pos[1] -= d[1]; 403 443 404 if(this.options.scroll && (this.options.scroll != window )) {444 if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) { 405 445 pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft; 406 446 pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop; … … 413 453 if(this.options.snap) { 414 454 if(typeof this.options.snap == 'function') { 415 p = this.options.snap(p[0],p[1] );455 p = this.options.snap(p[0],p[1],this); 416 456 } else { 417 457 if(this.options.snap instanceof Array) { … … 429 469 if((!this.options.constraint) || (this.options.constraint=='vertical')) 430 470 style.top = p[1] + "px"; 471 431 472 if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering 432 473 }, … … 441 482 442 483 startScrolling: function(speed) { 484 if(!(speed[0] || speed[1])) return; 443 485 this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed]; 444 486 this.lastScrolled = new Date(); … … 465 507 Droppables.show(Draggables._lastPointer, this.element); 466 508 Draggables.notify('onDrag', this); 467 Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer); 468 Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000; 469 Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000; 470 if (Draggables._lastScrollPointer[0] < 0) 471 Draggables._lastScrollPointer[0] = 0; 472 if (Draggables._lastScrollPointer[1] < 0) 473 Draggables._lastScrollPointer[1] = 0; 474 this.draw(Draggables._lastScrollPointer); 509 if (this._isScrollChild) { 510 Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer); 511 Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000; 512 Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000; 513 if (Draggables._lastScrollPointer[0] < 0) 514 Draggables._lastScrollPointer[0] = 0; 515 if (Draggables._lastScrollPointer[1] < 0) 516 Draggables._lastScrollPointer[1] = 0; 517 this.draw(Draggables._lastScrollPointer); 518 } 475 519 476 520 if(this.options.change) this.options.change(this); … … 524 568 525 569 var Sortable = { 570 SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/, 571 526 572 sortables: {}, 527 573 … … 564 610 handle: false, // or a CSS class 565 611 only: false, 612 delay: 0, 566 613 hoverclass: null, 567 614 ghosting: false, … … 569 616 scrollSensitivity: 20, 570 617 scrollSpeed: 15, 571 format: /^[^_]*_(.*)$/,618 format: this.SERIALIZE_RULE, 572 619 onChange: Prototype.emptyFunction, 573 620 onUpdate: Prototype.emptyFunction … … 583 630 scrollSpeed: options.scrollSpeed, 584 631 scrollSensitivity: options.scrollSensitivity, 632 delay: options.delay, 585 633 ghosting: options.ghosting, 586 634 constraint: options.constraint, … … 611 659 hoverclass: options.hoverclass, 612 660 onHover: Sortable.onHover 613 //greedy: !options.dropOnEmpty614 661 } 615 662 … … 636 683 // handles are per-draggable 637 684 var handle = options.handle ? 638 Element.childrenWithClassName(e, options.handle)[0]: e;685 $(e).down('.'+options.handle,0) : e; 639 686 options.draggables.push( 640 687 new Draggable(e, Object.extend(options_for_draggable, { handle: handle }))); … … 707 754 var index; 708 755 709 var children = Sortable.findElements(dropon, {tag: droponOptions.tag });756 var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only}); 710 757 var child = null; 711 758 … … 734 781 735 782 unmark: function() { 736 if(Sortable._marker) Element.hide(Sortable._marker);783 if(Sortable._marker) Sortable._marker.hide(); 737 784 }, 738 785 … … 743 790 744 791 if(!Sortable._marker) { 745 Sortable._marker = $('dropmarker') || document.createElement('DIV'); 746 Element.hide(Sortable._marker); 747 Element.addClassName(Sortable._marker, 'dropmarker'); 748 Sortable._marker.style.position = 'absolute'; 792 Sortable._marker = 793 ($('dropmarker') || Element.extend(document.createElement('DIV'))). 794 hide().addClassName('dropmarker').setStyle({position:'absolute'}); 749 795 document.getElementsByTagName("body").item(0).appendChild(Sortable._marker); 750 796 } 751 797 var offsets = Position.cumulativeOffset(dropon); 752 Sortable._marker.style.left = offsets[0] + 'px'; 753 Sortable._marker.style.top = offsets[1] + 'px'; 798 Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'}); 754 799 755 800 if(position=='after') 756 801 if(sortable.overlap == 'horizontal') 757 Sortable._marker.s tyle.left = (offsets[0]+dropon.clientWidth) + 'px';802 Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'}); 758 803 else 759 Sortable._marker.s tyle.top = (offsets[1]+dropon.clientHeight) + 'px';760 761 Element.show(Sortable._marker);804 Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'}); 805 806 Sortable._marker.show(); 762 807 }, 763 808 … … 774 819 element: element, 775 820 parent: parent, 776 children: new Array,821 children: [], 777 822 position: parent.children.length, 778 container: Sortable._findChildrenElement(children[i], options.treeTag.toUpperCase())823 container: $(children[i]).down(options.treeTag) 779 824 } 780 825 … … 787 832 788 833 return parent; 789 },790 791 /* Finds the first element of the given tag type within a parent element.792 Used for finding the first LI[ST] within a L[IST]I[TEM].*/793 _findChildrenElement: function (element, containerTag) {794 if (element && element.hasChildNodes)795 for (var i = 0; i < element.childNodes.length; ++i)796 if (element.childNodes[i].tagName == containerTag)797 return element.childNodes[i];798 799 return null;800 834 }, 801 835 … … 814 848 id: null, 815 849 parent: null, 816 children: new Array,850 children: [], 817 851 container: element, 818 852 position: 0 819 853 } 820 854 821 return Sortable._tree (element, options, root);855 return Sortable._tree(element, options, root); 822 856 }, 823 857 … … 868 902 if (options.tree) { 869 903 return Sortable.tree(element, arguments[1]).children.map( function (item) { 870 return [name + Sortable._constructIndex(item) + " =" +904 return [name + Sortable._constructIndex(item) + "[id]=" + 871 905 encodeURIComponent(item.id)].concat(item.children.map(arguments.callee)); 872 906 }).flatten().join('&'); … … 879 913 } 880 914 881 / * Returns true if child is contained within element */915 // Returns true if child is contained within element 882 916 Element.isParent = function(child, element) { 883 917 if (!child.parentNode || child == element) return false; 884 885 918 if (child.parentNode == element) return true; 886 887 919 return Element.isParent(child.parentNode, element); 888 920 } … … 907 939 908 940 Element.offsetSize = function (element, type) { 909 if (type == 'vertical' || type == 'height') 910 return element.offsetHeight; 911 else 912 return element.offsetWidth; 941 return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')]; 913 942 } trunk/demo/public/javascripts/effects.js
r28 r169 1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)1 // Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 2 2 // Contributors: 3 3 // Justin Palmer (http://encytemedia.com/) … … 5 5 // Martin Bialasinki 6 6 // 7 // See scriptaculous.js for full license. 7 // script.aculo.us is freely distributable under the terms of an MIT-style license. 8 // For details, see the script.aculo.us web site: http://script.aculo.us/ 8 9 9 10 // converts rgb() and #xxx to #xxxxxx format, 10 11 // returns self (or first argument) if not convertable 11 12 String.prototype.parseColor = function() { 12 var color = '#'; 13 var color = '#'; 13 14 if(this.slice(0,4) == 'rgb(') { 14 15 var cols = this.slice(4,this.length-1).split(','); … … 42 43 Element.setContentZoom = function(element, percent) { 43 44 element = $(element); 44 Element.setStyle(element,{fontSize: (percent/100) + 'em'});45 element.setStyle({fontSize: (percent/100) + 'em'}); 45 46 if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0); 46 } 47 48 Element.getOpacity = function(element){ 47 return element; 48 } 49 50 Element.getOpacity = function(element){ 51 element = $(element); 49 52 var opacity; 50 if (opacity = Element.getStyle(element,'opacity'))53 if (opacity = element.getStyle('opacity')) 51 54 return parseFloat(opacity); 52 if (opacity = ( Element.getStyle(element,'filter') || '').match(/alpha\(opacity=(.*)\)/))55 if (opacity = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/)) 53 56 if(opacity[1]) return parseFloat(opacity[1]) / 100; 54 57 return 1.0; … … 58 61 element= $(element); 59 62 if (value == 1){ 60 Element.setStyle(element,{ opacity:63 element.setStyle({ opacity: 61 64 (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 62 0.999999 : null});63 if(/MSIE/.test(navigator.userAgent) )64 Element.setStyle(element,{filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')});65 0.999999 : 1.0 }); 66 if(/MSIE/.test(navigator.userAgent) && !window.opera) 67 element.setStyle({filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')}); 65 68 } else { 66 69 if(value < 0.00001) value = 0; 67 Element.setStyle(element, {opacity: value}); 68 if(/MSIE/.test(navigator.userAgent)) 69 Element.setStyle(element, 70 { filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'') + 71 'alpha(opacity='+value*100+')' }); 72 } 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; 73 77 } 74 78 … … 76 80 return $(element).style.opacity || ''; 77 81 } 78 79 Element.childrenWithClassName = function(element, className, findFirst) {80 var classNameRegExp = new RegExp("(^|\\s)" + className + "(\\s|$)");81 var results = $A($(element).getElementsByTagName('*'))[findFirst ? 'detect' : 'select']( function(c) {82 return (c.className && c.className.match(classNameRegExp));83 });84 if(!results) results = [];85 return results;86 }87 82 88 83 Element.forceRerendering = function(element) { … … 105 100 106 101 var Effect = { 102 _elementDoesNotExistError: { 103 name: 'ElementDoesNotExistError', 104 message: 'The specified DOM element does not exist, but is required for this effect to operate' 105 }, 107 106 tagifyText: function(element) { 107 if(typeof Builder == 'undefined') 108 throw("Effect.tagifyText requires including script.aculo.us' builder.js library"); 109 108 110 var tagifyStyle = 'position:relative'; 109 if(/MSIE/.test(navigator.userAgent)) tagifyStyle += ';zoom:1'; 111 if(/MSIE/.test(navigator.userAgent) && !window.opera) tagifyStyle += ';zoom:1'; 112 110 113 element = $(element); 111 114 $A(element.childNodes).each( function(child) { … … 160 163 /* ------------- transitions ------------- */ 161 164 162 Effect.Transitions = {} 163 164 Effect.Transitions.linear = function(pos) { 165 return pos; 166 } 167 Effect.Transitions.sinoidal = function(pos) { 168 return (-Math.cos(pos*Math.PI)/2) + 0.5; 169 } 170 Effect.Transitions.reverse = function(pos) { 171 return 1-pos; 172 } 173 Effect.Transitions.flicker = function(pos) { 174 return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4; 175 } 176 Effect.Transitions.wobble = function(pos) { 177 return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5; 178 } 179 Effect.Transitions.pulse = function(pos) { 180 return (Math.floor(pos*10) % 2 == 0 ? 181 (pos*10-Math.floor(pos*10)) : 1-(pos*10-Math.floor(pos*10))); 182 } 183 Effect.Transitions.none = function(pos) { 184 return 0; 185 } 186 Effect.Transitions.full = function(pos) { 187 return 1; 188 } 165 Effect.Transitions = { 166 linear: Prototype.K, 167 sinoidal: function(pos) { 168 return (-Math.cos(pos*Math.PI)/2) + 0.5; 169 }, 170 reverse: function(pos) { 171 return 1-pos; 172 }, 173 flicker: function(pos) { 174 return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4; 175 }, 176 wobble: function(pos) { 177 return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5; 178 }, 179 pulse: function(pos, pulses) { 180 pulses = pulses || 5; 181 return ( 182 Math.round((pos % (1/pulses)) * pulses) == 0 ? 183 ((pos * pulses * 2) - Math.floor(pos * pulses * 2)) : 184 1 - ((pos * pulses * 2) - Math.floor(pos * pulses * 2)) 185 ); 186 }, 187 none: function(pos) { 188 return 0; 189 }, 190 full: function(pos) { 191 return 1; 192 } 193 }; 189 194 190 195 /* ------------- core effects ------------- */ … … 212 217 e.finishOn += effect.finishOn; 213 218 }); 219 break; 220 case 'with-last': 221 timestamp = this.effects.pluck('startOn').max() || timestamp; 214 222 break; 215 223 case 'end': … … 349 357 }); 350 358 359 Effect.Event = Class.create(); 360 Object.extend(Object.extend(Effect.Event.prototype, Effect.Base.prototype), { 361 initialize: function() { 362 var options = Object.extend({ 363 duration: 0 364 }, arguments[0] || {}); 365 this.start(options); 366 }, 367 update: Prototype.emptyFunction 368 }); 369 351 370 Effect.Opacity = Class.create(); 352 371 Object.extend(Object.extend(Effect.Opacity.prototype, Effect.Base.prototype), { 353 372 initialize: function(element) { 354 373 this.element = $(element); 374 if(!this.element) throw(Effect._elementDoesNotExistError); 355 375 // make this work on IE on elements without 'layout' 356 if(/MSIE/.test(navigator.userAgent) && (!this.element.hasLayout))376 if(/MSIE/.test(navigator.userAgent) && !window.opera && (!this.element.currentStyle.hasLayout)) 357 377 this.element.setStyle({zoom: 1}); 358 378 var options = Object.extend({ … … 371 391 initialize: function(element) { 372 392 this.element = $(element); 393 if(!this.element) throw(Effect._elementDoesNotExistError); 373 394 var options = Object.extend({ 374 395 x: 0, … … 394 415 update: function(position) { 395 416 this.element.setStyle({ 396 left: this.options.x * position + this.originalLeft+ 'px',397 top: this.options.y * position + this.originalTop+ 'px'417 left: Math.round(this.options.x * position + this.originalLeft) + 'px', 418 top: Math.round(this.options.y * position + this.originalTop) + 'px' 398 419 }); 399 420 } … … 409 430 Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), { 410 431 initialize: function(element, percent) { 411 this.element = $(element) 432 this.element = $(element); 433 if(!this.element) throw(Effect._elementDoesNotExistError); 412 434 var options = Object.extend({ 413 435 scaleX: true, … … 434 456 435 457 var fontSize = this.element.getStyle('font-size') || '100%'; 436 ['em','px','%' ].each( function(fontSizeType) {458 ['em','px','%','pt'].each( function(fontSizeType) { 437 459 if(fontSize.indexOf(fontSizeType)>0) { 438 460 this.fontSize = parseFloat(fontSize); … … 459 481 }, 460 482 finish: function(position) { 461 if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle);483 if(this.restoreAfterFinish) this.element.setStyle(this.originalStyle); 462 484 }, 463 485 setDimensions: function(height, width) { 464 486 var d = {}; 465 if(this.options.scaleX) d.width = width+ 'px';466 if(this.options.scaleY) d.height = height+ 'px';487 if(this.options.scaleX) d.width = Math.round(width) + 'px'; 488 if(this.options.scaleY) d.height = Math.round(height) + 'px'; 467 489 if(this.options.scaleFromCenter) { 468 490 var topd = (height - this.dims[0])/2; … … 484 506 initialize: function(element) { 485 507 this.element = $(element); 508 if(!this.element) throw(Effect._elementDoesNotExistError); 486 509 var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || {}); 487 510 this.start(options); … … 548 571 afterFinishInternal: function(effect) { 549 572 if(effect.options.to!=0) return; 550 effect.element.hide(); 551 effect.element.setStyle({opacity: oldOpacity}); 573 effect.element.hide().setStyle({opacity: oldOpacity}); 552 574 }}, arguments[1] || {}); 553 575 return new Effect.Opacity(element,options); … … 564 586 }, 565 587 beforeSetup: function(effect) { 566 effect.element.setOpacity(effect.options.from); 567 effect.element.show(); 588 effect.element.setOpacity(effect.options.from).show(); 568 589 }}, arguments[1] || {}); 569 590 return new Effect.Opacity(element,options); … … 572 593 Effect.Puff = function(element) { 573 594 element = $(element); 574 var oldStyle = { opacity: element.getInlineOpacity(), position: element.getStyle('position') }; 595 var oldStyle = { 596 opacity: element.getInlineOpacity(), 597 position: element.getStyle('position'), 598 top: element.style.top, 599 left: element.style.left, 600 width: element.style.width, 601 height: element.style.height 602 }; 575 603 return new Effect.Parallel( 576 604 [ new Effect.Scale(element, 200, … … 579 607 Object.extend({ duration: 1.0, 580 608 beforeSetupInternal: function(effect) { 581 effect.effects[0].element.setStyle({position: 'absolute'}); }, 609 Position.absolutize(effect.effects[0].element) 610 }, 582 611 afterFinishInternal: function(effect) { 583 effect.effects[0].element.hide(); 584 effect.effects[0].element.setStyle(oldStyle); } 612 effect.effects[0].element.hide().setStyle(oldStyle); } 585 613 }, arguments[1] || {}) 586 614 ); … … 590 618 element = $(element); 591 619 element.makeClipping(); 592 return new Effect.Scale(element, 0, 620 return new Effect.Scale(element, 0, 593 621 Object.extend({ scaleContent: false, 594 622 scaleX: false, 595 623 restoreAfterFinish: true, 596 624 afterFinishInternal: function(effect) { 597 effect.element.hide(); 598 effect.element.undoClipping(); 625 effect.element.hide().undoClipping(); 599 626 } 600 627 }, arguments[1] || {}) … … 605 632 element = $(element); 606 633 var elementDimensions = element.getDimensions(); 607 return new Effect.Scale(element, 100, 608 Object.extend({ scaleContent: false, 609 scaleX: false, 610 scaleFrom: 0, 611 scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, 612 restoreAfterFinish: true, 613 afterSetup: function(effect) { 614 effect.element.makeClipping(); 615 effect.element.setStyle({height: '0px'}); 616 effect.element.show(); 617 }, 618 afterFinishInternal: function(effect) { 619 effect.element.undoClipping(); 620 } 621 }, arguments[1] || {}) 622 ); 634 return new Effect.Scale(element, 100, Object.extend({ 635 scaleContent: false, 636 scaleX: false, 637 scaleFrom: 0, 638 scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, 639 restoreAfterFinish: true, 640 afterSetup: function(effect) { 641 effect.element.makeClipping().setStyle({height: '0px'}).show(); 642 }, 643 afterFinishInternal: function(effect) { 644 effect.element.undoClipping(); 645 } 646 }, arguments[1] || {})); 623 647 } 624 648 … … 626 650 element = $(element); 627 651 var oldOpacity = element.getInlineOpacity(); 628 return new Effect.Appear(element, {652 return new Effect.Appear(element, Object.extend({ 629 653 duration: 0.4, 630 654 from: 0, … … 635 659 scaleX: false, scaleContent: false, restoreAfterFinish: true, 636 660 beforeSetup: function(effect) { 637 effect.element.makePositioned(); 638 effect.element.makeClipping(); 661 effect.element.makePositioned().makeClipping(); 639 662 }, 640 663 afterFinishInternal: function(effect) { 641 effect.element.hide(); 642 effect.element.undoClipping(); 643 effect.element.undoPositioned(); 644 effect.element.setStyle({opacity: oldOpacity}); 664 effect.element.hide().undoClipping().undoPositioned().setStyle({opacity: oldOpacity}); 645 665 } 646 666 }) 647 667 } 648 } );668 }, arguments[1] || {})); 649 669 } 650 670 … … 664 684 }, 665 685 afterFinishInternal: function(effect) { 666 effect.effects[0].element.hide(); 667 effect.effects[0].element.undoPositioned(); 668 effect.effects[0].element.setStyle(oldStyle); 686 effect.effects[0].element.hide().undoPositioned().setStyle(oldStyle); 669 687 } 670 688 }, arguments[1] ||
