forked from vim-zz/nitrogen_elements
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ofera
committed
May 3, 2009
1 parent
bfb58e2
commit aa1984f
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-module(element_force_reload_on_back_button). | ||
-compile(export_all). | ||
|
||
-include_lib("lib/nitrogen/include/wf.inc"). | ||
-record(force_reload_on_back_button, {?ELEMENT_BASE(element_force_reload_on_back_button)}). | ||
|
||
reflect() -> record_info(fields, force_reload_on_back_button). | ||
|
||
% desc: put this element if you need the page to reload whenever the user | ||
% used the back button in order to return to the page. mostly needed on | ||
% dinamic created pages | ||
|
||
% in plain html/java this will look like this: | ||
% function body_onload() { | ||
% if(document.getElementById("force_reload") != null) { | ||
% if(force_reload.value != "initialvalue") { | ||
% window.location = document.location.href; | ||
% } else { | ||
% force_reload.value = "newvalue" | ||
% } | ||
% } | ||
% } | ||
% <body onload=body_onload()> | ||
% <input id="force_reload" type="hidden" value="initialvalue"/> | ||
|
||
% i used jquery which better than using the body onload method | ||
render(ControlID, _Record) -> | ||
JS = "$(function() { | ||
if(obj('" ++ ControlID ++ "').value != 'initialvalue') | ||
window.location = document.location.href; | ||
else | ||
obj('" ++ ControlID ++ "').value = 'newvalue'; | ||
});", | ||
Hidden = #hidden{id=ControlID, text="initialvalue"}, | ||
wf:wire(ControlID, JS), | ||
element_hidden:render(ControlID, Hidden). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-module(element_image_x). | ||
-compile(export_all). | ||
|
||
-include_lib("lib/nitrogen/include/wf.inc"). | ||
-record(image_x, {?ELEMENT_BASE(element_image_x), image, alt, width, height, usemap}). | ||
|
||
% desc: this enhance the basic image element, mostly for using 'usemap' tag | ||
% it also allow adding inline width/height to the iamge | ||
|
||
|
||
reflect() -> record_info(fields, image_x). | ||
|
||
render(ControlID, Record) -> | ||
Attributes = [ | ||
{id, ControlID}, | ||
{class, [image, Record#image_x.class]}, | ||
{style, Record#image_x.style}, | ||
{src, Record#image_x.image}, | ||
{usemap, Record#image_x.usemap} | ||
], | ||
|
||
OptionalArgs = [fun add_alt/2, fun add_width/2, fun add_height/2], | ||
FinalAttributes = lists:foldl(fun(F, X) -> F(Record, X) end, Attributes, OptionalArgs), | ||
wf_tags:emit_tag(img, FinalAttributes). | ||
|
||
|
||
|
||
add_alt(Record, Attributes) -> | ||
case Record#image_x.alt of | ||
undefined -> Attributes; | ||
Val -> [{alt, Val}|Attributes] | ||
end. | ||
|
||
add_width(Record, Attributes) -> | ||
case Record#image_x.width of | ||
undefined -> Attributes; | ||
Val -> [{width, Val}|Attributes] | ||
end. | ||
|
||
add_height(Record, Attributes) -> | ||
case Record#image_x.height of | ||
undefined -> Attributes; | ||
Val -> [{height, Val}|Attributes] | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-module(element_textarea_x). | ||
-compile(export_all). | ||
|
||
-include_lib("lib/nitrogen/include/wf.inc"). | ||
-record(textarea_x, {?ELEMENT_BASE(element_textarea_x), text="", html_encode=true, rows=2, columns=20}). | ||
|
||
% desc: enhance the basic textarea with inline cols/rows values | ||
|
||
reflect() -> record_info(fields, textarea_x). | ||
|
||
render(ControlID, Record) -> | ||
Content = wf:html_encode(Record#textarea_x.text, Record#textarea_x.html_encode), | ||
wf_tags:emit_tag(textarea, Content, [ | ||
{id, ControlID}, | ||
{name, ControlID}, | ||
{class, [textarea, Record#textarea_x.class]}, | ||
{style, Record#textarea_x.style}, | ||
{rows, Record#textarea_x.rows}, | ||
{columns, Record#textarea_x.columns} | ||
]). |