Changeset 223
- Timestamp:
- 08/26/07 19:29:18 (1 year ago)
- Files:
-
- trunk/demo/app/controllers/content_controller.rb (modified) (3 diffs)
- trunk/demo/app/controllers/search_controller.rb (added)
- trunk/demo/app/helpers/search_helper.rb (added)
- trunk/demo/app/models/content.rb (modified) (1 diff)
- trunk/demo/app/models/search.rb (added)
- trunk/demo/app/views/content/index.rhtml (moved) (moved from trunk/demo/app/views/content/list.rhtml) (2 diffs)
- trunk/demo/app/views/search (added)
- trunk/demo/app/views/search/show.html.erb (moved) (moved from trunk/demo/app/views/content/search.rhtml) (2 diffs)
- trunk/demo/config/boot.rb (modified) (1 diff)
- trunk/demo/config/environments/development.rb (modified) (1 diff)
- trunk/demo/config/routes.rb (modified) (1 diff)
- 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)
- trunk/demo/script/process/inspector (added)
- trunk/demo/test/functional/content_controller_test.rb (modified) (3 diffs)
- trunk/demo/test/functional/search_controller_test.rb (added)
- trunk/demo/test/unit/comment_test.rb (modified) (1 diff)
- trunk/demo/vendor/plugins (modified) (1 prop)
- trunk/demo/vendor/plugins/will_paginate (added)
- trunk/demo/vendor/plugins/will_paginate/LICENSE (added)
- trunk/demo/vendor/plugins/will_paginate/README (added)
- trunk/demo/vendor/plugins/will_paginate/Rakefile (added)
- trunk/demo/vendor/plugins/will_paginate/init.rb (added)
- trunk/demo/vendor/plugins/will_paginate/lib (added)
- trunk/demo/vendor/plugins/will_paginate/lib/core_ext (added)
- trunk/demo/vendor/plugins/will_paginate/lib/will_paginate (added)
- trunk/demo/vendor/plugins/will_paginate/lib/will_paginate/collection.rb (added)
- trunk/demo/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb (added)
- trunk/demo/vendor/plugins/will_paginate/lib/will_paginate/finder.rb (added)
- trunk/demo/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test (added)
- trunk/demo/vendor/plugins/will_paginate/test/array_pagination_test.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/boot.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/console (added)
- trunk/demo/vendor/plugins/will_paginate/test/finder_test.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/admin.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/companies.yml (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/company.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/developer.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/developers_projects.yml (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/project.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/projects.yml (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/replies.yml (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/reply.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/schema.sql (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/topic.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/topics.yml (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/user.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/fixtures/users.yml (added)
- trunk/demo/vendor/plugins/will_paginate/test/helper.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/lib (added)
- trunk/demo/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/lib/load_fixtures.rb (added)
- trunk/demo/vendor/plugins/will_paginate/test/pagination_test.rb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/controllers/content_controller.rb
r5 r223 1 1 class ContentController < ApplicationController 2 def index 3 list 4 render :action => 'list' 5 end 2 before_filter :find_content, :only => [ :show, :edit, :update, :destroy ] 6 3 7 def list8 @content _pages, @contents = paginate :contents, :per_page => 104 def index 5 @contents = Content.paginate :page => params[:page] 9 6 end 10 7 11 8 def show 12 @content = Content.find(params[:id])13 9 end 14 10 … … 28 24 29 25 def edit 30 @content = Content.find(params[:id])31 26 end 32 27 33 28 def update 34 @content = Content.find(params[:id])35 29 if @content.update_attributes(params[:content]) 36 30 flash[:notice] = 'Content was successfully updated.' … … 42 36 43 37 def destroy 44 Content.find(params[:id]).destroy38 @content.destroy 45 39 redirect_to :action => 'list' 46 40 end 47 41 48 def search49 @query = params[:query] || '' 50 unless @query.blank?51 @ results = Content.find_by_contents @query42 protected 43 44 def find_content 45 @content = Content.find params[:id] 52 46 end 53 end 47 54 48 end trunk/demo/app/models/content.rb
r142 r223 1 1 class Content < ContentBase #ActiveRecord::Base 2 3 def self.per_page; 10; end 2 4 3 5 has_many :comments trunk/demo/app/views/content/index.rhtml
r5 r223 1 1 <h1>Listing contents</h1> 2 2 3 <p><%= will_paginate @contents %></p> 3 4 <table> 4 5 <tr> … … 20 21 </table> 21 22 22 <%= link_to 'Previous page', { :page => @content_pages.current.previous } if @content_pages.current.previous %> 23 <%= link_to 'Next page', { :page => @content_pages.current.next } if @content_pages.current.next %> 24 25 <br /> 26 27 <%= link_to 'New content', :action => 'new' %> 23 <p><%= will_paginate @contents %></p> 24 <p><%= link_to 'New content', :action => 'new' %></p> trunk/demo/app/views/search/show.html.erb
r135 r223 1 <h1>Search Content</h1>2 <% form_ tag :action => 'search' do%>1 <h1>Search</h1> 2 <% form_for :search, @search, search_path, :method => :get do |f| %> 3 3 <fieldset> 4 4 <legend>Search</legend> 5 < input type="text" name="query" value="<%= h @query %>" />5 <%= f.text_field 'query' %> 6 6 </fieldset> 7 7 <%= submit_tag 'search' %> … … 9 9 10 10 <% if @results -%> 11 <p>Your search for <%= h @query %> returned <%= @results.size %> Results:</p> 12 <ul> 13 <% @results.each { |result| -%> 14 <li><%= link_to result.title, :action => 'show', :id => result %></li> 15 <% } -%> 16 </ul> 11 12 <p>Your search for <%= h @search.query %> returned <%= @results.total_hits %> Results:</p> 13 14 <p><%= will_paginate @results %></p> 15 <ul> 16 <% @results.each { |result| -%> 17 <li><%= link_to result.title, :action => 'show', :id => result %></li> 18 <% } -%> 19 </ul> 20 <p><%= will_paginate @results %></p> 21 17 22 <% end -%> trunk/demo/config/boot.rb
r169 r223 1 1 # Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb 2 2 3 unless defined?(RAILS_ROOT) 4 root_path = File.join(File.dirname(__FILE__), '..') 5 6 unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ 7 require 'pathname' 8 root_path = Pathname.new(root_path).cleanpath(true).to_s 9 end 10 11 RAILS_ROOT = root_path 12 end 3 RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) 13 4 14 5 unless defined?(Rails::Initializer) trunk/demo/config/environments/development.rb
r5 r223 9 9 config.whiny_nils = true 10 10 11 # Enable the breakpoint server that script/breakpointer connects to12 config.breakpoint_server = true13 14 11 # Show full error reports and disable caching 15 12 config.action_controller.consider_all_requests_local = true trunk/demo/config/routes.rb
r5 r223 1 1 ActionController::Routing::Routes.draw do |map| 2 # Add your own custom routes here.3 # The priority is based upon order of creation: first created -> highest priority.4 5 # Here's a sample route:6 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'7 # Keep in mind you can assign values other than :controller and :action8 2 9 # You can have the root of your site routed by hooking up '' 10 # -- just remember to delete public/index.html. 11 # map.connect '', :controller => "welcome" 3 map.resources :content 4 map.resource :search 12 5 13 # Allow downloading Web Service WSDL as a file with an extension14 # instead of a file named 'wsdl'15 map.connect ':controller/service.wsdl', :action => 'wsdl'16 6 17 7 # Install the default route as the lowest priority. 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
