/// <summary> /// Called by the framework so the component can /// render its content /// </summary> public override void Render() { base.Render(); if (Text.Length <= MaxLength) { RenderText(Text); } else { int inx = Text.LastIndexOf(' ', MaxLength); RenderText(Text.Substring(0, inx)); JavascriptHelper helper = new JavascriptHelper(Context, EngineContext, "MoreLessComponent"); if (helper.PreferredLibrary == "jquery") { helper.IncludeStandardScripts("jquery"); helper.IncludeScriptText("function moreless(key) {jQuery('#extraText:'+key).toggle();jQuery('#more:'+key);}"); } else { helper.IncludeStandardScripts("Ajax"); helper.IncludeScriptText("function moreless(key) {Element.toggle('extraText:'+key);Element.toggle('more:'+key);}"); } string key = base.MakeUniqueId(""); RenderTextFormat(@" <span id=""extraText:{0}"">", key); RenderText(Text.Substring(inx)); RenderTextFormat(@"<a onclick=""moreless('{0}');"">{1}</a></span>" + @"<span id=""more:{0}"" style=""display:none""><a onclick=""moreless('{0}');"">{2}</a></span>"+ @"<script type=""text/javascript"">moreless('{0}');</script>", key, LessText, MoreText); } CancelView(); }
void AddScript() { JavascriptHelper helper = new JavascriptHelper(this.Context, this.EngineContext, "CollapsiblePanelComponent"); jsLibrary = jsLibrary ?? helper.PreferredLibrary; ResourceManager rm = new ResourceManager("Castle.MonoRail.ViewComponents.CollapsiblePanelScripts", Assembly.GetExecutingAssembly()); string script = rm.GetString(jsLibrary); if (script == null) throw new ViewComponentException("unsupported JSLibrary option"); helper.IncludeScriptText(script); helper.IncludeStandardScripts(jsLibrary); if (jsLibrary.StartsWith("proto")) helper.IncludeStandardScripts("effects"); helper.IncludeScriptText("\nvar CollapseComponentDefaults = {effect: 'blind', effectDuration:0.3,expandLinkText: 'Show', collapseLinkText: 'Hide'};"); }
private void RenderJavascript() { JavascriptHelper helper = new JavascriptHelper(Context, EngineContext, "MenuComponent"); string jslibrary = this.ComponentParams["JSLibrary"] as string ?? helper.PreferredLibrary ?? "prototype"; ResourceManager rm = new ResourceManager("Castle.MonoRail.ViewComponents.Menu", Assembly.GetExecutingAssembly()); switch (jslibrary.ToLowerInvariant()) { case "jquery": helper.IncludeScriptText(rm.GetString(jslibrary)); helper.IncludeStandardScripts("jquery"); break; case "prototype": helper.IncludeScriptText(rm.GetString(jslibrary)); helper.IncludeStandardScripts("effects2"); break; case "none": break; default: throw new ViewComponentException("Unsupported JavaScript library requested. Must be 'prototype' or 'jquery'"); } }
private void RenderJavascript() { AddScript(); JavascriptHelper helper = new JavascriptHelper(this.Context, this.EngineContext, "CollapsiblePanelComponent-"+this.id); StringBuilder sb = new StringBuilder(); sb.AppendFormat(@"var {0}Opts = {{controlName: '{0}Body', togglerName: '{0}Toggle'", this.id); if (collapseLinkText != null) sb.AppendFormat(@", collapseLinkText:'{0}'", collapseLinkText); if (expandLinkText != null) sb.AppendFormat(@", expandLinkText: '{0}'", expandLinkText); if (this.collapseImagePath != null) sb.AppendFormat(@", collapseImagePath:'{0}'", collapseImagePath); if (this.expandImagePath != null) sb.AppendFormat(@", expandImagePath:'{0}'", expandImagePath); if (this.effect != null) sb.AppendFormat(@", effect:'{0}'", effect); if (this.effectDuration.HasValue) sb.AppendFormat(@", effectDuration:{0}", effectDuration.Value); sb.Append("};"); helper.IncludeScriptText(sb.ToString()); }
private void BuildScript() { JavascriptHelper helper = new JavascriptHelper(Context, EngineContext, "DualList"); helper.IncludeStandardScripts("Ajax"); helper.IncludeScriptText( @"function moveItem(sourceControl, targetControl) { var source = $(sourceControl); var target = $(targetControl); if ((source != null) && (target != null)) { while ( source.options.selectedIndex >= 0 ) { var newOption = new Option(); // Create a new instance of ListItem newOption.text = source.options[source.options.selectedIndex].text; newOption.value = source.options[source.options.selectedIndex].value; target.options[target.length] = newOption; //Append the item in target source.remove(source.options.selectedIndex); //Remove the item from Source } } } // moveOptionsUp // // move the selected options up one location in the select list // function moveOptionsUp(sourceControl) { var selectList = $(sourceControl); var selectOptions = selectList.getElementsByTagName('option'); for (var i = 1; i < selectOptions.length; i++) { var opt = selectOptions[i]; if (opt.selected) { selectList.removeChild(opt); selectList.insertBefore(opt, selectOptions[i - 1]); } } } // moveOptionsDown // // move the selected options down one location in the select list // function moveOptionsDown(sourceControl) { var selectList = $(sourceControl); var selectOptions = selectList.getElementsByTagName('option'); for (var i = selectOptions.length - 2; i >= 0; i--) { var opt = selectOptions[i]; if (opt.selected) { var nextOpt = selectOptions[i + 1]; opt = selectList.removeChild(opt); nextOpt = selectList.replaceChild(opt, nextOpt); selectList.insertBefore(nextOpt, opt); } } } "); }