UI Dialog window - How to not display dialog until content is loaded? - jquery-ui-dialog

I've been experimenting with using a UI Dialog window to display an existing form (page with the form and no layout). I'm not sure if I'm doing this the right way but it seems to work fine minus a couple of pieces of bad behavior. This is the behavior right now:
The dialog window with no conent opens (very small/empty)
About a half second later the content loads and the window expands insantly (looks bad visually)
Even though the window width expands when the content is loaded, the title bar does not adjust to the new width and remains very small width wise. Although if resizeable is set to 'true' the title will expand. It's just not responding with a width adjustment when the content from the hidden div is loaded.
How could I go about not displaying the dialog until the content is finished loading into the dialog, and how could I force the dialog title to width adjust right after the content is finished loading?
<A HREF="javascript:newItem('foo')">CREATE NEW FOO ITEM<A>
<script type="text/javascript">
newItem= function(type) {
$("#form_load").load(
'/items/new', {item_type: type}).dialog({
modal:true,
draggable: true,
resizable: false,
width:'auto',
height:'auto',
title: 'Some title',
position: [150, 150]
});
};
</script>
Thanks!

You're going to want to call the dialog after the content is loading.
You can do this by using $.load's callback method.
<script type="text/javascript">
newItem = function(type) {
$("#form_load").hide().load(
'/items/new',
{item_type: type},
function (data) {
$(this).dialog({
modal : true,
draggable : true,
resizable : false,
width : 'auto',
height : 'auto',
title : 'Some title',
position : [100, 100]
});
}
});
}
</script>
You may also want to include a hide/show toggle so the #form_load container isn't displayed until the content is loaded.
See jQuery's $.load docs here: http://api.jquery.com/load/
UPDATE: Added .hide() so content isn't shown until dialog is created.

Related

Magnific Popup Wordpress Audio Shortcode Keeps Playing after Close

I have created an inline popup for my custom Wordpress theme using Magnific Popup and the wp_audio_shortcode() function. It works beautifully, except that the audio keeps playing when I close the popup. (Embedded video stops exactly as expected, which is great!)
I read this post magnific-popup, how to play an audio file when popup open and stop playing when closing it and it didn't quite address my problem; I get several javascript errors.
Any help would be greatly appreciated!
Here is the HTML for the popup window that my function renders. I have removed extraneous things like web addresses and multi-line headlines.
THE LINK PEOPLE CLICK:
<span class="pop-up-wrapper"><h2 class="homecard-title">Link Text</h2></span>
THE POPUP THAT APPEARS:
<div id="popup-3" class="pop-up-post zoom-anim-dialog">
<div class="pop-up-left"><img src="graphic.jpg" class="pop-up-back-image"></div>
<div class="pop-up-right">
<h2 class="homecard-title">Headline Here<br><span class="play-wrapper" id="audio-3"><!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->
<audio class="audio-3" id="audio-104-1" preload="none" style="width: 100%;" controls="controls"><source type="audio/mpeg" src="http://vivenne:8888/wp-content/uploads/2019/04/Vivienne-Leheny-Hot-Winter-NIghts-Lucas-Mom.mp3?_=1">http://vivenne:8888/wp-content/uploads/2019/04/Vivienne-Leheny-Hot-Winter-NIghts-Lucas-Mom.mp3</audio></span></h2>
</div>
<button title="Close (Esc)" type="button" class="mfp-close">×</button>
</div>
The jquery for Magnific (taken directly from the website):
$('.popup-with-zoom-anim').magnificPopup({
type: 'inline',
fixedContentPos: false,
fixedBgPos: true,
overflowY: 'auto',
closeBtnInside: true,
preloader: false,
midClick: true,
removalDelay: 300,
mainClass: 'my-mfp-zoom-in',
});
When the close button is clicked, I would like the audio to STOP playing, but it continues in the background.
Well folks, I solved it. I abandoned the wp_audio_shortcode(), which made it easier to assign an ID to the <audio> element.
I am happy to provide all of the code, but I think it's confusing out-of-context. Here are the important tidbits…
The magnificPopup container gets a data-ref attribute that matches the audio player's ID contained within it. (I did this with a simple $count variable because there are several popups on the page.)
The important part for the magnificPopup jQuery is this:
callbacks: {
close: function(){
var magnificPopupVar = $.magnificPopup.instance,
magnificPopupSrc = magnificPopupVar.currItem.src,
magnificPopupRef = $(magnificPopupSrc).attr('data-ref'),
audioplayer = document.getElementById('audio-popup-'+magnificPopupRef);
audioplayer.pause();
}
}
In context:
$('.popup-with-zoom-anim').magnificPopup({
type: 'inline',
fixedContentPos: false,
fixedBgPos: true,
overflowY: 'auto',
closeBtnInside: true,
preloader: false,
modal:false,
midClick: true,
removalDelay: 300,
mainClass: 'my-mfp-zoom-in',
callbacks: {
close: function(){
var magnificPopupVar = $.magnificPopup.instance,
magnificPopupSrc = magnificPopupVar.currItem.src,
magnificPopupRef = $(magnificPopupSrc).attr('data-ref'),
audioplayer = document.getElementById('audio-popup-'+magnificPopupRef);
audioplayer.pause();
}
}
});
I hope that's helpful to someone else trying to sort this out!

resize header not working on DataTable js

I've got a datatable that is responsive, except for the header. The table is initialized according to the code below:
$('.datatable-objects').DataTable({
autoWidth: false,
responsive: true,
scrollX: true,
dom: '<"datatable-header"fl><"datatable-scroll-wrap"t><"datatable-footer"ip>',
language: {
search: '<span>Filter:</span> _INPUT_',
lengthMenu: '<span>Show:</span> _MENU_',
paginate: { 'first': 'First', 'last': 'Last', 'next': '→', 'previous': '←' }
}
});
// Add placeholder to the datatable filter option
$('.dataTables_filter input[type=search]').attr('placeholder','Type to filter...');
// Enable Select2 select for the length option
$('.dataTables_length select').select2({
minimumResultsForSearch: Infinity,
width: 'auto'
});
$('.dataTables_scrollHeadInner').css({"width":"100%"});
$('.datatable-objects').css({"width":"100%"});
$('.datatable-objects').on( 'draw.dt', function () {
$('.dataTables_scrollHeadInner').css({"width":"100%"});
$('.datatable-objects').css({"width":"100%"});
});
});
I need the css hacks at the end in order to make it resize appropriately on window resize. Otherwise, there is a hard size put in the width property and resizing is not working correctly.
I'm not clear on why I need to add this, while in other examples I see there is no need. Anybody a suggestion?
Let's say you have the "tbl-principal" table, then you just need to add as follows:
$('#tbl-principal').dataTable().fnAdjustColumnSizing();
Remarks: if you need to resie on window resize, the code of above needs to be putted on $(window) resize function.
In my case, I´m doing a show/hide div, so... i just put the code on my function...
And that's it... It's working!

wordpress media uploader window size

i got one issue that im stacked on.
Im running the media uploader window from a colorbox modal window, which i set to 90% width, and inside i have button which trigger the media uploader (opens second window).
but when i trigger it, it everytime opens smaller modal window than the parent colorbox modal.
i think the problem is that my first window is an Iframe and when i trigger another modal, it takes the iframe as main window and by some percentage it makes the second window smaller. this could fix if i know where to set, that the second window should be 100%.
Do you know where can i set the width and height for the window with media uploader? i tried with the "40" value, but it doesnt work. i cant find no documentation for this.
thanks for reply.
screenshot here: screencast link
my code is
var file_frame1;
jQuery('#mxn_button_add_img1').on('click', function(event) {
event.preventDefault();
// If the media frame already exists, reopen it.
if (file_frame1) {
file_frame1.open();
return;
}
// Create the media frame.
file_frame1 = wp.media.frames.file_frame = wp.media({
title: jQuery(this).data('uploader_title'),
width: 40,
button: {
text: jQuery(this).data('uploader_button_text'),
},
multiple: false // Set to true to allow multiple files to be selected
});
// When an image is selected, run a callback.
// When an image is selected, run a callback.
file_frame1.on('select', function() {
var selection = file_frame1.state().get('selection');
selection.map(function(attachment) {
attachment = attachment.toJSON();
jQuery('#mxn_input_img1').val(attachment.url);
jQuery('#mxn_post_img1').attr('src', attachment.url);
return false;
});
});
});

jQuery modal height is too small

I have a dialog that pops on $(document).ready(function() {, it blocks the whole page with modal : true.
$(function () {
$("#dialog").dialog({
show: { effect: 'drop', direction: "up" },
hide: "explode",
modal: true,
draggable: false,
resizable: false
});
});
The problem is that when $(document).ready(function() { fires, all the images in the page may not be loaded.
It results in having the overlay's height smaller than the page actually is.
(ex :) You have a page with 2 images (height of 100px). When the $(document).ready(function() { fires, you have a height of 800px, then the overlay appears, with a height of 800px. after that, when the images had the time to load, you have a 1000px page... So if I scroll down, there is 200px at the bottom that is not blocked by the overlay.
What i'm trying to do is, when $(window).load(function() { will fire (so everything will be loaded), refresh the height of the overlay, if the dialog had not been closed of course.
I noticed that, once all of the images are loaded, if I zoom +/- or If I open Chrome's developer tool, it refreshes the overlay height.
Thank you!
I fixed it, I wonder if there is a more efficient way to do this..
$(function () {
$("#dialog").dialog({
show: { effect: 'drop', direction: "up" },
hide: "explode",
modal: true,
draggable: false,
resizable: false
});
});
$(window).load(function() {
$(window).resize();
});
So I pop the dialog, then when the images are loaded, I just refresh the size..

How do I add a button to the bottom bar in extjs?

I try to add a text filed and a button to the grid panel in extjs with following code:
var shopIdInput = new Ext.form.TextField({
emptyText: "请输入商户Id",
width: 200
});
var deleteOneShopCacheBtn = new Ext.Button({
text : '删除商户缓存',
handler: deleteOneShopCache,
minWidth : 100,
cls: "delBtn"
});
......
var grid = new Ext.grid.GridPanel({
store: store,
columns: columns,
bbar: [shopIdInput, deleteOneShopCacheBtn],
buttons: [clearRedressWordCacheBtn, clearSplitWordCacheBtn, clearRegionCacheBtn, clearCategoryCacheBtn, runCommandBtn],
items: [commandForm],
buttonAlign: 'center',
stripeRows: true,
autoExpandColumn: 'serverUrl',
//title: '批量执行指令',
sm: checkboxSelect,
frame: true,
autoHeight: true,
enableColumnHide: false,
renderTo : 'serverInfoList'
});
But the button deleteOneShopCacheBtn in bbar doesn't look like a common button as button clearRedressWordCacheBtn in buttons. It changes to a button when the mouse is on it. I have tried to fix the problem by set the property cls and fail, so what can I do?
I usually just add an icon to the button which helps it stand out. so just set a value for
iconCls: 'mybuttonicon'
and in your css
.mybuttonicon { background-image: url(../path/to/icon) !important;}
the cls config allows you to specify additional classes to which to apply to your renderable object (in your case a button) but does NOT do anything with making it change based on the mouse hovering over it, etc.
What you need is a listener on deleteOneShopCacheBtn and listen to the mouseover event(also see Sencha docs for the list of events a button responds to). You can fire off a function and make your button look like whatever you want. I am currently at work. If you still have this question when I get home tonight I can post some code.
Also see following example:
Button click event Ext JS
}

Resources