Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Helpers / ScriptaculousHelper.cs
blob073b1dc73c3848c80fd857b0d76260123774c21d
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
18 using System.Collections;
20 // TODO: Add support for Sortable, Draggable, and DropReceiving
22 /// <summary>
23 /// Exposes the effect script from Thomas Fuchs
24 /// (http://script.aculo.us, http://mir.aculo.us)
25 /// </summary>
26 /// <remarks>
27 /// Before using it, you must install the scripts.
28 /// See <see cref="ScriptaculousHelper.InstallScripts"/>
29 /// </remarks>
30 public class ScriptaculousHelper : AbstractHelper
32 #region Constructors
33 /// <summary>
34 /// Initializes a new instance of the <see cref="ScriptaculousHelper"/> class.
35 /// </summary>
36 public ScriptaculousHelper() { }
37 /// <summary>
38 /// Initializes a new instance of the <see cref="ScriptaculousHelper"/> class.
39 /// setting the Controller, Context and ControllerContext.
40 /// </summary>
41 /// <param name="engineContext">The engine context.</param>
42 public ScriptaculousHelper(IEngineContext engineContext) : base(engineContext) { }
43 #endregion
45 #region Scripts
47 /// <summary>
48 /// Renders a Javascript library inside a single script tag.
49 /// </summary>
50 /// <returns></returns>
51 public String InstallScripts()
53 return RenderScriptBlockToSource("/MonoRail/Files/Effects2");
56 /// <summary>
57 /// Gets the javascript functions.
58 /// </summary>
59 /// <returns></returns>
60 [Obsolete("Please use the preferred InstallScripts function.")]
61 public String GetJavascriptFunctions()
63 return InstallScripts();
66 #endregion
68 /// <summary>
69 /// Generates a JS snippet invoking the specified effect.
70 /// <para>Examples:
71 /// <code>
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')
79 /// </code>
80 /// </para>
81 /// </summary>
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);
90 /// <summary>
91 /// Generates a JS snippet invoking the specified effect.
92 /// <para>Examples:
93 /// <code>
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')
101 /// </code>
102 /// </para>
103 /// <para>
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>.
108 /// </para>
109 /// <para>
110 /// Callbacks:
111 /// <c>beforeStart</c>, <c>beforeUpdate</c>, <c>afterUpdate</c>, <c>afterFinish</c>
112 /// </para>
113 /// </summary>
114 /// <remarks>
115 /// If you want to use the DropOut effect, please refer to <see cref="VisualEffectDropOut"/>
116 /// </remarks>
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) + ");";
133 else
135 return "new Effect." + name + "(" + SQuote(elementId) + ", " + JavascriptOptions(options) + ");";
139 /// <summary>
140 /// Generates a JS snippet invoking the DropOut effect
141 /// <para>Examples:
142 /// <code>
143 /// VisualEffectDropOut('elementid', {position:'end', scope='test', limit=2})
144 /// </code>
145 /// </para>
146 /// </summary>
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'});";
158 else
160 return "new Effect.DropOut(" + SQuote(elementId) + ", " + JavascriptOptions(queue) + ");";