talia_core 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +4 -0
- data/config/database.yml +19 -0
- data/config/database.yml.example +35 -0
- data/config/rdfstore.yml +13 -0
- data/config/rdfstore.yml.example +13 -0
- data/config/rdfstore.yml.rdflite_example +16 -0
- data/config/rdfstore.yml.redland_example +46 -0
- data/config/talia_core.yml +14 -0
- data/config/talia_core.yml.example +42 -0
- data/generators/generator_helpers.rb +49 -0
- data/generators/talia_admin/USAGE +1 -0
- data/generators/talia_admin/talia_admin_generator.rb +19 -0
- data/generators/talia_admin/templates/controllers/admin/background_controller.rb +50 -0
- data/generators/talia_admin/templates/controllers/admin/custom_templates_controller.rb +25 -0
- data/generators/talia_admin/templates/controllers/admin/locales_controller.rb +15 -0
- data/generators/talia_admin/templates/controllers/admin/sources_controller.rb +71 -0
- data/generators/talia_admin/templates/controllers/admin/translations_controller.rb +61 -0
- data/generators/talia_admin/templates/controllers/admin/users_controller.rb +48 -0
- data/generators/talia_admin/templates/controllers/admin_controller.rb +7 -0
- data/generators/talia_admin/templates/helpers/admin/background_helper.rb +60 -0
- data/generators/talia_admin/templates/helpers/admin/custom_templates_helper.rb +5 -0
- data/generators/talia_admin/templates/helpers/admin/locales_helper.rb +2 -0
- data/generators/talia_admin/templates/helpers/admin/sources_helper.rb +65 -0
- data/generators/talia_admin/templates/helpers/admin/translations_helper.rb +51 -0
- data/generators/talia_admin/templates/helpers/admin/users_helper.rb +2 -0
- data/generators/talia_admin/templates/helpers/admin_helper.rb +11 -0
- data/generators/talia_admin/templates/public/images/backend/body_bg.gif +0 -0
- data/generators/talia_admin/templates/public/images/backend/footer_bg.gif +0 -0
- data/generators/talia_admin/templates/public/images/backend/header.jpg +0 -0
- data/generators/talia_admin/templates/public/images/backend/header_bg.gif +0 -0
- data/generators/talia_admin/templates/public/images/backend/menu.jpg +0 -0
- data/generators/talia_admin/templates/public/images/backend/menu_bg.gif +0 -0
- data/generators/talia_admin/templates/public/images/backend/opednid.gif +0 -0
- data/generators/talia_admin/templates/public/images/backend/page_bg.jpg +0 -0
- data/generators/talia_admin/templates/public/images/backend/triangolino.gif +0 -0
- data/generators/talia_admin/templates/public/images/backend/triangolino_full.gif +0 -0
- data/generators/talia_admin/templates/public/javascripts/backend.js +24 -0
- data/generators/talia_admin/templates/public/javascripts/lowpro.js +321 -0
- data/generators/talia_admin/templates/public/stylesheets/backend.css +466 -0
- data/generators/talia_admin/templates/test/fixtures/users.yml +32 -0
- data/generators/talia_admin/templates/test/functional/admin/custom_templates_controller_test.rb +8 -0
- data/generators/talia_admin/templates/test/functional/admin/locales_controller_test.rb +35 -0
- data/generators/talia_admin/templates/test/functional/admin/sources_controller_test.rb +109 -0
- data/generators/talia_admin/templates/test/functional/admin/translations_controller_test.rb +93 -0
- data/generators/talia_admin/templates/test/functional/admin/users_controller_test.rb +67 -0
- data/generators/talia_admin/templates/test/functional/admin_controller_test.rb +15 -0
- data/generators/talia_admin/templates/test/unit/user_test.rb +134 -0
- data/generators/talia_admin/templates/views/admin/background/_finished.html.erb +9 -0
- data/generators/talia_admin/templates/views/admin/background/_pending.html.erb +1 -0
- data/generators/talia_admin/templates/views/admin/background/_progress.html.erb +15 -0
- data/generators/talia_admin/templates/views/admin/background/_running.html.erb +11 -0
- data/generators/talia_admin/templates/views/admin/background/environment.html.erb +12 -0
- data/generators/talia_admin/templates/views/admin/background/show.html.erb +17 -0
- data/generators/talia_admin/templates/views/admin/background/stderr.html.erb +6 -0
- data/generators/talia_admin/templates/views/admin/background/stdin.html.erb +6 -0
- data/generators/talia_admin/templates/views/admin/background/stdout.html.erb +6 -0
- data/generators/talia_admin/templates/views/admin/custom_templates/_content_form_column.rhtml +2 -0
- data/generators/talia_admin/templates/views/admin/custom_templates/_template_type_form_column.rhtml +2 -0
- data/generators/talia_admin/templates/views/admin/index.html.erb +5 -0
- data/generators/talia_admin/templates/views/admin/locales/new.html.erb +9 -0
- data/generators/talia_admin/templates/views/admin/sources/_data.html.erb +6 -0
- data/generators/talia_admin/templates/views/admin/sources/_data_form.html.erb +15 -0
- data/generators/talia_admin/templates/views/admin/sources/_form.html.erb +7 -0
- data/generators/talia_admin/templates/views/admin/sources/_list.html.erb +3 -0
- data/generators/talia_admin/templates/views/admin/sources/_notice.html.erb +1 -0
- data/generators/talia_admin/templates/views/admin/sources/_predicate.html.erb +22 -0
- data/generators/talia_admin/templates/views/admin/sources/_predicates.html.erb +15 -0
- data/generators/talia_admin/templates/views/admin/sources/_sources.html.erb +17 -0
- data/generators/talia_admin/templates/views/admin/sources/_upload.html.erb +6 -0
- data/generators/talia_admin/templates/views/admin/sources/edit.html.erb +6 -0
- data/generators/talia_admin/templates/views/admin/sources/index.html.erb +5 -0
- data/generators/talia_admin/templates/views/admin/translations/_new_translation.html.erb +7 -0
- data/generators/talia_admin/templates/views/admin/translations/_translation.html.erb +10 -0
- data/generators/talia_admin/templates/views/admin/translations/edit.html.erb +16 -0
- data/generators/talia_admin/templates/views/admin/users/_form.html.erb +10 -0
- data/generators/talia_admin/templates/views/admin/users/_form_roles.html.erb +8 -0
- data/generators/talia_admin/templates/views/admin/users/edit.html.erb +12 -0
- data/generators/talia_admin/templates/views/admin/users/index.html.erb +22 -0
- data/generators/talia_admin/templates/views/admin/users/new.html.erb +5 -0
- data/generators/talia_admin/templates/views/admin/users/show.html.erb +6 -0
- data/generators/talia_admin/templates/views/layouts/admin.html.erb +56 -0
- data/generators/talia_base/USAGE +5 -0
- data/generators/talia_base/talia_base_generator.rb +62 -0
- data/generators/talia_base/templates/app/controllers/custom_templates_controller.rb +27 -0
- data/generators/talia_base/templates/app/controllers/ontologies_controller.rb +13 -0
- data/generators/talia_base/templates/app/controllers/sessions_controller.rb +90 -0
- data/generators/talia_base/templates/app/controllers/source_data/show.html.erb +2 -0
- data/generators/talia_base/templates/app/controllers/source_data_controller.rb +43 -0
- data/generators/talia_base/templates/app/controllers/sources_controller.rb +62 -0
- data/generators/talia_base/templates/app/controllers/types_controller.rb +23 -0
- data/generators/talia_base/templates/app/helpers/custom_templates_helper.rb +2 -0
- data/generators/talia_base/templates/app/helpers/ontologies_helper.rb +2 -0
- data/generators/talia_base/templates/app/helpers/sessions_helper.rb +2 -0
- data/generators/talia_base/templates/app/helpers/source_data/show.html.erb +2 -0
- data/generators/talia_base/templates/app/helpers/source_data_helper.rb +2 -0
- data/generators/talia_base/templates/app/helpers/sources_helper.rb +39 -0
- data/generators/talia_base/templates/app/helpers/types_helper.rb +2 -0
- data/generators/talia_base/templates/app/views/ontologies/index.builder +10 -0
- data/generators/talia_base/templates/app/views/ontologies/show.builder +7 -0
- data/generators/talia_base/templates/app/views/sessions/new.html.erb +33 -0
- data/generators/talia_base/templates/app/views/source_data/show.html.erb +2 -0
- data/generators/talia_base/templates/app/views/sources/_form.html.erb +15 -0
- data/generators/talia_base/templates/app/views/sources/edit.html.erb +9 -0
- data/generators/talia_base/templates/app/views/sources/index.html.erb +2 -0
- data/generators/talia_base/templates/app/views/sources/new.html.erb +8 -0
- data/generators/talia_base/templates/app/views/sources/show.html.erb +19 -0
- data/generators/talia_base/templates/app/views/types/index.html.erb +4 -0
- data/generators/talia_base/templates/app/views/types/show.html.erb +3 -0
- data/generators/talia_base/templates/config/routes.rb +83 -0
- data/generators/talia_base/templates/config/talia_initializer.rb +8 -0
- data/generators/talia_base/templates/migrations/bj_migration.rb +10 -0
- data/generators/talia_base/templates/migrations/constraint_migration.rb +24 -0
- data/generators/talia_base/templates/migrations/create_active_sources.rb +15 -0
- data/generators/talia_base/templates/migrations/create_custom_templates.rb +17 -0
- data/generators/talia_base/templates/migrations/create_data_records.rb +27 -0
- data/generators/talia_base/templates/migrations/create_open_id.rb +26 -0
- data/generators/talia_base/templates/migrations/create_progress_jobs.rb +18 -0
- data/generators/talia_base/templates/migrations/create_roles.rb +20 -0
- data/generators/talia_base/templates/migrations/create_semantic_properties.rb +14 -0
- data/generators/talia_base/templates/migrations/create_semantic_relations.rb +17 -0
- data/generators/talia_base/templates/migrations/create_sessions.rb +16 -0
- data/generators/talia_base/templates/migrations/create_users.rb +20 -0
- data/generators/talia_base/templates/migrations/create_workflows.rb +28 -0
- data/generators/talia_base/templates/migrations/populate_users.rb +11 -0
- data/generators/talia_base/templates/migrations/upgrade_relations.rb +12 -0
- data/generators/talia_base/templates/ontologies/hyper_ontology.owl +1462 -0
- data/generators/talia_base/templates/ontologies/hyper_ontology.pprj +9351 -0
- data/generators/talia_base/templates/ontologies/hyper_ontology.repository +6 -0
- data/generators/talia_base/templates/ontologies/scholar_0.1.owl +109 -0
- data/generators/talia_base/templates/script/configure_talia +292 -0
- data/generators/talia_base/templates/script/prepare_images +100 -0
- data/generators/talia_base/templates/talia.sh +51 -0
- data/generators/talia_base/templates/tasks/talia_core.rk +1 -0
- data/lib/loader_helper.rb +9 -0
- data/lib/talia_core.rb +0 -2
- data/lib/talia_dependencies.rb +5 -0
- data/lib/talia_util/rake_tasks.rb +223 -0
- data/tasks/talia_core_tasks.rake +2 -0
- metadata +138 -13
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module Admin::SourcesHelper
|
|
2
|
+
def add_another_predicate(namespace)
|
|
3
|
+
link_to_function image_tag('add.png', :size => '12x12', :alt => 'Add another predicate for '+namespace, :class => 'add') do |page|
|
|
4
|
+
page.insert_html :bottom, 'new_predicates_for_'+namespace.underscore, :partial => 'predicate', :object => TaliaCore::Source.new(''), :locals => {:namespace => namespace, :name => ''}
|
|
5
|
+
page[namespace.underscore].select('.predicate').last.visual_effect :highlight
|
|
6
|
+
page << "attachAjaxAutocompleterOnNewElement('"+h(namespace.underscore)+"');"
|
|
7
|
+
page << "showPredicatesOfDiv('"+h(namespace.underscore)+"');"
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def show_upload_form
|
|
12
|
+
link_to_function "upload", :id => 'upload_link' do |page|
|
|
13
|
+
page.replace_html 'data_form', :partial => 'upload'
|
|
14
|
+
page['upload_link'].visual_effect :fade, :duration => 0.001
|
|
15
|
+
page['data_form'].visual_effect :appear, :duration => 0.4
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def hide_upload_form
|
|
20
|
+
link_to_function "cancel" do |page|
|
|
21
|
+
page['data_form'].visual_effect :fade, :duration => 0.001
|
|
22
|
+
page['upload_link'].visual_effect :appear, :duration => 0.4
|
|
23
|
+
page.replace_html 'data_form', ''
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def file_type(data_type)
|
|
28
|
+
data_type = case data_type
|
|
29
|
+
when Class
|
|
30
|
+
data_type.name
|
|
31
|
+
when nil
|
|
32
|
+
'Record'
|
|
33
|
+
else
|
|
34
|
+
data_type
|
|
35
|
+
end.demodulize.gsub(/(Data|Simple|Media)/, '').gsub(/Record/, 'File').upcase
|
|
36
|
+
|
|
37
|
+
%(<span class="data #{h data_type.downcase}">#{h data_type}</span>)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Use this method in your view to generate a return for the AJAX autocomplete requests.
|
|
41
|
+
#
|
|
42
|
+
# Example action:
|
|
43
|
+
#
|
|
44
|
+
# def auto_complete_for_item_title
|
|
45
|
+
# @items = Item.find(:all,
|
|
46
|
+
# :conditions => [ 'LOWER(description) LIKE ?',
|
|
47
|
+
# '%' + request.raw_post.downcase + '%' ])
|
|
48
|
+
# render :inline => "<%= auto_complete_result(@items, 'description') %>"
|
|
49
|
+
# end
|
|
50
|
+
#
|
|
51
|
+
# The auto_complete_result can of course also be called from a view belonging to the
|
|
52
|
+
# auto_complete action if you need to decorate it further.
|
|
53
|
+
def auto_complete_result(entries, field, phrase = nil)
|
|
54
|
+
return unless entries
|
|
55
|
+
items = entries.map { |entry| content_tag("li", phrase ? highlight(entry.send(field), phrase) : h(entry.send(field))) }
|
|
56
|
+
content_tag("ul", items.uniq)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def escaped_source_identifiers(source)
|
|
60
|
+
tokens = source.uri.to_s.split('/')
|
|
61
|
+
name = unescape(tokens.pop)
|
|
62
|
+
uri = tokens.join('/') + "/" + unescape_link(name)
|
|
63
|
+
[ uri, name ]
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Admin::TranslationsHelper
|
|
2
|
+
# Always pick fresh locales, instead of rely on application.rb
|
|
3
|
+
# This because application.rb is evaluated once in production mode.
|
|
4
|
+
# TODO: Rely on globalize2 when migrate to Rails 2.2.2
|
|
5
|
+
delegate :locales, :to => I18n
|
|
6
|
+
|
|
7
|
+
def add_translation
|
|
8
|
+
link_to_function "Add a translation" do |page|
|
|
9
|
+
page.insert_html :bottom, "translations", :partial => 'new_translation', :object => ViewTranslation.new
|
|
10
|
+
page['translations'].select('.translation').last.focus
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_locale
|
|
15
|
+
link_to "Add locale", :controller => 'admin/locales', :action => 'new'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def languages_picker
|
|
19
|
+
content_tag(:div, :id => 'languages_picker') do
|
|
20
|
+
returning result = "Pick a language: " do
|
|
21
|
+
result << select_tag("languages", languages_options_tags(params[:id]), :onchange => change_language_function)
|
|
22
|
+
result << " | #{reference_translations_picker} | #{add_locale} | #{add_translation}"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def reference_translations_picker
|
|
28
|
+
returning result = "Load translations: " do
|
|
29
|
+
result << select_tag("reference_languages", languages_options_tags(session[:reference_locale] || params[:id], false))
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def languages_options_tags(locale_code, include_url = true)
|
|
34
|
+
locales.map do |language, locale|
|
|
35
|
+
language = language.to_s.titleize
|
|
36
|
+
selected = "selected" if locale_code.match %r{#{locale}}
|
|
37
|
+
value = include_url ? edit_admin_translation_url(locale) : locale
|
|
38
|
+
content_tag(:option, language, :value => value, :selected => selected)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def delete_admin_traslation_path(translation, params)
|
|
43
|
+
admin_translation_path(translation) + "?locale=" + params[:id] + "&page=" + (params[:page] || "1")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def autoload_reference_translations
|
|
47
|
+
content_for :javascript do
|
|
48
|
+
javascript_tag "var autoloadReferenceTranslations = #{@autoload};"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module AdminHelper
|
|
2
|
+
def admin_toolbar
|
|
3
|
+
widget(:toolbar, :buttons => [
|
|
4
|
+
["Home", {:controller => 'source', :action => 'show', :id => 'Lucca'}],
|
|
5
|
+
["Admin", {:action => 'index'} ],
|
|
6
|
+
["Sources", {:controller => 'admin/sources' }],
|
|
7
|
+
["Users", { :controller => 'admin/users'} ],
|
|
8
|
+
["Print Page", "javascript:print();"]
|
|
9
|
+
] )
|
|
10
|
+
end
|
|
11
|
+
end
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//= require <prototype>
|
|
2
|
+
|
|
3
|
+
// LOAD PAGE EVENT
|
|
4
|
+
Event.observe(window, 'load', function() {
|
|
5
|
+
setContentHeight();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// RESIZE PAGE EVENT
|
|
9
|
+
window.onresize = function () {
|
|
10
|
+
setContentHeight();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Set the height of div content from back end
|
|
14
|
+
function setContentHeight() {
|
|
15
|
+
// SPROCKETIZED
|
|
16
|
+
if(contents = $('contenuti')) {
|
|
17
|
+
// Height of the whole window
|
|
18
|
+
var windowHeight = document.viewport.getDimensions().height;
|
|
19
|
+
// Top position of div content
|
|
20
|
+
var contentPosY = $('contenuti').cumulativeOffset().top;
|
|
21
|
+
contents.style.height = ( windowHeight - contentPosY ) + "px";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
//= require <prototype>
|
|
2
|
+
|
|
3
|
+
LowPro = {};
|
|
4
|
+
LowPro.Version = '0.5';
|
|
5
|
+
LowPro.CompatibleWithPrototype = '1.6';
|
|
6
|
+
|
|
7
|
+
if (Prototype.Version.indexOf(LowPro.CompatibleWithPrototype) != 0 && console && console.warn)
|
|
8
|
+
console.warn("This version of Low Pro is tested with Prototype " + LowPro.CompatibleWithPrototype +
|
|
9
|
+
" it may not work as expected with this version (" + Prototype.Version + ")");
|
|
10
|
+
|
|
11
|
+
if (!Element.addMethods)
|
|
12
|
+
Element.addMethods = function(o) { Object.extend(Element.Methods, o) };
|
|
13
|
+
|
|
14
|
+
// Simple utility methods for working with the DOM
|
|
15
|
+
DOM = {};
|
|
16
|
+
|
|
17
|
+
// DOMBuilder for prototype
|
|
18
|
+
DOM.Builder = {
|
|
19
|
+
tagFunc : function(tag) {
|
|
20
|
+
return function() {
|
|
21
|
+
var attrs, children;
|
|
22
|
+
if (arguments.length>0) {
|
|
23
|
+
if (arguments[0].nodeName ||
|
|
24
|
+
typeof arguments[0] == "string")
|
|
25
|
+
children = arguments;
|
|
26
|
+
else {
|
|
27
|
+
attrs = arguments[0];
|
|
28
|
+
children = Array.prototype.slice.call(arguments, 1);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return DOM.Builder.create(tag, attrs, children);
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
create : function(tag, attrs, children) {
|
|
35
|
+
attrs = attrs || {}; children = children || []; tag = tag.toLowerCase();
|
|
36
|
+
var el = new Element(tag, attrs);
|
|
37
|
+
|
|
38
|
+
for (var i=0; i<children.length; i++) {
|
|
39
|
+
if (typeof children[i] == 'string')
|
|
40
|
+
children[i] = document.createTextNode(children[i]);
|
|
41
|
+
el.appendChild(children[i]);
|
|
42
|
+
}
|
|
43
|
+
return $(el);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Automatically create node builders as $tagName.
|
|
48
|
+
(function() {
|
|
49
|
+
var els = ("p|div|span|strong|em|img|table|tr|td|th|thead|tbody|tfoot|pre|code|" +
|
|
50
|
+
"h1|h2|h3|h4|h5|h6|ul|ol|li|form|input|textarea|legend|fieldset|" +
|
|
51
|
+
"select|option|blockquote|cite|br|hr|dd|dl|dt|address|a|button|abbr|acronym|" +
|
|
52
|
+
"script|link|style|bdo|ins|del|object|param|col|colgroup|optgroup|caption|" +
|
|
53
|
+
"label|dfn|kbd|samp|var").split("|");
|
|
54
|
+
var el, i=0;
|
|
55
|
+
while (el = els[i++])
|
|
56
|
+
window['$' + el] = DOM.Builder.tagFunc(el);
|
|
57
|
+
})();
|
|
58
|
+
|
|
59
|
+
DOM.Builder.fromHTML = function(html) {
|
|
60
|
+
var root;
|
|
61
|
+
if (!(root = arguments.callee._root))
|
|
62
|
+
root = arguments.callee._root = document.createElement('div');
|
|
63
|
+
root.innerHTML = html;
|
|
64
|
+
return root.childNodes[0];
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// Wraps the 1.6 contentloaded event for backwards compatibility
|
|
70
|
+
//
|
|
71
|
+
// Usage:
|
|
72
|
+
//
|
|
73
|
+
// Event.onReady(callbackFunction);
|
|
74
|
+
Object.extend(Event, {
|
|
75
|
+
onReady : function(f) {
|
|
76
|
+
if (document.body) f();
|
|
77
|
+
else document.observe('dom:loaded', f);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Based on event:Selectors by Justin Palmer
|
|
82
|
+
// http://encytemedia.com/event-selectors/
|
|
83
|
+
//
|
|
84
|
+
// Usage:
|
|
85
|
+
//
|
|
86
|
+
// Event.addBehavior({
|
|
87
|
+
// "selector:event" : function(event) { /* event handler. this refers to the element. */ },
|
|
88
|
+
// "selector" : function() { /* runs function on dom ready. this refers to the element. */ }
|
|
89
|
+
// ...
|
|
90
|
+
// });
|
|
91
|
+
//
|
|
92
|
+
// Multiple calls will add to exisiting rules. Event.addBehavior.reassignAfterAjax and
|
|
93
|
+
// Event.addBehavior.autoTrigger can be adjusted to needs.
|
|
94
|
+
Event.addBehavior = function(rules) {
|
|
95
|
+
var ab = this.addBehavior;
|
|
96
|
+
Object.extend(ab.rules, rules);
|
|
97
|
+
|
|
98
|
+
if (!ab.responderApplied) {
|
|
99
|
+
Ajax.Responders.register({
|
|
100
|
+
onComplete : function() {
|
|
101
|
+
if (Event.addBehavior.reassignAfterAjax)
|
|
102
|
+
setTimeout(function() { ab.reload() }, 10);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
ab.responderApplied = true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (ab.autoTrigger) {
|
|
109
|
+
this.onReady(ab.load.bind(ab, rules));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
Object.extend(Event.addBehavior, {
|
|
115
|
+
rules : {}, cache : [],
|
|
116
|
+
reassignAfterAjax : false,
|
|
117
|
+
autoTrigger : true,
|
|
118
|
+
|
|
119
|
+
load : function(rules) {
|
|
120
|
+
for (var selector in rules) {
|
|
121
|
+
var observer = rules[selector];
|
|
122
|
+
var sels = selector.split(',');
|
|
123
|
+
sels.each(function(sel) {
|
|
124
|
+
var parts = sel.split(/:(?=[a-z]+$)/), css = parts[0], event = parts[1];
|
|
125
|
+
$$(css).each(function(element) {
|
|
126
|
+
if (event) {
|
|
127
|
+
observer = Event.addBehavior._wrapObserver(observer);
|
|
128
|
+
$(element).observe(event, observer);
|
|
129
|
+
Event.addBehavior.cache.push([element, event, observer]);
|
|
130
|
+
} else {
|
|
131
|
+
if (!element.$$assigned || !element.$$assigned.include(observer)) {
|
|
132
|
+
if (observer.attach) observer.attach(element);
|
|
133
|
+
|
|
134
|
+
else observer.call($(element));
|
|
135
|
+
element.$$assigned = element.$$assigned || [];
|
|
136
|
+
element.$$assigned.push(observer);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
unload : function() {
|
|
145
|
+
this.cache.each(function(c) {
|
|
146
|
+
Event.stopObserving.apply(Event, c);
|
|
147
|
+
});
|
|
148
|
+
this.cache = [];
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
reload: function() {
|
|
152
|
+
var ab = Event.addBehavior;
|
|
153
|
+
ab.unload();
|
|
154
|
+
ab.load(ab.rules);
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
_wrapObserver: function(observer) {
|
|
158
|
+
return function(event) {
|
|
159
|
+
if (observer.call(this, event) === false) event.stop();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
Event.observe(window, 'unload', Event.addBehavior.unload.bind(Event.addBehavior));
|
|
166
|
+
|
|
167
|
+
// A silly Prototype style shortcut for the reckless
|
|
168
|
+
$$$ = Event.addBehavior.bind(Event);
|
|
169
|
+
|
|
170
|
+
// Behaviors can be bound to elements to provide an object orientated way of controlling elements
|
|
171
|
+
// and their behavior. Use Behavior.create() to make a new behavior class then use attach() to
|
|
172
|
+
// glue it to an element. Each element then gets it's own instance of the behavior and any
|
|
173
|
+
// methods called onxxx are bound to the relevent event.
|
|
174
|
+
//
|
|
175
|
+
// Usage:
|
|
176
|
+
//
|
|
177
|
+
// var MyBehavior = Behavior.create({
|
|
178
|
+
// onmouseover : function() { this.element.addClassName('bong') }
|
|
179
|
+
// });
|
|
180
|
+
//
|
|
181
|
+
// Event.addBehavior({ 'a.rollover' : MyBehavior });
|
|
182
|
+
//
|
|
183
|
+
// If you need to pass additional values to initialize use:
|
|
184
|
+
//
|
|
185
|
+
// Event.addBehavior({ 'a.rollover' : MyBehavior(10, { thing : 15 }) })
|
|
186
|
+
//
|
|
187
|
+
// You can also use the attach() method. If you specify extra arguments to attach they get passed to initialize.
|
|
188
|
+
//
|
|
189
|
+
// MyBehavior.attach(el, values, to, init);
|
|
190
|
+
//
|
|
191
|
+
// Finally, the rawest method is using the new constructor normally:
|
|
192
|
+
// var draggable = new Draggable(element, init, vals);
|
|
193
|
+
//
|
|
194
|
+
// Each behaviour has a collection of all its instances in Behavior.instances
|
|
195
|
+
//
|
|
196
|
+
var Behavior = {
|
|
197
|
+
create: function() {
|
|
198
|
+
var parent = null, properties = $A(arguments);
|
|
199
|
+
if (Object.isFunction(properties[0]))
|
|
200
|
+
parent = properties.shift();
|
|
201
|
+
|
|
202
|
+
var behavior = function() {
|
|
203
|
+
var behavior = arguments.callee;
|
|
204
|
+
if (!this.initialize) {
|
|
205
|
+
var args = $A(arguments);
|
|
206
|
+
|
|
207
|
+
return function() {
|
|
208
|
+
var initArgs = [this].concat(args);
|
|
209
|
+
behavior.attach.apply(behavior, initArgs);
|
|
210
|
+
};
|
|
211
|
+
} else {
|
|
212
|
+
var args = (arguments.length == 2 && arguments[1] instanceof Array) ?
|
|
213
|
+
arguments[1] : Array.prototype.slice.call(arguments, 1);
|
|
214
|
+
|
|
215
|
+
this.element = $(arguments[0]);
|
|
216
|
+
this.initialize.apply(this, args);
|
|
217
|
+
behavior._bindEvents(this);
|
|
218
|
+
behavior.instances.push(this);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
Object.extend(behavior, Class.Methods);
|
|
223
|
+
Object.extend(behavior, Behavior.Methods);
|
|
224
|
+
behavior.superclass = parent;
|
|
225
|
+
behavior.subclasses = [];
|
|
226
|
+
behavior.instances = [];
|
|
227
|
+
|
|
228
|
+
if (parent) {
|
|
229
|
+
var subclass = function() { };
|
|
230
|
+
subclass.prototype = parent.prototype;
|
|
231
|
+
behavior.prototype = new subclass;
|
|
232
|
+
parent.subclasses.push(behavior);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
for (var i = 0; i < properties.length; i++)
|
|
236
|
+
behavior.addMethods(properties[i]);
|
|
237
|
+
|
|
238
|
+
if (!behavior.prototype.initialize)
|
|
239
|
+
behavior.prototype.initialize = Prototype.emptyFunction;
|
|
240
|
+
|
|
241
|
+
behavior.prototype.constructor = behavior;
|
|
242
|
+
|
|
243
|
+
return behavior;
|
|
244
|
+
},
|
|
245
|
+
Methods : {
|
|
246
|
+
attach : function(element) {
|
|
247
|
+
return new this(element, Array.prototype.slice.call(arguments, 1));
|
|
248
|
+
},
|
|
249
|
+
_bindEvents : function(bound) {
|
|
250
|
+
for (var member in bound)
|
|
251
|
+
if (member.match(/^on(.+)/) && typeof bound[member] == 'function')
|
|
252
|
+
bound.element.observe(RegExp.$1, Event.addBehavior._wrapObserver(bound[member].bindAsEventListener(bound)));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
Remote = Behavior.create({
|
|
258
|
+
initialize: function(options) {
|
|
259
|
+
if (this.element.nodeName == 'FORM') new Remote.Form(this.element, options);
|
|
260
|
+
else new Remote.Link(this.element, options);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
Remote.Base = {
|
|
265
|
+
initialize : function(options) {
|
|
266
|
+
this.options = Object.extend({
|
|
267
|
+
evaluateScripts : true
|
|
268
|
+
}, options || {});
|
|
269
|
+
},
|
|
270
|
+
_makeRequest : function(options) {
|
|
271
|
+
if (options.update) new Ajax.Updater(options.update, options.url, options);
|
|
272
|
+
else new Ajax.Request(options.url, options);
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
Remote.Link = Behavior.create(Remote.Base, {
|
|
278
|
+
onclick : function() {
|
|
279
|
+
var options = Object.extend({ url : this.element.href, method : 'get' }, this.options);
|
|
280
|
+
return this._makeRequest(options);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
Remote.Form = Behavior.create(Remote.Base, {
|
|
286
|
+
onclick : function(e) {
|
|
287
|
+
var sourceElement = e.element();
|
|
288
|
+
|
|
289
|
+
if (['input', 'button'].include(sourceElement.nodeName.toLowerCase()) &&
|
|
290
|
+
sourceElement.type == 'submit')
|
|
291
|
+
this._submitButton = sourceElement;
|
|
292
|
+
},
|
|
293
|
+
onsubmit : function() {
|
|
294
|
+
var options = Object.extend({
|
|
295
|
+
url : this.element.action,
|
|
296
|
+
method : this.element.method || 'get',
|
|
297
|
+
parameters : this.element.serialize({ submit: this._submitButton.name })
|
|
298
|
+
}, this.options);
|
|
299
|
+
this._submitButton = null;
|
|
300
|
+
return this._makeRequest(options);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
Observed = Behavior.create({
|
|
305
|
+
initialize : function(callback, options) {
|
|
306
|
+
this.callback = callback.bind(this);
|
|
307
|
+
this.options = options || {};
|
|
308
|
+
this.observer = (this.element.nodeName == 'FORM') ? this._observeForm() : this._observeField();
|
|
309
|
+
},
|
|
310
|
+
stop: function() {
|
|
311
|
+
this.observer.stop();
|
|
312
|
+
},
|
|
313
|
+
_observeForm: function() {
|
|
314
|
+
return (this.options.frequency) ? new Form.Observer(this.element, this.options.frequency, this.callback) :
|
|
315
|
+
new Form.EventObserver(this.element, this.callback);
|
|
316
|
+
},
|
|
317
|
+
_observeField: function() {
|
|
318
|
+
return (this.options.frequency) ? new Form.Element.Observer(this.element, this.options.frequency, this.callback) :
|
|
319
|
+
new Form.Element.EventObserver(this.element, this.callback);
|
|
320
|
+
}
|
|
321
|
+
});
|