jquery - Fire Wordpress Plugin/Shortcode after Ajax Load -
i have website loads main content via ajax, have run problem getting plugins/shortcodes in said content load. plugins work fine if directly load each page via url bar.
ajax code
jquery(document).ready(function() { var history = window.history; if (!history.enabled) { return false; } // bind statechange event history.adapter.bind(window,'statechange',function(){ var state = history.getstate(); //history.log(state.data, state.title, state.url); var goto_url = state.url; jquery('.content').load(goto_url+ ' #main').hide().delay(750).fadein(1000); }); jquery('.main-menu a').click(function(evt){ var href = jquery(this).attr('href'); history.pushstate({}, '', href); var elementclassname = jquery(this).attr('class'); jquery('.main-menu a').removeclass('active'); jquery('.main-menu a.'+elementclassname).addclass('active'); jquery('.content').load(href+ ' #main', function() { jquery(this).fadein(750); }); return false; }); });
i looking run page specific shortcodes..
<?php echo do_shortcode('[shortcode goes here]'); ?>
after it's corresponding page loaded via ajax. believe correct solution run scripts in load functions callback not sure how shortcodes. if need be, can function being called each shortcode..
example shortcode function
jquery(document).ready(function($){ window.dzsp_init("#port0",{ settings_slideshowtime:3 ,settings_mode: "masonry" ,title: "" ,design_item_width: "" ,design_item_height: "" ,design_categories_style: "normal" ,design_categories_pos: "top" ,design_pagecontent_pos: "top" ,settings_disablecats: "off" ,settings_lightboxlibrary: "zoombox" ,settings_preloadall: "off" ,audioplayer_swflocation: "http://sbmdesigns.net/wp-content/plugins/dzs-portfolio/ap.swf" ,videoplayer_swflocation: "http://sbmdesigns.net/wp-content/plugins/dzs-portfolio/preview.swf" ,disable_itemmeta: "off" ,settings_ajax_loadmoremethod: "button" ,settings_mode_masonry_layout: "masonry" ,design_total_height_full: "off" ,settings_mode_masonry_layout_straightacross_setitemsoncenter: "off" ,design_item_height_same_as_width : "off"}) });
not elegant solution, depending on plugins/shortcodes trying re-init, can many in .load callback appropriate jquery initialization.
$( "#result" ).load( "ajax/test.html", function() { /*put re-init code here*/ });
for example flex sliders:
jquery('.slider-<?php echo $slider->id; ?>').flexslider({ animation: "<?php echo $animation; ?>", easing: "swing", direction: "<?php echo $direction; ?>", slideshowspeed: "<?php echo $slideshow_speed; ?>", animationspeed: "<?php echo $animation_speed; ?>", controlnav: <?php echo $control_nav; ?>, directionnav: <?php echo $directional_nav; ?>, pauseonaction: <?php echo $action; ?>, pauseonhover: <?php echo $hover; ?>, usecss: false });
or replicate audio shortcode (with proper scripts enqueued in functions.php):
$('.asset-audio').mediaelementplayer({videoheight: 30, videowidth: 0, alwaysshowcontrols: true, features: ['playpause','progress','current','duration','volume'], });
Comments
Post a Comment