How to create “full page dialog” with DurandalJS

不羁的心 提交于 2019-12-22 10:48:43

问题


I'm trying to eliminate "css modal windows" (modal windows are not mobile device best friends) of a web client side application (SPA), built with DurandalJS version 2.

I would like to convert the modal windows to full page dialogs. It would still be a dialog window but instead of superimpose the div over the current view, I would like to hide the current view (while keeping its state) and show the div containing the dialog (using the "entrance" transition if possible or a similar technique - to keep a consistent flow).

I think I am close to a solution. The two options I'm trying at the moment are using the dialog plugin as is (by adding a new dialog context) or creating a new plugin based on the dialog plugin. Either way, I am stock at the point where I need to hide the current view.

Any ideas how to go with this or how to determine the current active view from the compositionComplete hook inside a dialog context?

Related question on the DurandalJS Google Groups

Edit 1 (following @CodingGorilla comments)

Using the entrance transition as is, is not the important part here. I could live with copying the code of the transition. But what is paramount, is that I should not navigate to a new view. The concept is exactly the same as a dialog in DurandalJS. The only difference is the presentation. A dialog should not have a URL, it is contextual to the current state/window.


回答1:


I think I got it. It is not as pretty as I would like it to be but I am very happy to be able to reuse the dialog plugin and the transition mechanism as is.

Here is the dialog context that I use:

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 () { });
        }
    };
});


来源:https://stackoverflow.com/questions/18537647/how-to-create-full-page-dialog-with-durandaljs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!