如何使用DurandalJS创建“完整页面对话框”

时间:2013-08-30 16:34:07

标签: durandal

我正在尝试消除使用DurandalJS版本2构建的Web客户端应用程序(SPA)的“css模式窗口”(模式窗口不是移动设备最好的朋友)。

我想将模态窗口转换为完整页面对话框。它仍然是一个对话窗口,但不是将div叠加在当前视图上,而是隐藏当前视图(同时保持其状态)并显示包含对话框的div(如果可能,使用“入口”转换或类似的技术 - 保持一致的流量。)

我认为我接近解决方案。我正在尝试的两个选项是按原样使用对话框插件(通过添加新的对话框上下文)或基于对话框插件创建新插件。无论哪种方式,我都需要隐藏当前视图。

如何使用此方法或如何从对话框上下文中的compositionComplete钩子确定当前活动视图?

DurandalJS Google Groups

上的相关问题

编辑1 (在@CodingGorilla评论之后)

按原样使用入口过渡,这不是重要的部分。我可以复制过渡代码。但最重要的是,我不应该导航到一个新的观点。这个概念与DurandalJS中的对话框完全相同。唯一的区别是演示文稿。一个对话框有一个URL,它与当前状态/窗口是上下文关系。

1 个答案:

答案 0 :(得分:2)

我想我明白了。它并不像我希望的那样漂亮,但我很高兴能够重用对话框插件和转换机制。

以下是我使用的对话框上下文:

define(['jquery', 'knockout', 'transitions/entrance', 'plugins/dialog'], function ($, ko, entrance, dialog) {
    return {
        addHost: function (theDialog) {
            //Cheat - only applies to my project (where I want to put the dialog - side-by-side with the current active view)
            var container = $('div.document-edit');

            var host = $('<div></div>').appendTo(body);
            theDialog.host = host.get(0);

            //Cheat - the view I want to hide (while the dialog is displayed)
            theDialog.activeView = container.find("div[data-active-view='true']:first").get(0); 
        },
        removeHost: function (theDialog) {
            var context = {
                activeView: theDialog.host,
                child: theDialog.activeView,
                triggerAttach: function () { } //Cheat - no need for triggerAttach
            };

            entrance(context).then(function () {
                ko.removeNode(theDialog.host);
            });
        },
        compositionComplete: function (child, parent, context) {
            var theDialog = dialog.getDialog(context.model);
            context.activeView = theDialog.activeView;

            //Cheat - no need for triggerAttach
            context.triggerAttach = function () { }; 

            entrance(context).then(function () { });
        }
    };
});