yui3/commit
add yui3_beta
author | Michiel Hildebrand |
---|---|
Tue Apr 19 17:02:54 2011 +0200 | |
committer | Michiel Hildebrand |
Tue Apr 19 17:02:54 2011 +0200 | |
commit | c866a7006fb3bb3ac4a393eadef39650fd2b74a8 |
tree | 3f60f4c3e30b853fe7f3538b97a4946c351ed4f4 |
parent | 5442df4579c97ab88b5c9f0f6e7071e875bb81a4 |
Diff style: patch stat
diff --git a/config-available/yui3.pl b/config-available/yui3.pl index c5f38b4001..50e121d654 100644 --- a/config-available/yui3.pl +++ b/config-available/yui3.pl @@ -6,7 +6,7 @@ :- use_module(library(settings)). :- use_module(library(http/http_path)). -:- setting(local, boolean, false, +:- setting(local, boolean, true, 'When set to true the local version of YUI is used'). :- multifile http:location/3. diff --git a/lib/yui3.pl b/lib/yui3.pl index a1e04464a2..6a77041b4b 100644 --- a/lib/yui3.pl +++ b/lib/yui3.pl @@ -8,7 +8,10 @@ js_yui3_render//2, js_function//2, js_function_decl//3, - js_yui3_decl//2 + js_global_function_decl//3, + js_yui3_decl//2, + js_yui3_select//1, + js_yui3_io//2 ]). :- use_module(library(http/js_write)). @@ -31,9 +34,10 @@ js_yui3(Head, Include, Body) --> html_requires(yui3('yui/yui-min.js')), - html('YUI(\n'), + html('var Y = YUI(\n'), js_args(Head), - html(')\n.use('), + html(');\n'), + html('Y.use('), js_yui3_include(Include), html('\n'), js_function(['Y'], Body), @@ -51,7 +55,7 @@ js_yui3_include(List) --> % Emit javascript event handler. js_yui3_event(Id, When, Event, Fn, Scope) --> - html([Id, '.' ,When, '("', Event, '",', Fn, ',', Scope, ');\n']). + html([\js_yui3_select(Id), '.' ,When, '("', Event, '",', Fn, ',', Scope, ');\n']). %% js_yui3_on(+Id, +EventType, +JSFunction) % @@ -59,7 +63,7 @@ js_yui3_event(Id, When, Event, Fn, Scope) --> % Same as js_yui3_event with When parameter = 'on'. js_yui3_on(Id, Event, Fn) --> - html([Id,'.on("',Event,'",', Fn, ');\n']). + html([\js_yui3_select(Id),'.on("',Event,'",', Fn, ');\n']). % js_yui3_delegate(+Selecter, +Context, +EventType, +JSFunction, % +Args) @@ -80,15 +84,6 @@ js_function(Args, Body) --> html([Body,'\n']), html('}'). -%% js_function_decl(+Id, +Args, +Body) -% -% Emit javascript function declaration. - -js_function_decl(Id, Args, Body) --> - html(['var ', Id, ' = ']), - js_function(Args, Body), - html(';\n'). - js_vars([]) --> []. js_vars([H]) --> !, @@ -98,13 +93,26 @@ js_vars([H|T]) --> js_vars(T). +%% js_function_decl(+Id, +Args, +Body) +% +% Emit javascript function declaration. + +js_function_decl(Id, Args, Body) --> + html(['var ', Id, ' = ']), + js_function(Args, Body), + html(';\n'). +js_global_function_decl(Id, Args, Body) --> + html([Id, ' = ']), + js_function(Args, Body), + html(';\n'). + %% js_yui3_decl(+Name, +Value) % % Emit javascript variable declaration. js_yui3_decl(Name, Value) --> html(['Y.', Name, ' = ']), - js_args([Value]), + js_arg(Value), html(';\n'). %% js_yui3_plug(+Id, +Plugin, +Conf) @@ -112,7 +120,7 @@ js_yui3_decl(Name, Value) --> % Emit javascript plugin. js_yui3_plug(Id, Plugin, Conf) --> - html([Id, '.plug(', Plugin, ',']), + html([\js_yui3_select(Id), '.plug(', Plugin, ',']), js_args([Conf]), html(');\n'). @@ -122,5 +130,25 @@ js_yui3_plug(Id, Plugin, Conf) --> js_yui3_render(Id) --> html([Id, '.render();\n']). -js_yui3_render(Id, El) --> - html([Id, '.render(', \js_args([El]), ');\n']). +js_yui3_render(Id, Selector) --> + html([Id, '.render(', \js_yui3_select(Selector), ');\n']). + + +%% js_yui3_select(+YUI3_Selector) +% +% Emit YUI3 selector. + +js_yui3_select(Id) --> {atom(Id)}, !, html(Id). +js_yui3_select(#(Id)) --> !, html(['"#',Id,'"']). +js_yui3_select(class(Id)) --> !, html(['".',Id,'"']). +js_yui3_select(string(Id)) --> !, html(['"',Id,'"']). +js_yui3_select(one(Id)) --> !, html(['Y.one(',\js_yui3_select(Id),')']). +js_yui3_select(all(Id)) --> !, html(['Y.all(',\js_yui3_select(Id),')']). + + +%% js_yui3_io(+Server, +Conf) +% +% Emit YUI io object. + +js_yui3_io(Server, Conf) --> + html(['Y.io("',Server,'", ', \js_args([Conf]), ');']). diff --git a/lib/yui3_beta.pl b/lib/yui3_beta.pl new file mode 100644 index 0000000000..858dd599a0 --- /dev/null +++ b/lib/yui3_beta.pl @@ -0,0 +1,178 @@ +:- module(yui3_beta, + [ yui3//3, + yui3_select//1, + yui3_new//3, + yui3_set//3, + yui3_get//3, + yui3_add_class//2, + yui3_render//1, + yui3_render//2, + yui3_plug//3, + yui3_on//4, + yui3_delegate//6, + yui3_io//2, + js_function//2 + ]). + +:- use_module(library(http/js_write)). +:- use_module(library(http/html_write)). +:- use_module(library(http/html_head)). + +:- meta_predicate + yui3(+, +, :, -, +), + yui3_select(+, -, +), + yui3_new(+,+,+,-,+), + yui3_set(+,+,+,-,+), + yui3_get(+,+,-,-,+), + yui3_add_class(+,+,-,+), + yui3_render(+), + yui3_render(+,+), + yui3_on(+, +, +, :, -, +), + yui3_delegate(+, +, :, +, +, +, -, +), + yui3_io(+, +, -, +), + js_function(+, :, -, +). + + + +%% yui3(+Head, +Include, +Body) +% +% Emit javascript YUI3 object. + +yui3(Head, Include, Body) --> + html_requires(yui3('yui/yui-min.js')), + html('YUI('), + js_args(Head), + html(').use('), + yui3_include(Include), + js_function(['Y'], Body), + html(');'). + +yui3_include([]) --> + !. +yui3_include(List) --> + js_args(List), + html(', '). + + /******************************* + * atomic YUI3 writes * + *******************************/ + +%% yui3_new(+Node, +Object, +Options) +% +% Emit javascript object initializer + +yui3_new(Node, Object, Options) --> + html([Node, ' = new ', Object, '(']), + js_arg(Options), + html(');\n'). + + +%% yui3_set(+Selector, +Attr, +Value) +% +% Emit javascript attribute setter. + +yui3_set(Selector, Attr, Value) --> + yui3_select(Selector), + html(['.set("',Attr,'",']), + js_arg(Value), + html(');\n'). + +%% yui3_get(+Selector, +Attr, -Value) +% +% Emit javascript attribute getter. + +yui3_get(Selector, Attr, symbol(Value)) --> + { Value = tmp1 }, + html(['var ', Value, ' = ']), + yui3_select(Selector), + html(['.get("',Attr,'");\n']). + +%% yui3_add_class(+Selector, +ClassName) +% +% Emit javascript className setter. + +yui3_add_class(Selector, ClassName) --> + yui3_select(Selector), + html(['.addClass("',ClassName,'");\n']). + +%% yui3_render(+Node, +Selector) +% +% Emit javascript render call. + +yui3_render(Node) --> + html([Node, '.render();\n']). +yui3_render(Node, Selector) --> + html([Node, '.render(']), + yui3_select(Selector), + html(');\n'). + +%% yui3_on(+Selecter, +Event, +Vars, :Body) +% +% Emit YUI3 event handler + +yui3_on(Selector, Event, Vars, Body) --> + yui3_select(Selector), + html(['.on("',Event,'",']), + js_function(Vars, Body), + html(');\n'). + +%% yui3_delegate(+Event, +Vars, :Body, +Selector, +Context, +Args) +% +% Emit javascript event handler on multiple nodes. + +yui3_delegate(Event, Vars, Body, Selector, Context, Args) --> + html(['Y.delegate', '("', Event, '",']), + js_function(Vars, Body), + html(', '), + yui3_select(Selector), + html([', "',Context,'",', Args, ');\n']). + +%% yui3_plug(+Node, +Plugin, +Conf) +% +% Emit javascript plugin. + +yui3_plug(Selector, Plugin, Conf) --> + yui3_select(Selector), + html(['.plug(', Plugin, ',']), + js_arg(Conf), + html(');\n'). + +%% yui3_io(+Server, +Conf) +% +% Emit YUI io object. + +yui3_io(Server, Conf) --> + html(['Y.io("',Server,'", ', \js_args([Conf]), ');']). + +%% yui3_select(+YUI3_Selector) +% +% Emit YUI3 selector. + +yui3_select(#(Id)) --> html(['"#',Id,'"']). +yui3_select(id(Id)) --> html(['"#',Id,'"']). +yui3_select(class(Id)) --> html(['".',Id,'"']). +yui3_select(one(Id)) --> html(['Y.one(',\yui3_select(Id),')']). +yui3_select(all(Id)) --> html(['Y.all(',\yui3_select(Id),')']). +yui3_select(Id) --> html(Id). + + + /******************************* + * atomic JS writes * + *******************************/ + +%% js_function(+Args, +Body) +% +% Emit javascript function. + +js_function(Args, Body) --> + html(['function(', \js_vars(Args), ') {\n']), + html(Body), + html('}'). + +js_vars([]) --> + []. +js_vars([H]) --> !, + html(H). +js_vars([H|T]) --> + html([H,',']), + js_vars(T).