How display a dialog use javascript only on Jquery mobile 1.4 - javascript

I'm looking for a way only use javascript to display a dialog , The dialog display include:
Title
(operation icon) Content
Button(OK)
But after I see the sample in the Jquery mobile document, Looks like If I want to display a dialog, I must use some html+css code, But I just want to use javascript only to display it.
The sample dialog already not support the new version Jquery mobile, it's not working.
the popup so ugly, only has content, not button like OK, also no close button.
So Is there any way can display a good dialog(not so simple like popup) only use javascript? Also can use Jquery.

jQuery Mobile Popups can absolutely handle your requirements. It is no problem to include titles, content, buttons, and a top corner close button. Additionally you can add the popup via script instead of markup in the page.
For example, if you have the following button on your page:
<button id="btnDynamic">Dynamic Popup...</button>
And you want to launch a dialog when it is clicked, your script could be something like this:
$("#btnDynamic").on("click", function () {
//create the popup markup
var html = CreatePopup("Dynamic", "This popup is created and launched entirely via script");
//append popup to DOM, tell jqm to enhance and initialize the popup
// and to remove the popup from DOM on close
$("#page1").append(html).find("#mypDialog").enhanceWithin().popup({
afterclose: function (event, ui) {
//remove from DOM on close
$("#mypDialog").remove();
}
}).popup("open", {
transition: "flow",
positionTo: "window"
});
//Add click handler for button in popup
$("#mypDialog").on("click", "#btnPopOK", function(){
alert("You clicked OK, I will now close the popup");
$("#mypDialog").popup("close");
});
});
function CreatePopup(title, content){
var html = '<div data-role="popup" id="mypDialog" data-overlay-theme="b" data-theme="a" data-dismissible="false" >';
html += '<div data-role="header"><h1>' + title + '</h1>Close</div>';
html += '<div role="main" class="ui-content"> <h3 class="ui-title">' + content + '</h3>Cancel<a id="btnPopOK" href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline" data-transition="flow">OK</a></div>';
html += '</div>';
return html;
}
I am creating the popup markup as a string. That string is then appended to the data-role="page" DIV. We then find the popup div (We assigned an id of myDialog to it) and tell jQM to enhance the content of the popup, initialize the popup widget with an afterclose callback that removes the popup from the DOM once closed, and finally the command to show the popup. I have also included a handler for the OK button click.
Here is a working DEMO. Note I have also included a static popup in the DEMO.

Related

Fancybox modal popup content not loaded properly in magento1?

Actually I got the popup modal fancy box problem where the popup is not loaded the content properly. The modal div is by default to display none. And I need to show that modal on click event.
I am using the module for AfterPAy payment method where this feature is included. When We click on the learn more button then the popup is open but not the content in that fancy box. I need to make it perfect. This my website URl https://www.tradie.com/tradie-honey-badger-sports-mid-length-trunk-1371.html
(function($) {
$(document).on('ready', function() {
$('.afterpay-what-is-modal-trigger').fancybox({
afterLoad: function() {
$('#afterpay-what-is-modal').css("display", "block");
}
afterShow: function() {
$('#afterpay-what-is-modal').find('.close-afterpay-button').on('click', function(event) {
event.preventDefault();
$.fancybox.close();
})
}
})
});
})(jQuery);
The above js code is in the file of extension modal.js. Here the aftershow function is working, but afterload is not working. Please how that modal will open properly with content.
Thanks.
As per the concern there is a div that is inline set to display none. So when you will hit the link/button then the modal will blanks due to that inline css.
Please find the html of the modal file and add an extra div at the top of that code and set display none to that div inline.
e.g.,
<div style="display:none;">
<div id="afterpay-what-is-modal">
<!--some modal code for popup-->
</div>
</div>
Add a div before the and style it to display none inline that it.
Hope this will work for you.

jquery tabbed ui - javascript in loaded code not working anymore

I am trying to use the jQuery tabbed widget as a menu for my application and have managed to set up the tabbed interface so that when you click a tab it shows the first page of that section. According to the docs, if you click on a link on this page and want it to load in the same tab then you need to use the code below. This partially works because now when I click on an image-hyperlink on that page it renders the new page in the tabbed window.
However, when I click on a button which has javascript the button no longer works. This is the case for all of the javascript. How can I get the javascript working again under the new tabbed interface?
$('#example').tabs({
load: function(event, ui) {
$(ui.panel).delegate('a', 'click', function(event) {
$(ui.panel).load(this.href);
event.preventDefault();
});
}
});
EDIT: So if you add the following line to LeftyX's code in the page 1 file, then the button causes page4.html to open but does not do it in the tab
<button onclick="location.href='Page4.html'">Test button </button>
It must work.
If you show us your HTML we might try to help.
You can check my sample and download the code.
Try and check if there are any errors in your script using some Dev Tools (ex: Google Chrome Developer Tools)
UPDATE:
if you're using a button you can use some HTML5 attribute:
<button data-pagelink="Page4.html">Test button</button>
and trap the click event:
$(ui.panel).delegate('button', 'click', function(event, o) {
$(ui.panel).load(this.dataset.pagelink);
event.preventDefault();
});
or use an hyperlink and transform it in a button:
<a id="thisIsAButton" href="Page4.html">go to page 4</a>
with this:
$("#thisIsAButton").button();

How to display HTML Content using window.showModalDialog()

Will I be able to display a HTML content (not a file) in a pop up window using JS?
I am trying to open a pop up window and display an user defined HTML inside this. I am trying the below, but it doesn't work.
window.showModalDialog("<p>Pop up window text</p>","resizable: yes");
Can some one suggest me how to do this? Thanks in advance.
Contrary to window.open(), the first (URL) argument of showModalDialog() is required. Thus, you can't pass it an HTML string. You can either use window.open:
var newWindow = window.open("", "newWindow", "resizable=yes");
newWindow.document.write('<p>Pop up window text</p>');
Or alternatively, use one the existing modal plugins, such as jQuery UI Dialog or Twitter Bootstrap Modals. They allow you to easily display a modal window based on the content of an existing HTML element, e.g.:
<div id="dialog">
<p>Pop up window text</p>
</div>
$('#dialog').modal(); // Twitter Bootstrap
$("#dialog").dialog({ resizable: true }); // jQuery UI

Colorbox IE display inline href function doesn't get triggered second time the the same link clicked

Hi hope some one can help. Have been trying to display some hidden inline content in a colorbox. Everything works great in firefox but in IE8 it works the first time then fails the second. When using alert(id) the id var is coming up as undefined the second time in IE.
Have tried a click handler to set the id and I get the same result. Here's some sample html (simplified for clarity). This is generated by Drupal CMS
<div class="my-div">
<a class="pop-extra nid-628 cboxElement" href="/alex-f">the link triggering colorbox</a>
<div id="628" class="inline-content" style="display: none;">
The hidden content to display
</div>
</div>
Here's my jquery
$(document).ready(function() {
// Hide inline content
$('.inline-content').hide();
//Fire colorbox
$('a.pop-extra').colorbox(
{
height:700,
width:420,
inline:true,
//Set the inline content to display dynamicaly by grabing the next div id
href:
function(){
id = $(this).next().attr("id");
return '#'+id;
},
onOpen:function(){
//Show the content so colorbox has something to display
$('#'+id).show();
},
});
$(document).bind('cbox_closed', function(){
//Hide content again when colorbox closes
$('#'+id).hide();
});
});
To see a demo please have a look at this url:
http://eyestoneartists-com-au.kept.com.au/browse-extras/male/all
To reproduce in IE8 click one of the images, then close the image then click it again.
put the content in another div and then display:none in a div before it.

jQuery UI Dialog - change the content of an open dialog (Ajax)

I've got some links I want to have dynamically open in a jQuery UI Dialog using jQuery.load(). Once the dialog is open, I want the links load inside the already opened dialog.
So, the site loads, you click a link, and it opens in a dialog. That's fine. You can close and open it as many times as you want.
While it's open, if you click on one of the links from the loaded content, it doesn't work.
An Ajax GET request IS performed, but the resulting content is not successfully loaded into the dialog. (Firebug shows the request)
The previous dialog title and dialog content is erased. But the new content is not shown, NOR is it inserted into the DOM. (The generated source does not show content anywhere.)
The links look like this...
<a href="http://www.example.com/index.php?action=something&search=somethingelse#fragment" rel="dialog" title="Title Attribute">
The click event is bound...
$('body').delegate("a[rel~=dialog]", "click", function(e){return ajax_dialog(this, e);});
The ajax_dialog function checks to see if there's a dialog, calls to create one if there isn't, calls to load the content, sets the title, and opens the dialog if it's not open.
function ajax_dialog(_this, _event){
var urlToLoad = $(_this).attr("href").replace("#", "&ajax=true #");
var linkTitle = $(_this).attr("title");
// Create dialog
if(!$('body').find('#ajaxDialog').size()){
$('body').append('not yet init<br />'); // This shows up the first click only.
init_dialog('#ajaxDialog');
}
// Load Dialog Content
load_dialog('#ajaxDialog', urlToLoad);
// Add title
$('#ajaxDialog').dialog('option', 'title', linkTitle);
// Open dialog (or reload)
if(!$('#ajaxDialog').dialog('isOpen')){
$('#ajaxDialog').dialog('open');
$('body').append('not yet open<br />'); // This shows up the first click only.
}
return false;
}
The init_dialog function creates the dialog if there isn't one...
function init_dialog(_this){
$('body').append('<div id="ajaxDialog"></div>');
// Set Dialog Options
$(_this).dialog({
modal:true,
autoOpen:false,
width:900,
height:400,
position:['center','center'],
zIndex: 9999,
//open:function(){load_dialog(this, urlToLoad);}, This didn't work without destroying the dialog for each click.
close:function(){$(this).empty();}
});
}
The load_dialog function loads the desired content into the dialog.
function load_dialog(_this, urlToLoad){
$(_this).load(urlToLoad, function(){
$('body').append(urlToLoad + ' load function<br />'); // This shows up each click
$(_this).append("Hihi?"); // This shows up each click
});
// The loaded information only shows the first click, other times show an empty dialog.
}
Hah. As shown in the code, I was using $jQuery.load() and pulling the exact href of the link as the URL to request. All the URLs had fragments/anchors on the end, that is: ....html#id-of-div.
In this case, the script itself was working fine, but the #id-of-div didn't exist on the page yet. That's why I could see content returned, but the dialog just ended up blank. :-)

Categories