简体   繁体   English

jQuery Mobile站点中所有页面共有的弹出窗口

[英]Popups common to all pages in jQuery Mobile site

I am trying to make a site using jQuery Mobile. 我正在尝试使用jQuery Mobile创建一个站点。 It consists of many pages in HTML files, some of which have only one page, and some of which have several pages (using their multi-page feature ). 它由HTML文件中的许多页面组成,其中一些页面只有一个页面,其中一些页面有多个页面(使用它们的多页面功能 )。

The site is going to have some popups for notifications, and they are going to look the same on all pages. 该网站将有一些通知弹出窗口,并且它们在所有页面上看起来都是一样的。 I am implementing the popups using their new popup feature which seems designed for this purpose. 我正在使用新的弹出功能实现弹出窗口,这个功能似乎是为此目的而设计的。 I can easily implement this by putting copies of the popups on each of the pages but this will create a lot of redundant code which may be hard to maintain. 我可以通过在每个页面上放置弹出窗口的副本来轻松实现这一点,但这会产生很多可能难以维护的冗余代码。 I can probably make my server insert the code for me in the proper places but that seems complex and inefficient. 我可以让我的服务器在适当的位置为我插入代码,但这似乎很复杂,效率低下。

I tried putting the popups outside of the pages and they do not work reliably (you can see an example here ). 我尝试将弹出窗口放在页面之外并且它们不能可靠地工作(你可以在这里看到一个例子)。

I tried dynamically generating them by using a templating system (the one built into underscore.js) but that looks like it may cause problems – I will have to destroy every popup when it is closed to avoid memory leaks. 我尝试使用模板系统(内置于underscore.js中)来动态生成它们,但看起来它可能会导致问题 - 我必须在关闭时销毁每个弹出窗口以避免内存泄漏。

I am not sure if this is a bug in the popup widget, which seems likely since the popup widget is only in an alpha version of jQuery Mobile. 我不确定这是否是弹出窗口小部件中的错误,这似乎很可能因为弹出窗口小部件仅在jQuery Mobile的alpha版本中。

Does anyone here have any ideas as to how to make a site with many pages in several html files, with a few popups that are common to all of the pages? 这里有没有人有任何想法如何在几个html文件中创建一个包含许多页面的网站,并且所有页面都有一些共同的弹出窗口?

I've seen your request on jQuery Mobile github, and posted a solution that I'm using on my web applications. 我在jQuery Mobile github上看到了你的请求,并发布了我在我的web应用程序上使用的解决方案。 Check http://ghita.org/jquery/dynamic-mobile-popup it's a small plugin that allows you to have dynamic popups, it let you focus on the content of the popup and the events . 检查http://ghita.org/jquery/dynamic-mobile-popup它是一个小插件,可以让你有动态弹出窗口,它让您专注于弹出式窗口, 事件 内容

Include the plugin (has 1.8kb ), and then call: 包括插件(有1.8kb ),然后调用:

$.dynamicPopup({content: 'This is the dynamic content of the popup.'});

content - can be a string or a jQuery html object. content - 可以是字符串或jQuery html对象。

Check https://github.com/serbanghita/jQM-dynamic-popup for the full list of options, some of which are inherited from jQuery's mobile popup() function. 检查https://github.com/serbanghita/jQM-dynamic-popup以获取完整的选项列表,其中一些选项继承自jQuery的mobile popup()函数。

This problem was a show stopper for me because I have dynamic webpages and I don't care of manually injecting HTML content for the popup() to be active. 这个问题对我来说是一个阻碍,因为我有动态网页,我不关心手动注入HTML内容让popup()处于活动状态。 Hope you find it helpful. 希望你觉得它有用。

you would have to try and set it up like the jqm loader, which also resides outside of the div.page (otherwise you would have one loader per page inside the dom), so i think the right approach would be to not include the popup within a page, but outside the div.page. 你必须尝试像jqm加载器一样设置它,它也位于div.page之外(否则你将在dom中每页有一个加载器),所以我认为正确的方法是不包括弹出窗口在页面内,但在div.page之外。

as jqm will only pull in div.pages and nothing before/after you should be able to include a generic popover on every page and only have it in the dom once. 因为jqm只能拉入div.pages而且之前/之后没有任何东西你应该能够在每个页面上包含一个通用的popover并且只在dom中有一次。 not sure this is working though outside div.page. 不确定这是在div.page外面工作。

May be very late to the party, but may be useful for someone coming across. 派对可能会很晚,但可能对遇到的人有用。

Now you can use Global Popups if you are using latest JQM (I am using JQM 1.4.2). 现在,如果您使用的是最新的JQM(我正在使用JQM 1.4.2),您可以使用全局弹出窗口。 You just need to declare the popup directly under body div, out side all data-role pages. 您只需要在body div下面直接声明弹出窗口,在所有数据角色页面外面。

Better go through this JQM documentation 最好通过这个JQM文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM