Revision 05f13042
Added by Marc Dequènes over 14 years ago
- ID 05f13042d910b390b3eeb3123fcdfe209e155da3
app/controllers/application.rb | ||
---|---|---|
# Filters added to this controller apply to all controllers in the application.
|
||
# Likewise, all the methods added will be available for all controllers.
|
||
|
||
require 'gettext/rails'
|
||
require 'exif'
|
||
require 'utils'
|
||
require 'mycyma'
|
||
|
||
#Mime::Type.register "image/svg+xml", :svg
|
||
|
||
class ApplicationController < ActionController::Base
|
||
helper :all # include all helpers, all the time
|
||
|
||
rescue_from RestfulSupport::ResourceNotFound, :with => :render_404
|
||
rescue_from RestfulSupport::UnrelatedResources, :with => :render_404
|
||
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
|
||
|
||
# See ActionController::RequestForgeryProtection for details
|
||
# Uncomment the :secret if you're not using the cookie session store
|
||
protect_from_forgery :secret => MyCyma::Config.instance.session_secret
|
||
|
||
filter_parameter_logging :password
|
||
|
||
init_gettext MyCyma::Info::app_name
|
||
|
||
before_init_gettext :ensure_prefered_language
|
||
|
||
def initialize
|
||
super
|
||
|
||
@config = MyCyma::Config.instance
|
||
end
|
||
|
||
def render_404
|
||
render :template => "common/404", :layout => ! request.xhr?, :status => :not_found
|
||
return false
|
||
end
|
||
|
||
def login_required
|
||
return true if session[:user_id]
|
||
|
||
flash[:warning] = _('Please login to continue')
|
||
session[:return_to] = request.request_uri
|
||
redirect_to :controller => "/logon", :action => "login"
|
||
return false
|
||
end
|
||
|
||
def admin_required
|
||
return true if login_required and current_user.admin
|
||
|
||
@reject_reason = "You are not an Admin !"
|
||
render :template => "common/403", :layout => ! request.xhr?, :status => :forbidden
|
||
return false
|
||
end
|
||
|
||
def current_user
|
||
@current_user ||= ((session[:user_id] && User.find_by_id(session[:user_id])) || nil)
|
||
end
|
||
|
||
def redirect_to_stored
|
||
if return_to = session[:return_to]
|
||
session[:return_to] = nil
|
||
redirect_to(return_to)
|
||
else
|
||
redirect_to :controller => 'welcome', :action => 'index'
|
||
end
|
||
end
|
||
|
||
def ensure_prefered_language
|
||
@config.switch_locale(current_user.prefered_language) if current_user
|
||
end
|
||
end
|
app/controllers/application_controller.rb | ||
---|---|---|
# Filters added to this controller apply to all controllers in the application.
|
||
# Likewise, all the methods added will be available for all controllers.
|
||
|
||
require 'gettext_rails'
|
||
require 'exif'
|
||
require 'utils'
|
||
require 'mycyma'
|
||
|
||
#Mime::Type.register "image/svg+xml", :svg
|
||
|
||
class ApplicationController < ActionController::Base
|
||
helper :all # include all helpers, all the time
|
||
|
||
rescue_from RestfulSupport::ResourceNotFound, :with => :render_404
|
||
rescue_from RestfulSupport::UnrelatedResources, :with => :render_404
|
||
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
|
||
|
||
# See ActionController::RequestForgeryProtection for details
|
||
# Uncomment the :secret if you're not using the cookie session store
|
||
protect_from_forgery :secret => MyCyma::Config.instance.session_secret
|
||
|
||
filter_parameter_logging :password
|
||
|
||
init_gettext MyCyma::Info::app_name
|
||
|
||
before_init_gettext :ensure_prefered_language
|
||
|
||
def initialize
|
||
super
|
||
|
||
@config = MyCyma::Config.instance
|
||
end
|
||
|
||
def render_404
|
||
render :template => "common/404", :layout => ! request.xhr?, :status => :not_found
|
||
return false
|
||
end
|
||
|
||
def login_required
|
||
return true if session[:user_id]
|
||
|
||
flash[:warning] = _('Please login to continue')
|
||
session[:return_to] = request.request_uri
|
||
redirect_to :controller => "/logon", :action => "login"
|
||
return false
|
||
end
|
||
|
||
def admin_required
|
||
return true if login_required and current_user.admin
|
||
|
||
@reject_reason = "You are not an Admin !"
|
||
render :template => "common/403", :layout => ! request.xhr?, :status => :forbidden
|
||
return false
|
||
end
|
||
|
||
def current_user
|
||
@current_user ||= ((session[:user_id] && User.find_by_id(session[:user_id])) || nil)
|
||
end
|
||
|
||
def redirect_to_stored
|
||
if return_to = session[:return_to]
|
||
session[:return_to] = nil
|
||
redirect_to(return_to)
|
||
else
|
||
redirect_to :controller => 'welcome', :action => 'index'
|
||
end
|
||
end
|
||
|
||
def ensure_prefered_language
|
||
@config.switch_locale(current_user.prefered_language) if current_user
|
||
end
|
||
end
|
config/boot.rb | ||
---|---|---|
def load_initializer
|
||
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
||
Rails::Initializer.run(:install_gem_spec_stubs)
|
||
Rails::GemDependency.add_frozen_gem_path
|
||
end
|
||
end
|
||
|
||
... | ... | |
end
|
||
|
||
def load_rubygems
|
||
min_version = '1.3.2'
|
||
require 'rubygems'
|
||
min_version = '1.3.1'
|
||
unless rubygems_version >= min_version
|
||
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
||
exit 1
|
config/environment.rb | ||
---|---|---|
# Be sure to restart your server when you modify this file
|
||
|
||
$KCODE = 'u'
|
||
require 'jcode'
|
||
|
||
# Uncomment below to force Rails into production mode when
|
||
# you don't control web/app server and can't set it the proper way
|
||
# ENV['RAILS_ENV'] ||= 'production'
|
||
|
||
# Specifies gem version of Rails to use when vendor/rails is not present
|
||
RAILS_GEM_VERSION = '2.1.0' unless defined? RAILS_GEM_VERSION
|
||
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
|
||
|
||
# Bootstrap the Rails environment, frameworks, and default configuration
|
||
require File.join(File.dirname(__FILE__), 'boot')
|
||
... | ... | |
# Settings in config/environments/* take precedence over those specified here.
|
||
# Application configuration should go into files in config/initializers
|
||
# -- all .rb files in that directory are automatically loaded.
|
||
# See Rails::Configuration for more options.
|
||
|
||
# Skip frameworks you're not going to use. To use Rails without a database
|
||
# you must remove the Active Record framework.
|
||
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
|
||
# Add additional load paths for your own custom dirs
|
||
# config.load_paths += %W( #{RAILS_ROOT}/extras )
|
||
|
||
# Specify gems that this application depends on.
|
||
# They can then be installed with "rake gems:install" on new installations.
|
||
# Specify gems that this application depends on and have them installed with rake gems:install
|
||
# config.gem "bj"
|
||
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
|
||
# config.gem "sqlite3-ruby", :lib => "sqlite3"
|
||
# config.gem "aws-s3", :lib => "aws/s3"
|
||
|
||
# Only load the plugins named here, in the order given. By default, all plugins
|
||
# in vendor/plugins are loaded in alphabetical order.
|
||
# Only load the plugins named here, in the order given (default is alphabetical).
|
||
# :all can be used as a placeholder for all plugins not explicitly named
|
||
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
||
|
||
# Add additional load paths for your own custom dirs
|
||
# config.load_paths += %W( #{RAILS_ROOT}/extras )
|
||
# Skip frameworks you're not going to use. To use Rails without a database,
|
||
# you must remove the Active Record framework.
|
||
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
|
||
|
||
# Force all environments to use the same logger level
|
||
# (by default production uses :info, the others :debug)
|
||
# config.log_level = :debug
|
||
# Activate observers that should always be running
|
||
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
||
|
||
# Make Time.zone default to the specified zone, and make Active Record store time values
|
||
# in the database in UTC, and return them converted to the specified local zone.
|
||
# Run "rake -D time" for a list of tasks for finding time zone names. Uncomment to use default local time.
|
||
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
||
# Run "rake -D time" for a list of tasks for finding time zone names.
|
||
config.time_zone = 'UTC'
|
||
|
||
# Your secret key for verifying cookie session data integrity.
|
||
# If you change this key, all old sessions will become invalid!
|
||
# Make sure the secret is at least 30 characters and all random,
|
||
# no regular words or you'll be exposed to dictionary attacks.
|
||
config.action_controller.session = {
|
||
:session_key => '_jmb_session',
|
||
:secret => 'c80b03ca37da9987a2f109b9d2eda82cd249bb36be4a0c4ae198f7744027b6f874f1809471f998f7b3108e50b979fa795adc6fab857c47f89287eae1a77b74ec'
|
||
}
|
||
|
||
# Use the database for sessions instead of the cookie-based default,
|
||
# which shouldn't be used to store highly confidential information
|
||
# (create the session table with "rake db:sessions:create")
|
||
config.action_controller.session_store = :active_record_store
|
||
|
||
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
||
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
||
# like if you have constraints or database-specific column types
|
||
# config.active_record.schema_format = :sql
|
||
|
||
# Activate observers that should always be running
|
||
# config.active_record.observers = :cacher, :garbage_collector
|
||
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
||
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
|
||
# config.i18n.default_locale = :de
|
||
end
|
||
|
||
require 'fixes'
|
config/environments/production.rb | ||
---|---|---|
# Code is not reloaded between requests
|
||
config.cache_classes = true
|
||
|
||
# Use a different logger for distributed setups
|
||
# config.logger = SyslogLogger.new
|
||
|
||
# Full error reports are disabled and caching is turned on
|
||
config.action_controller.consider_all_requests_local = false
|
||
config.action_controller.perform_caching = true
|
||
config.action_view.cache_template_loading = true
|
||
|
||
# See everything in the log (default is :info)
|
||
# config.log_level = :debug
|
||
|
||
# Use a different logger for distributed setups
|
||
# config.logger = SyslogLogger.new
|
||
|
||
# Use a different cache store in production
|
||
# config.cache_store = :mem_cache_store
|
||
|
||
# Enable serving of images, stylesheets, and javascripts from an asset server
|
||
# config.action_controller.asset_host = "http://assets.example.com"
|
||
# config.action_controller.asset_host = "http://assets.example.com"
|
||
|
||
# Disable delivery errors, bad email addresses will be ignored
|
||
# config.action_mailer.raise_delivery_errors = false
|
||
|
||
# Enable threaded mode
|
||
# config.threadsafe!
|
config/environments/test.rb | ||
---|---|---|
# Show full error reports and disable caching
|
||
config.action_controller.consider_all_requests_local = true
|
||
config.action_controller.perform_caching = false
|
||
config.action_view.cache_template_loading = true
|
||
|
||
# Disable request forgery protection in test environment
|
||
config.action_controller.allow_forgery_protection = false
|
||
... | ... | |
# The :test delivery method accumulates sent emails in the
|
||
# ActionMailer::Base.deliveries array.
|
||
config.action_mailer.delivery_method = :test
|
||
|
||
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
||
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
||
# like if you have constraints or database-specific column types
|
||
# config.active_record.schema_format = :sql
|
config/initializers/backtrace_silencers.rb | ||
---|---|---|
# Be sure to restart your server when you modify this file.
|
||
|
||
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
||
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
||
|
||
# You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
|
||
# Rails.backtrace_cleaner.remove_silencers!
|
config/initializers/inflections.rb | ||
---|---|---|
|
||
# Add new inflection rules using the following format
|
||
# (all these examples are active by default):
|
||
# Inflector.inflections do |inflect|
|
||
# ActiveSupport::Inflector.inflections do |inflect|
|
||
# inflect.plural /^(ox)$/i, '\1en'
|
||
# inflect.singular /^(ox)en/i, '\1'
|
||
# inflect.irregular 'person', 'people'
|
config/initializers/new_rails_defaults.rb | ||
---|---|---|
# Be sure to restart your server when you modify this file.
|
||
|
||
# These settings change the behavior of Rails 2 apps and will be defaults
|
||
# for Rails 3. You can remove this initializer when Rails 3 is released.
|
||
|
||
# Include Active Record class name as root for JSON serialized output.
|
||
ActiveRecord::Base.include_root_in_json = true
|
||
if defined?(ActiveRecord)
|
||
# Include Active Record class name as root for JSON serialized output.
|
||
ActiveRecord::Base.include_root_in_json = true
|
||
|
||
# Store the full class name (including module namespace) in STI type column.
|
||
ActiveRecord::Base.store_full_sti_class = true
|
||
end
|
||
|
||
# Store the full class name (including module namespace) in STI type column.
|
||
ActiveRecord::Base.store_full_sti_class = true
|
||
ActionController::Routing.generate_best_match = false
|
||
|
||
# Use ISO 8601 format for JSON serialized times and dates.
|
||
ActiveSupport.use_standard_json_time_format = true
|
config/initializers/session_store.rb | ||
---|---|---|
# Be sure to restart your server when you modify this file.
|
||
|
||
# Your secret key for verifying cookie session data integrity.
|
||
# If you change this key, all old sessions will become invalid!
|
||
# Make sure the secret is at least 30 characters and all random,
|
||
# no regular words or you'll be exposed to dictionary attacks.
|
||
ActionController::Base.session = {
|
||
:key => '_jmb_session',
|
||
:secret => 'c80b03ca37da9987a2f109b9d2eda82cd249bb36be4a0c4ae198f7744027b6f874f1809471f998f7b3108e50b979fa795adc6fab857c47f89287eae1a77b74ec'
|
||
}
|
||
|
||
# Use the database for sessions instead of the cookie-based default,
|
||
# which shouldn't be used to store highly confidential information
|
||
# (create the session table with "rake db:sessions:create")
|
||
# ActionController::Base.session_store = :active_record_store
|
public/javascripts/controls.js | ||
---|---|---|
// Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
||
// (c) 2005-2008 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
|
||
// (c) 2005-2008 Jon Tirsen (http://www.tirsen.com)
|
||
// (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
|
||
// (c) 2005-2007 Jon Tirsen (http://www.tirsen.com)
|
||
// Contributors:
|
||
// Richard Livsey
|
||
// Rahul Bhargava
|
||
// Rob Wills
|
||
//
|
||
//
|
||
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
||
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
||
|
||
// Autocompleter.Base handles all the autocompletion functionality
|
||
// Autocompleter.Base handles all the autocompletion functionality
|
||
// that's independent of the data source for autocompletion. This
|
||
// includes drawing the autocompletion menu, observing keyboard
|
||
// and mouse events, and similar.
|
||
//
|
||
// Specific autocompleters need to provide, at the very least,
|
||
// Specific autocompleters need to provide, at the very least,
|
||
// a getUpdatedChoices function that will be invoked every time
|
||
// the text inside the monitored textbox changes. This method
|
||
// the text inside the monitored textbox changes. This method
|
||
// should get the text for which to provide autocompletion by
|
||
// invoking this.getToken(), NOT by directly accessing
|
||
// this.element.value. This is to allow incremental tokenized
|
||
... | ... | |
// will incrementally autocomplete with a comma as the token.
|
||
// Additionally, ',' in the above example can be replaced with
|
||
// a token array, e.g. { tokens: [',', '\n'] } which
|
||
// enables autocompletion on multiple tokens. This is most
|
||
// useful when one of the tokens is \n (a newline), as it
|
||
// enables autocompletion on multiple tokens. This is most
|
||
// useful when one of the tokens is \n (a newline), as it
|
||
// allows smart autocompletion after linebreaks.
|
||
|
||
if(typeof Effect == 'undefined')
|
||
throw("controls.js requires including script.aculo.us' effects.js library");
|
||
|
||
var Autocompleter = { };
|
||
var Autocompleter = { }
|
||
Autocompleter.Base = Class.create({
|
||
baseInitialize: function(element, update, options) {
|
||
element = $(element);
|
||
this.element = element;
|
||
this.update = $(update);
|
||
this.hasFocus = false;
|
||
this.changed = false;
|
||
this.active = false;
|
||
this.index = 0;
|
||
element = $(element)
|
||
this.element = element;
|
||
this.update = $(update);
|
||
this.hasFocus = false;
|
||
this.changed = false;
|
||
this.active = false;
|
||
this.index = 0;
|
||
this.entryCount = 0;
|
||
this.oldElementValue = this.element.value;
|
||
|
||
... | ... | |
this.options.tokens = this.options.tokens || [];
|
||
this.options.frequency = this.options.frequency || 0.4;
|
||
this.options.minChars = this.options.minChars || 1;
|
||
this.options.onShow = this.options.onShow ||
|
||
function(element, update){
|
||
this.options.onShow = this.options.onShow ||
|
||
function(element, update){
|
||
if(!update.style.position || update.style.position=='absolute') {
|
||
update.style.position = 'absolute';
|
||
Position.clone(element, update, {
|
||
setHeight: false,
|
||
setHeight: false,
|
||
offsetTop: element.offsetHeight
|
||
});
|
||
}
|
||
Effect.Appear(update,{duration:0.15});
|
||
};
|
||
this.options.onHide = this.options.onHide ||
|
||
this.options.onHide = this.options.onHide ||
|
||
function(element, update){ new Effect.Fade(update,{duration:0.15}) };
|
||
|
||
if(typeof(this.options.tokens) == 'string')
|
||
if(typeof(this.options.tokens) == 'string')
|
||
this.options.tokens = new Array(this.options.tokens);
|
||
// Force carriage returns as token delimiters anyway
|
||
if (!this.options.tokens.include('\n'))
|
||
this.options.tokens.push('\n');
|
||
|
||
this.observer = null;
|
||
|
||
|
||
this.element.setAttribute('autocomplete','off');
|
||
|
||
Element.hide(this.update);
|
||
... | ... | |
|
||
show: function() {
|
||
if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
|
||
if(!this.iefix &&
|
||
if(!this.iefix &&
|
||
(Prototype.Browser.IE) &&
|
||
(Element.getStyle(this.update, 'position')=='absolute')) {
|
||
new Insertion.After(this.update,
|
||
new Insertion.After(this.update,
|
||
'<iframe id="' + this.update.id + '_iefix" '+
|
||
'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
|
||
'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
|
||
... | ... | |
}
|
||
if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
|
||
},
|
||
|
||
|
||
fixIEOverlapping: function() {
|
||
Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
|
||
this.iefix.style.zIndex = 1;
|
||
... | ... | |
Event.stop(event);
|
||
return;
|
||
}
|
||
else
|
||
if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
|
||
else
|
||
if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
|
||
(Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
|
||
|
||
this.changed = true;
|
||
this.hasFocus = true;
|
||
|
||
if(this.observer) clearTimeout(this.observer);
|
||
this.observer =
|
||
this.observer =
|
||
setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
|
||
},
|
||
|
||
... | ... | |
|
||
onHover: function(event) {
|
||
var element = Event.findElement(event, 'LI');
|
||
if(this.index != element.autocompleteIndex)
|
||
if(this.index != element.autocompleteIndex)
|
||
{
|
||
this.index = element.autocompleteIndex;
|
||
this.render();
|
||
}
|
||
Event.stop(event);
|
||
},
|
||
|
||
|
||
onClick: function(event) {
|
||
var element = Event.findElement(event, 'LI');
|
||
this.index = element.autocompleteIndex;
|
||
this.selectEntry();
|
||
this.hide();
|
||
},
|
||
|
||
|
||
onBlur: function(event) {
|
||
// needed to make click events working
|
||
setTimeout(this.hide.bind(this), 250);
|
||
this.hasFocus = false;
|
||
this.active = false;
|
||
},
|
||
|
||
this.active = false;
|
||
},
|
||
|
||
render: function() {
|
||
if(this.entryCount > 0) {
|
||
for (var i = 0; i < this.entryCount; i++)
|
||
this.index==i ?
|
||
Element.addClassName(this.getEntry(i),"selected") :
|
||
this.index==i ?
|
||
Element.addClassName(this.getEntry(i),"selected") :
|
||
Element.removeClassName(this.getEntry(i),"selected");
|
||
if(this.hasFocus) {
|
||
if(this.hasFocus) {
|
||
this.show();
|
||
this.active = true;
|
||
}
|
||
... | ... | |
this.hide();
|
||
}
|
||
},
|
||
|
||
|
||
markPrevious: function() {
|
||
if(this.index > 0) this.index--;
|
||
if(this.index > 0) this.index--
|
||
else this.index = this.entryCount-1;
|
||
this.getEntry(this.index).scrollIntoView(true);
|
||
},
|
||
|
||
|
||
markNext: function() {
|
||
if(this.index < this.entryCount-1) this.index++;
|
||
if(this.index < this.entryCount-1) this.index++
|
||
else this.index = 0;
|
||
this.getEntry(this.index).scrollIntoView(false);
|
||
},
|
||
|
||
|
||
getEntry: function(index) {
|
||
return this.update.firstChild.childNodes[index];
|
||
},
|
||
|
||
|
||
getCurrentEntry: function() {
|
||
return this.getEntry(this.index);
|
||
},
|
||
|
||
|
||
selectEntry: function() {
|
||
this.active = false;
|
||
this.updateElement(this.getCurrentEntry());
|
||
... | ... | |
if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
|
||
} else
|
||
value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
|
||
|
||
|
||
var bounds = this.getTokenBounds();
|
||
if (bounds[0] != -1) {
|
||
var newValue = this.element.value.substr(0, bounds[0]);
|
||
... | ... | |
}
|
||
this.oldElementValue = this.element.value;
|
||
this.element.focus();
|
||
|
||
|
||
if (this.options.afterUpdateElement)
|
||
this.options.afterUpdateElement(this.element, selectedElement);
|
||
},
|
||
... | ... | |
Element.cleanWhitespace(this.update.down());
|
||
|
||
if(this.update.firstChild && this.update.down().childNodes) {
|
||
this.entryCount =
|
||
this.entryCount =
|
||
this.update.down().childNodes.length;
|
||
for (var i = 0; i < this.entryCount; i++) {
|
||
var entry = this.getEntry(i);
|
||
entry.autocompleteIndex = i;
|
||
this.addObservers(entry);
|
||
}
|
||
} else {
|
||
} else {
|
||
this.entryCount = 0;
|
||
}
|
||
|
||
this.stopIndicator();
|
||
this.index = 0;
|
||
|
||
|
||
if(this.entryCount==1 && this.options.autoSelect) {
|
||
this.selectEntry();
|
||
this.hide();
|
||
... | ... | |
},
|
||
|
||
onObserverEvent: function() {
|
||
this.changed = false;
|
||
this.changed = false;
|
||
this.tokenBounds = null;
|
||
if(this.getToken().length>=this.options.minChars) {
|
||
this.getUpdatedChoices();
|
||
... | ... | |
|
||
getUpdatedChoices: function() {
|
||
this.startIndicator();
|
||
|
||
var entry = encodeURIComponent(this.options.paramName) + '=' +
|
||
|
||
var entry = encodeURIComponent(this.options.paramName) + '=' +
|
||
encodeURIComponent(this.getToken());
|
||
|
||
this.options.parameters = this.options.callback ?
|
||
this.options.callback(this.element, entry) : entry;
|
||
|
||
if(this.options.defaultParams)
|
||
if(this.options.defaultParams)
|
||
this.options.parameters += '&' + this.options.defaultParams;
|
||
|
||
|
||
new Ajax.Request(this.url, this.options);
|
||
},
|
||
|
||
... | ... | |
// - choices - How many autocompletion choices to offer
|
||
//
|
||
// - partialSearch - If false, the autocompleter will match entered
|
||
// text only at the beginning of strings in the
|
||
// text only at the beginning of strings in the
|
||
// autocomplete array. Defaults to true, which will
|
||
// match text at the beginning of any *word* in the
|
||
// strings in the autocomplete array. If you want to
|
||
... | ... | |
// - ignoreCase - Whether to ignore case when autocompleting.
|
||
// Defaults to true.
|
||
//
|
||
// It's possible to pass in a custom function as the 'selector'
|
||
// It's possible to pass in a custom function as the 'selector'
|
||
// option, if you prefer to write your own autocompletion logic.
|
||
// In that case, the other options above will not apply unless
|
||
// you support them.
|
||
... | ... | |
var entry = instance.getToken();
|
||
var count = 0;
|
||
|
||
for (var i = 0; i < instance.options.array.length &&
|
||
ret.length < instance.options.choices ; i++) {
|
||
for (var i = 0; i < instance.options.array.length &&
|
||
ret.length < instance.options.choices ; i++) {
|
||
|
||
var elem = instance.options.array[i];
|
||
var foundPos = instance.options.ignoreCase ?
|
||
elem.toLowerCase().indexOf(entry.toLowerCase()) :
|
||
var foundPos = instance.options.ignoreCase ?
|
||
elem.toLowerCase().indexOf(entry.toLowerCase()) :
|
||
elem.indexOf(entry);
|
||
|
||
while (foundPos != -1) {
|
||
if (foundPos == 0 && elem.length != entry.length) {
|
||
ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
|
||
if (foundPos == 0 && elem.length != entry.length) {
|
||
ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
|
||
elem.substr(entry.length) + "</li>");
|
||
break;
|
||
} else if (entry.length >= instance.options.partialChars &&
|
||
} else if (entry.length >= instance.options.partialChars &&
|
||
instance.options.partialSearch && foundPos != -1) {
|
||
if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
|
||
partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
|
||
... | ... | |
}
|
||
}
|
||
|
||
foundPos = instance.options.ignoreCase ?
|
||
elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
|
||
foundPos = instance.options.ignoreCase ?
|
||
elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
|
||
elem.indexOf(entry, foundPos + 1);
|
||
|
||
}
|
||
}
|
||
if (partial.length)
|
||
ret = ret.concat(partial.slice(0, instance.options.choices - ret.length));
|
||
ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
|
||
return "<ul>" + ret.join('') + "</ul>";
|
||
}
|
||
}, options || { });
|
||
... | ... | |
setTimeout(function() {
|
||
Field.activate(field);
|
||
}, 1);
|
||
};
|
||
}
|
||
|
||
Ajax.InPlaceEditor = Class.create({
|
||
initialize: function(element, url, options) {
|
||
... | ... | |
this.triggerCallback('onEnterHover');
|
||
},
|
||
getText: function() {
|
||
return this.element.innerHTML.unescapeHTML();
|
||
return this.element.innerHTML;
|
||
},
|
||
handleAJAXFailure: function(transport) {
|
||
this.triggerCallback('onFailure', transport);
|
||
... | ... | |
onSuccess: function(transport) {
|
||
var js = transport.responseText.strip();
|
||
if (!/^\[.*\]$/.test(js)) // TODO: improve sanity check
|
||
throw('Server returned an invalid collection representation.');
|
||
throw 'Server returned an invalid collection representation.';
|
||
this._collection = eval(js);
|
||
this.checkForExternalText();
|
||
}.bind(this),
|
||
... | ... | |
loadingCollectionText: 'Loading options...'
|
||
};
|
||
|
||
// Delayed observer, like Form.Element.Observer,
|
||
// Delayed observer, like Form.Element.Observer,
|
||
// but waits for delay after last key input
|
||
// Ideal for live-search fields
|
||
|
||
... | ... | |
this.element = $(element);
|
||
this.callback = callback;
|
||
this.timer = null;
|
||
this.lastValue = $F(this.element);
|
||
this.lastValue = $F(this.element);
|
||
Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));
|
||
},
|
||
delayedListener: function(event) {
|
||
... | ... | |
this.timer = null;
|
||
this.callback(this.element, $F(this.element));
|
||
}
|
||
});
|
||
});
|
public/javascripts/dragdrop.js | ||
---|---|---|
// Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
||
// (c) 2005-2008 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
|
||
//
|
||
// (c) 2005-2007 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
|
||
//
|
||
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
||
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
||
|
||
... | ... | |
options._containers.push($(containment));
|
||
}
|
||
}
|
||
|
||
|
||
if(options.accept) options.accept = [options.accept].flatten();
|
||
|
||
Element.makePositioned(element); // fix IE
|
||
... | ... | |
|
||
this.drops.push(options);
|
||
},
|
||
|
||
|
||
findDeepestChild: function(drops) {
|
||
deepest = drops[0];
|
||
|
||
|
||
for (i = 1; i < drops.length; ++i)
|
||
if (Element.isParent(drops[i].element, deepest.element))
|
||
deepest = drops[i];
|
||
|
||
|
||
return deepest;
|
||
},
|
||
|
||
isContained: function(element, drop) {
|
||
var containmentNode;
|
||
if(drop.tree) {
|
||
containmentNode = element.treeNode;
|
||
containmentNode = element.treeNode;
|
||
} else {
|
||
containmentNode = element.parentNode;
|
||
}
|
||
return drop._containers.detect(function(c) { return containmentNode == c });
|
||
},
|
||
|
||
|
||
isAffected: function(point, element, drop) {
|
||
return (
|
||
(drop.element!=element) &&
|
||
((!drop._containers) ||
|
||
this.isContained(element, drop)) &&
|
||
((!drop.accept) ||
|
||
(Element.classNames(element).detect(
|
||
(Element.classNames(element).detect(
|
||
function(v) { return drop.accept.include(v) } ) )) &&
|
||
Position.within(drop.element, point[0], point[1]) );
|
||
},
|
||
... | ... | |
show: function(point, element) {
|
||
if(!this.drops.length) return;
|
||
var drop, affected = [];
|
||
|
||
|
||
this.drops.each( function(drop) {
|
||
if(Droppables.isAffected(point, element, drop))
|
||
affected.push(drop);
|
||
});
|
||
|
||
|
||
if(affected.length>0)
|
||
drop = Droppables.findDeepestChild(affected);
|
||
|
||
... | ... | |
Position.within(drop.element, point[0], point[1]);
|
||
if(drop.onHover)
|
||
drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element));
|
||
|
||
|
||
if (drop != this.last_active) Droppables.activate(drop);
|
||
}
|
||
},
|
||
... | ... | |
|
||
if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active))
|
||
if (this.last_active.onDrop) {
|
||
this.last_active.onDrop(element, this.last_active.element, event);
|
||
return true;
|
||
this.last_active.onDrop(element, this.last_active.element, event);
|
||
return true;
|
||
}
|
||
},
|
||
|
||
... | ... | |
if(this.last_active)
|
||
this.deactivate(this.last_active);
|
||
}
|
||
};
|
||
}
|
||
|
||
var Draggables = {
|
||
drags: [],
|
||
observers: [],
|
||
|
||
|
||
register: function(draggable) {
|
||
if(this.drags.length == 0) {
|
||
this.eventMouseUp = this.endDrag.bindAsEventListener(this);
|
||
this.eventMouseMove = this.updateDrag.bindAsEventListener(this);
|
||
this.eventKeypress = this.keyPress.bindAsEventListener(this);
|
||
|
||
|
||
Event.observe(document, "mouseup", this.eventMouseUp);
|
||
Event.observe(document, "mousemove", this.eventMouseMove);
|
||
Event.observe(document, "keypress", this.eventKeypress);
|
||
}
|
||
this.drags.push(draggable);
|
||
},
|
||
|
||
|
||
unregister: function(draggable) {
|
||
this.drags = this.drags.reject(function(d) { return d==draggable });
|
||
if(this.drags.length == 0) {
|
||
... | ... | |
Event.stopObserving(document, "keypress", this.eventKeypress);
|
||
}
|
||
},
|
||
|
||
|
||
activate: function(draggable) {
|
||
if(draggable.options.delay) {
|
||
this._timeout = setTimeout(function() {
|
||
Draggables._timeout = null;
|
||
window.focus();
|
||
Draggables.activeDraggable = draggable;
|
||
}.bind(this), draggable.options.delay);
|
||
if(draggable.options.delay) {
|
||
this._timeout = setTimeout(function() {
|
||
Draggables._timeout = null;
|
||
window.focus();
|
||
Draggables.activeDraggable = draggable;
|
||
}.bind(this), draggable.options.delay);
|
||
} else {
|
||
window.focus(); // allows keypress events if window isn't currently focused, fails for Safari
|
||
this.activeDraggable = draggable;
|
||
}
|
||
},
|
||
|
||
|
||
deactivate: function() {
|
||
this.activeDraggable = null;
|
||
},
|
||
|
||
|
||
updateDrag: function(event) {
|
||
if(!this.activeDraggable) return;
|
||
var pointer = [Event.pointerX(event), Event.pointerY(event)];
|
||
... | ... | |
// the same coordinates, prevent needless redrawing (moz bug?)
|
||
if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return;
|
||
this._lastPointer = pointer;
|
||
|
||
|
||
this.activeDraggable.updateDrag(event, pointer);
|
||
},
|
||
|
||
|
||
endDrag: function(event) {
|
||
if(this._timeout) {
|
||
clearTimeout(this._timeout);
|
||
this._timeout = null;
|
||
if(this._timeout) {
|
||
clearTimeout(this._timeout);
|
||
this._timeout = null;
|
||
}
|
||
if(!this.activeDraggable) return;
|
||
this._lastPointer = null;
|
||
this.activeDraggable.endDrag(event);
|
||
this.activeDraggable = null;
|
||
},
|
||
|
||
|
||
keyPress: function(event) {
|
||
if(this.activeDraggable)
|
||
this.activeDraggable.keyPress(event);
|
||
},
|
||
|
||
|
||
addObserver: function(observer) {
|
||
this.observers.push(observer);
|
||
this._cacheObserverCallbacks();
|
||
},
|
||
|
||
|
||
removeObserver: function(element) { // element instead of observer fixes mem leaks
|
||
this.observers = this.observers.reject( function(o) { return o.element==element });
|
||
this._cacheObserverCallbacks();
|
||
},
|
||
|
||
|
||
notify: function(eventName, draggable, event) { // 'onStart', 'onEnd', 'onDrag'
|
||
if(this[eventName+'Count'] > 0)
|
||
this.observers.each( function(o) {
|
||
... | ... | |
});
|
||
if(draggable.options[eventName]) draggable.options[eventName](draggable, event);
|
||
},
|
||
|
||
|
||
_cacheObserverCallbacks: function() {
|
||
['onStart','onEnd','onDrag'].each( function(eventName) {
|
||
Draggables[eventName+'Count'] = Draggables.observers.select(
|
||
... | ... | |
).length;
|
||
});
|
||
}
|
||
};
|
||
}
|
||
|
||
/*--------------------------------------------------------------------------*/
|
||
|
||
... | ... | |
},
|
||
endeffect: function(element) {
|
||
var toOpacity = Object.isNumber(element._opacity) ? element._opacity : 1.0;
|
||
new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
|
||
new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
|
||
queue: {scope:'_draggable', position:'end'},
|
||
afterFinish: function(){
|
||
Draggable._dragging[element] = false
|
||
afterFinish: function(){
|
||
Draggable._dragging[element] = false
|
||
}
|
||
});
|
||
});
|
||
},
|
||
zindex: 1000,
|
||
revert: false,
|
||
... | ... | |
snap: false, // false, or xy or [x,y] or function(x,y){ return [x,y] }
|
||
delay: 0
|
||
};
|
||
|
||
|
||
if(!arguments[1] || Object.isUndefined(arguments[1].endeffect))
|
||
Object.extend(defaults, {
|
||
starteffect: function(element) {
|
||
element._opacity = Element.getOpacity(element);
|
||
Draggable._dragging[element] = true;
|
||
new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
|
||
new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
|
||
}
|
||
});
|
||
|
||
|
||
var options = Object.extend(defaults, arguments[1] || { });
|
||
|
||
this.element = $(element);
|
||
|
||
|
||
if(options.handle && Object.isString(options.handle))
|
||
this.handle = this.element.down('.'+options.handle, 0);
|
||
|
||
|
||
if(!this.handle) this.handle = $(options.handle);
|
||
if(!this.handle) this.handle = this.element;
|
||
|
||
|
||
if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) {
|
||
options.scroll = $(options.scroll);
|
||
this._isScrollChild = Element.childOf(this.element, options.scroll);
|
||
}
|
||
|
||
Element.makePositioned(this.element); // fix IE
|
||
Element.makePositioned(this.element); // fix IE
|
||
|
||
this.options = options;
|
||
this.dragging = false;
|
||
this.dragging = false;
|
||
|
||
this.eventMouseDown = this.initDrag.bindAsEventListener(this);
|
||
Event.observe(this.handle, "mousedown", this.eventMouseDown);
|
||
|
||
|
||
Draggables.register(this);
|
||
},
|
||
|
||
|
||
destroy: function() {
|
||
Event.stopObserving(this.handle, "mousedown", this.eventMouseDown);
|
||
Draggables.unregister(this);
|
||
},
|
||
|
||
|
||
currentDelta: function() {
|
||
return([
|
||
parseInt(Element.getStyle(this.element,'left') || '0'),
|
||
parseInt(Element.getStyle(this.element,'top') || '0')]);
|
||
},
|
||
|
||
|
||
initDrag: function(event) {
|
||
if(!Object.isUndefined(Draggable._dragging[this.element]) &&
|
||
Draggable._dragging[this.element]) return;
|
||
if(Event.isLeftClick(event)) {
|
||
if(Event.isLeftClick(event)) {
|
||
// abort on form elements, fixes a Firefox issue
|
||
var src = Event.element(event);
|
||
if((tag_name = src.tagName.toUpperCase()) && (
|
||
... | ... | |
tag_name=='OPTION' ||
|
||
tag_name=='BUTTON' ||
|
||
tag_name=='TEXTAREA')) return;
|
||
|
||
|
||
var pointer = [Event.pointerX(event), Event.pointerY(event)];
|
||
var pos = Position.cumulativeOffset(this.element);
|
||
this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) });
|
||
|
||
|
||
Draggables.activate(this);
|
||
Event.stop(event);
|
||
}
|
||
},
|
||
|
||
|
||
startDrag: function(event) {
|
||
this.dragging = true;
|
||
if(!this.delta)
|
||
this.delta = this.currentDelta();
|
||
|
||
|
||
if(this.options.zindex) {
|
||
this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0);
|
||
this.element.style.zIndex = this.options.zindex;
|
||
}
|
||
|
||
|
||
if(this.options.ghosting) {
|
||
this._clone = this.element.cloneNode(true);
|
||
this._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
|
||
if (!this._originallyAbsolute)
|
||
this.element._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
|
||
if (!this.element._originallyAbsolute)
|
||
Position.absolutize(this.element);
|
||
this.element.parentNode.insertBefore(this._clone, this.element);
|
||
}
|
||
|
||
|
||
if(this.options.scroll) {
|
||
if (this.options.scroll == window) {
|
||
var where = this._getWindowScroll(this.options.scroll);
|
||
... | ... | |
this.originalScrollTop = this.options.scroll.scrollTop;
|
||
}
|
||
}
|
||
|
||
|
||
Draggables.notify('onStart', this, event);
|
||
|
||
|
||
if(this.options.starteffect) this.options.starteffect(this.element);
|
||
},
|
||
|
||
|
||
updateDrag: function(event, pointer) {
|
||
if(!this.dragging) this.startDrag(event);
|
||
|
||
|
||
if(!this.options.quiet){
|
||
Position.prepare();
|
||
Droppables.show(pointer, this.element);
|
||
}
|
||
|
||
|
||
Draggables.notify('onDrag', this, event);
|
||
|
||
|
||
this.draw(pointer);
|
||
if(this.options.change) this.options.change(this);
|
||
|
||
|
||
if(this.options.scroll) {
|
||
this.stopScrolling();
|
||
|
||
|
||
var p;
|
||
if (this.options.scroll == window) {
|
||
with(this._getWindowScroll(this.options.scroll)) { p = [ left, top, left+width, top+height ]; }
|
||
... | ... | |
if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity);
|
||
this.startScrolling(speed);
|
||
}
|
||
|
||
|
||
// fix AppleWebKit rendering
|
||
if(Prototype.Browser.WebKit) window.scrollBy(0,0);
|
||
|
||
|
||
Event.stop(event);
|
||
},
|
||
|
||
|
||
finishDrag: function(event, success) {
|
||
this.dragging = false;
|
||
|
||
|
||
if(this.options.quiet){
|
||
Position.prepare();
|
||
var pointer = [Event.pointerX(event), Event.pointerY(event)];
|
||
... | ... | |
}
|
||
|
||
if(this.options.ghosting) {
|
||
if (!this._originallyAbsolute)
|
||
if (!this.element._originallyAbsolute)
|
||
Position.relativize(this.element);
|
||
delete this._originallyAbsolute;
|
||
delete this.element._originallyAbsolute;
|
||
Element.remove(this._clone);
|
||
this._clone = null;
|
||
}
|
||
|
||
var dropped = false;
|
||
if(success) {
|
||
dropped = Droppables.fire(event, this.element);
|
||
if (!dropped) dropped = false;
|
||
var dropped = false;
|
||
if(success) {
|
||
dropped = Droppables.fire(event, this.element);
|
||
if (!dropped) dropped = false;
|
||
}
|
||
if(dropped && this.options.onDropped) this.options.onDropped(this.element);
|
||
Draggables.notify('onEnd', this, event);
|
||
|
||
var revert = this.options.revert;
|
||
if(revert && Object.isFunction(revert)) revert = revert(this.element);
|
||
|
||
|
||
var d = this.currentDelta();
|
||
if(revert && this.options.reverteffect) {
|
||
if (dropped == 0 || revert != 'failure')
|
||
... | ... | |
if(this.options.zindex)
|
||
this.element.style.zIndex = this.originalZ;
|
||
|
||
if(this.options.endeffect)
|
||
if(this.options.endeffect)
|
||
this.options.endeffect(this.element);
|
||
|
||
|
||
Draggables.deactivate(this);
|
||
Droppables.reset();
|
||
},
|
||
|
||
|
||
keyPress: function(event) {
|
||
if(event.keyCode!=Event.KEY_ESC) return;
|
||
this.finishDrag(event, false);
|
||
Event.stop(event);
|
||
},
|
||
|
||
|
||
endDrag: function(event) {
|
||
if(!this.dragging) return;
|
||
this.stopScrolling();
|
||
this.finishDrag(event, true);
|
||
Event.stop(event);
|
||
},
|
||
|
||
|
||
draw: function(point) {
|
||
var pos = Position.cumulativeOffset(this.element);
|
||
if(this.options.ghosting) {
|
||
var r = Position.realOffset(this.element);
|
||
pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY;
|
||
}
|
||
|
||
|
||
var d = this.currentDelta();
|
||
pos[0] -= d[0]; pos[1] -= d[1];
|
||
|
||
|
||
if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) {
|
||
pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft;
|
||
pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop;
|
||
}
|
||
|
||
var p = [0,1].map(function(i){
|
||
return (point[i]-pos[i]-this.offset[i])
|
||
|
||
var p = [0,1].map(function(i){
|
||
return (point[i]-pos[i]-this.offset[i])
|
||
}.bind(this));
|
||
|
||
|
||
if(this.options.snap) {
|
||
if(Object.isFunction(this.options.snap)) {
|
||
p = this.options.snap(p[0],p[1],this);
|
||
} else {
|
||
if(Object.isArray(this.options.snap)) {
|
||
p = p.map( function(v, i) {
|
||
return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this));
|
||
return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this))
|
||
} else {
|
||
p = p.map( function(v) {
|
||
return (v/this.options.snap).round()*this.options.snap }.bind(this));
|
||
return (v/this.options.snap).round()*this.options.snap }.bind(this))
|
||
}
|
||
}}
|
||
|
||
|
||
var style = this.element.style;
|
||
if((!this.options.constraint) || (this.options.constraint=='horizontal'))
|
||
style.left = p[0] + "px";
|
||
if((!this.options.constraint) || (this.options.constraint=='vertical'))
|
||
style.top = p[1] + "px";
|
||
|
||
|
||
if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
|
||
},
|
||
|
||
|
||
stopScrolling: function() {
|
||
if(this.scrollInterval) {
|
||
clearInterval(this.scrollInterval);
|
||
... | ... | |
Draggables._lastScrollPointer = null;
|
||
}
|
||
},
|
||
|
||
|
||
startScrolling: function(speed) {
|
||
if(!(speed[0] || speed[1])) return;
|
||
this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed];
|
||
this.lastScrolled = new Date();
|
||
this.scrollInterval = setInterval(this.scroll.bind(this), 10);
|
||
},
|
||
|
||
|
||
scroll: function() {
|
||
var current = new Date();
|
||
var delta = current - this.lastScrolled;
|
||
... | ... | |
this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000;
|
||
this.options.scroll.scrollTop += this.scrollSpeed[1] * delta / 1000;
|
||
}
|
||
|
||
|
||
Position.prepare();
|
||
Droppables.show(Draggables._lastPointer, this.element);
|
||
Draggables.notify('onDrag', this);
|
||
... | ... | |
Draggables._lastScrollPointer[1] = 0;
|
||
this.draw(Draggables._lastScrollPointer);
|
||
}
|
||
|
||
|
||
if(this.options.change) this.options.change(this);
|
||
},
|
||
|
||
|
||
_getWindowScroll: function(w) {
|
||
var T, L, W, H;
|
||
with (w.document) {
|
||
... | ... | |
H = documentElement.clientHeight;
|
||
} else {
|
||
W = body.offsetWidth;
|
||
H = body.offsetHeight;
|
||
H = body.offsetHeight
|
||
}
|
||
}
|
||
return { top: T, left: L, width: W, height: H };
|
||
... | ... | |
this.observer = observer;
|
||
this.lastValue = Sortable.serialize(this.element);
|
||
},
|
||
|
||
|
||
onStart: function() {
|
||
this.lastValue = Sortable.serialize(this.element);
|
||
},
|
||
|
||
|
||
onEnd: function() {
|
||
Sortable.unmark();
|
||
if(this.lastValue != Sortable.serialize(this.element))
|
||
... | ... | |
|
||
var Sortable = {
|
||
SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/,
|
||
|
||
|
||
sortables: { },
|
||
|
||
|
||
_findRootElement: function(element) {
|
||
while (element.tagName.toUpperCase() != "BODY") {
|
||
while (element.tagName.toUpperCase() != "BODY") {
|
||
if(element.id && Sortable.sortables[element.id]) return element;
|
||
element = element.parentNode;
|
||
}
|
||
... | ... | |
if(!element) return;
|
||
return Sortable.sortables[element.id];
|
||
},
|
||
|
||
|
||
destroy: function(element){
|
||
element = $(element);
|
||
var s = Sortable.sortables[element.id];
|
||
|
||
var s = Sortable.options(element);
|
||
|
||
if(s) {
|
||
Draggables.removeObserver(s.element);
|
||
s.droppables.each(function(d){ Droppables.remove(d) });
|
||
s.draggables.invoke('destroy');
|
||
|
||
|
||
delete Sortable.sortables[s.element.id];
|
||
}
|
||
},
|
||
|
||
create: function(element) {
|
||
element = $(element);
|
||
var options = Object.extend({
|
||
var options = Object.extend({
|
||
element: element,
|
||
tag: 'li', // assumes li children, override with tag: 'tagname'
|
||
dropOnEmpty: false,
|
||
... | ... | |
delay: 0,
|
||
hoverclass: null,
|
||
ghosting: false,
|
||
quiet: false,
|
||
quiet: false,
|
||
scroll: false,
|
||
scrollSensitivity: 20,
|
||
scrollSpeed: 15,
|
||
format: this.SERIALIZE_RULE,
|
||
|
||
// these take arrays of elements or ids and can be
|
||
|
||
// these take arrays of elements or ids and can be
|
||
// used for better initialization performance
|
||
elements: false,
|
||
handles: false,
|
||
|
||
|
||
onChange: Prototype.emptyFunction,
|
||
onUpdate: Prototype.emptyFunction
|
||
}, arguments[1] || { });
|
||
... | ... | |
if(options.zindex)
|
||
options_for_draggable.zindex = options.zindex;
|
||
|
||
// build options for the droppables
|
||
// build options for the droppables
|
||
var options_for_droppable = {
|
||
overlap: options.overlap,
|
||
containment: options.containment,
|
||
tree: options.tree,
|
||
hoverclass: options.hoverclass,
|
||
onHover: Sortable.onHover
|
||
};
|
||
|
||
}
|
||
|
||
var options_for_tree = {
|
||
onHover: Sortable.onEmptyHover,
|
||
overlap: options.overlap,
|
||
containment: options.containment,
|
||
hoverclass: options.hoverclass
|
||
};
|
||
}
|
||
|
Also available in: Unified diff
[evol] migration to libgettext-ruby 2.1.0 and split rails 2.3.5, step #1