1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Helpers
18 using System
.Collections
;
20 // TODO: Add support for Sortable, Draggable, and DropReceiving
23 /// Exposes the effect script from Thomas Fuchs
24 /// (http://script.aculo.us, http://mir.aculo.us)
27 /// Before using it, you must install the scripts.
28 /// See <see cref="ScriptaculousHelper.InstallScripts"/>
30 public class ScriptaculousHelper
: AbstractHelper
34 /// Initializes a new instance of the <see cref="ScriptaculousHelper"/> class.
36 public ScriptaculousHelper() { }
38 /// Initializes a new instance of the <see cref="ScriptaculousHelper"/> class.
39 /// setting the Controller, Context and ControllerContext.
41 /// <param name="engineContext">The engine context.</param>
42 public ScriptaculousHelper(IEngineContext engineContext
) : base(engineContext
) { }
48 /// Renders a Javascript library inside a single script tag.
50 /// <returns></returns>
51 public String
InstallScripts()
53 return RenderScriptBlockToSource("/MonoRail/Files/Effects2");
57 /// Gets the javascript functions.
59 /// <returns></returns>
60 [Obsolete("Please use the preferred InstallScripts function.")]
61 public String
GetJavascriptFunctions()
63 return InstallScripts();
69 /// Generates a JS snippet invoking the specified effect.
72 /// VisualEffect('ToggleSlide', 'elementid')
73 /// VisualEffect('ToggleBlind', 'elementid')
74 /// VisualEffect('ToggleAppear', 'elementid')
75 /// VisualEffect('Highlight', 'elementid')
76 /// VisualEffect('Fade', 'elementid')
77 /// VisualEffect('Shake', 'elementid')
78 /// VisualEffect('DropOut', 'elementid')
82 /// <param name="name">The effect name.</param>
83 /// <param name="elementId">The element id to act upon.</param>
84 /// <returns>A JS snippet</returns>
85 public string VisualEffect(string name
, string elementId
)
87 return VisualEffect(name
, elementId
, null);
91 /// Generates a JS snippet invoking the specified effect.
94 /// VisualEffect('ToggleSlide', 'elementid')
95 /// VisualEffect('ToggleBlind', 'elementid')
96 /// VisualEffect('ToggleAppear', 'elementid')
97 /// VisualEffect('Highlight', 'elementid')
98 /// VisualEffect('Fade', 'elementid')
99 /// VisualEffect('Shake', 'elementid')
100 /// VisualEffect('DropOut', 'elementid')
104 /// Common options includes <c>duration</c>,
105 /// <c>transition</c>, <c>fps</c>, <c>sync</c>,
106 /// <c>from</c>, <c>to</c>, <c>delay</c>, <c>queue</c>,
107 /// <c>startcolor</c>, <c>endcolor</c>.
111 /// <c>beforeStart</c>, <c>beforeUpdate</c>, <c>afterUpdate</c>, <c>afterFinish</c>
115 /// If you want to use the DropOut effect, please refer to <see cref="VisualEffectDropOut"/>
117 /// <param name="name">The effect name.</param>
118 /// <param name="elementId">The element id to act upon.</param>
119 /// <param name="options">A dictionary used to specify options to the effect behavior</param>
120 /// <returns>A JS snippet</returns>
121 public string VisualEffect(string name
, string elementId
, IDictionary options
)
123 if (name
== null) throw new ArgumentNullException("name", "Visual effect name is required");
125 if (elementId
== null) elementId
= "element";
127 if (name
.ToLowerInvariant().StartsWith("toggle"))
129 return "Effect.toggle(" + SQuote(elementId
) + ", " +
130 SQuote(name
.Substring("toggle".Length
).ToLowerInvariant()) +
131 ", " + JavascriptOptions(options
) + ");";
135 return "new Effect." + name
+ "(" + SQuote(elementId
) + ", " + JavascriptOptions(options
) + ");";
140 /// Generates a JS snippet invoking the DropOut effect
143 /// VisualEffectDropOut('elementid', {position:'end', scope='test', limit=2})
147 /// <param name="elementId">The element id to act upon.</param>
148 /// <param name="queue">A dictionary used to specify options to the DropOut behavior</param>
149 /// <returns>A JS snippet</returns>
150 public string VisualEffectDropOut(string elementId
, IDictionary queue
)
152 if (elementId
== null) throw new ArgumentNullException("elementId", "Visual effect's elementId is required");
154 if (queue
== null || queue
.Count
== 0)
156 return "new Effect.DropOut(" + SQuote(elementId
) + ", {queue:'end'});";
160 return "new Effect.DropOut(" + SQuote(elementId
) + ", " + JavascriptOptions(queue
) + ");";