mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-21 09:40:13 +01:00
Removed superfluous 'tracks' directory at the root of the repository.
Testing commits to github.
This commit is contained in:
parent
6a42901514
commit
4cbf5a34d3
2269 changed files with 0 additions and 0 deletions
58
vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_script.rb
vendored
Normal file
58
vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_script.rb
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
class UJS::BehaviourScript
|
||||
attr_reader :rules
|
||||
attr_writer :reapply_after_ajax
|
||||
|
||||
def initialize(cache=false, reapply_after_ajax=true)
|
||||
@rules, @cache, @reapply_after_ajax = [], cache, reapply_after_ajax
|
||||
end
|
||||
|
||||
def add_rule(selector, javascript, cancel_default=false)
|
||||
javascript = javascript << cancel_default_js if cancel_default
|
||||
@rules << [selector, javascript] unless rule_exists(selector, javascript)
|
||||
end
|
||||
|
||||
def cache?
|
||||
@cache
|
||||
end
|
||||
|
||||
def enable_cache
|
||||
@cache = true
|
||||
end
|
||||
|
||||
def reapply_after_ajax?
|
||||
@reapply_after_ajax
|
||||
end
|
||||
|
||||
# Renders behaviour block and option JavaScript.
|
||||
def to_s
|
||||
(@rules && !@rules.empty?) ? "Event.addBehavior({\n#{rule_js}\n});" + option_js : ''
|
||||
end
|
||||
|
||||
# Uses behaviour script converter to conver to a hash for session storage
|
||||
def to_hash
|
||||
UJS::BehaviourScriptConverter.convert_to_hash(self)
|
||||
end
|
||||
|
||||
protected
|
||||
# Renders a collection of behaviour rules in javascript format
|
||||
def rule_js
|
||||
@rules.uniq.collect { |sel, js| behaviour_rule(sel, js) }.join(",\n")
|
||||
end
|
||||
|
||||
# Renders behaviour rule javascript for the behaviours file
|
||||
def behaviour_rule(selector, behaviour)
|
||||
"\"#{selector}\": function(event) {\n#{behaviour}\n}"
|
||||
end
|
||||
|
||||
def option_js
|
||||
reapply_after_ajax? ? '' : "\nEvent.addBehavior.reapplyAfterAjax = false;"
|
||||
end
|
||||
|
||||
def cancel_default_js
|
||||
" return false;"
|
||||
end
|
||||
|
||||
def rule_exists(selector, javascript)
|
||||
@rules.detect{|r| r[0] == selector && r[1] == javascript} != nil
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue