public override void Update(System.Html.Element element, Func <object> valueAccessor, Func <System.Collections.Dictionary> allBindingsAccessor, object viewModel, object context) { // Whenever the value subsequently changes, slowly fade the element in or out Observable <bool> observable = (Observable <bool>)valueAccessor(); string effectIn = (string)((object)allBindingsAccessor()["effectIn"]); string effectOut = (string)((object)allBindingsAccessor()["effectOut"]); jQueryObject item = jQuery.FromElement(element); string effect = KnockoutUtils.UnwrapObservable(observable) ? effectIn : effectOut; switch (effect) { case "fadeIn": item.FadeIn(); break; case "fadeOut": item.FadeOut(); break; case "slideUp": item.SlideUp(); break; case "slideDown": item.SlideDown(); break; } }
/// <summary> /// Updats the HTML element with new HTML /// Also, loads the new JS object (module) to handle the behavior /// </summary> /// <param name="content">The element to be updated</param> /// <param name="value">The HTML with which to update it</param> private static void UpdateModule(jQueryObject content, string value) { Module module = null; // Find elements which have data-type attribute with any value // The attribute is applied to elements that can be updated jQueryObject dataTypes = content.Children("*[data-type]"); // If updatable elements exist, if (dataTypes.Length > 0) { // Get the first element found Element element = dataTypes.First().GetElement(0); // Find the corresponding module module = Module.GetModule(element); // Now we have the module which should be unloaded and then updated } // Fade the element out and update with the new HTML content.FadeOut(250, delegate() { // Unload the module // BUGBUG: when can this be NULL if (null != module) { module.Unload(); } // Update the content content.Html(value); content.FadeIn(250); // Check if it has any child modules to be loaded dataTypes = content.Children("*[data-type]"); if (dataTypes.Length > 0) { // Load only the first LoadModule(dataTypes.First().GetElement(0)); // BUGBUG: do we care about the rest? } }); }