简体   繁体   English

Joomla JHtml Behavior.Modal应用于滑动侧栏

[英]Joomla JHtml Behavior.Modal to apply on sliding side bar

I am caught with a problem that a modal popup link that is inside a sliding side bar is not working correctly to open a modal pop up box. 我遇到一个问题,即滑动侧栏内的模式弹出链接无法正常工作以打开模式弹出框。 The sliding sidebar will only open when a user click on it, and in it there will be contents that contain the modal links. 滑动侧栏仅在用户单击时打开,并且其中将包含包含模式链接的内容。

I have added 我已经添加了

Jhtml::_('behavior.modal');

At the beginning of the codes but still doesn't work. 在代码的开头,但仍然无法正常工作。 My link code is as follows 我的链接代码如下

<a class="modal" rel="{handler: 'iframe', size: {x: 750, y: 600}}" href="index.php">Click me</a>

Based on this link, it should open the content in a modal popup box in normal case (on the main page and not in the sliding sidebar). 基于此链接,在正常情况下(应该在主页上,而不是在滑动侧栏中),它应该在模式弹出框中打开内容。 However when it is in the sliding sidebar it doesn't work. 但是,当它在滑动侧栏中时,它不起作用。

The main reason I think of could be because the sliding sidebar is dynamically created after the site has been loaded, so the link will not behave as a modal link but just an ordinary href link. 我想到的主要原因可能是因为滑动侧栏是在网站加载后动态创建的,因此该链接将不会充当模式链接,而只会充当普通的href链接。

I have seen a reply online here suggesting to execute this 我已经看到了网上的答复这里暗示来执行此

SqueezeBox.assign($$('a.modal'), {
parse: 'rel'
});

every time you add a new element. 每次添加新元素时。 But I do not know what it means and how to execute it. 但是我不知道这意味着什么以及如何执行它。

Does anyone here have a solution to make the sliding sidebar modal link work? 这里有没有人有使滑动侧栏模式链接起作用的解决方案?

Finally, i found the answer myself. 最后,我自己找到了答案。 For anyone who may encounter this problem with ajax or dynamic content just add the following to your loading page javascript 对于任何可能会遇到有关Ajax或动态内容的问题的人,只需将以下内容添加到您的加载页面javascript中

$('body').on('click', 'a.osmodal', function(event) {
event.preventDefault();
SqueezeBox.open($(this).attr('href'), {
handler: 'iframe',
size: {x: 900, y: 500}
});
});

This is just a simple contribution, hope someone will find it helpful. 这只是简单的贡献,希望有人会有所帮助。

Wanted to answer your question regarding the proper means to assign Joomla's core modal behavior to dynamically generated content, because you were so close. 想回答有关将Joomla的核心模态行为分配给动态生成的内容的正确方法的问题,因为您是如此亲密。 At work we generate a lot of content using AJAX/lazy loading. 在工作中,我们使用AJAX /延迟加载生成了大量内容。

There are two parameters for assign method. 分配方法有两个参数。 The first indicates which DOM elements to apply, and below I include examples for both assigning by class or id. 第一个指示要应用的DOM元素,下面我提供了按类或ID进行分配的示例。 The second is JSON object options, which 9 times out of 10 will already be attached to the rel attribute of your anchor element. 第二个是JSON对象选项,其中10个中的9个将已附加到anchor元素的rel属性。

A final caveat being this method must be run after dynamically generated HTML is inserted into the DOM. 最后的警告是,必须在将动态生成的HTML插入DOM之后运行此方法。

Using Class 使用课堂

SqueezeBox.assign(
    $$('a.modal.unique-class-identifier'),
    $('a.modal.unique-class-identifier').attr('rel')
});

Using ID 使用ID

SqueezeBox.assign(
   'a.modal#unique-id-identifier',
    $('a.modal.unique-class-identifier').attr('rel')
});

Hope that helps. 希望能有所帮助。

Had the same issue, I dynamically added some links in a Joomla page after the page was already loaded. 遇到相同的问题,我已经在页面加载后在Joomla页面中动态添加了一些链接。 The following snipped added the event handler for the modal dialog on the newly added elements (make sure it's called after the elements were added): 下面的代码片段在新添加的元素上添加了模式对话框的事件处理程序(确保在添加元素后调用该事件处理程序):

<script>
SqueezeBox.assign(jQuery('a.modal'), {
parse: 'rel'
});
</script>

Also make sure, you have the modal functionality loaded in (eg) your template: 还要确保,您已在(例如)模板中加载了模态功能:

JHTML::_('behavior.modal');

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

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