diff --git a/post-selection-ui.js b/post-selection-ui.js index 3ba1e21..607973e 100644 --- a/post-selection-ui.js +++ b/post-selection-ui.js @@ -296,22 +296,54 @@ } + // get wordpress version + var wpVersion = null; + if ( parseInt( PostSelectionUI.wpVersion ) === 4 ) { + + wpVersion = 4; + + } else { + + var versionSplit = PostSelectionUI.wpVersion.split('.'); + wpVersion = parseFloat( parseInt( versionSplit[0] ) + ( parseInt( versionSplit[1] ) / 10 ) ); + + } + //work around for first creation of widget - if ( ( 'object' === typeof wpWidgets ) && ( 'function' === typeof wpWidgets.fixLabels ) ) { + if ( wpVersion >= 3.9 ) { + + $( document ).on( 'widget-added widget-updated', initPostSelectionUIOnEvent ); + + } else { - var oldSave = __bind(wpWidgets, wpWidgets.fixLabels); + if ( ( 'object' === typeof wpWidgets ) && ( 'function' === typeof wpWidgets.appendTitle ) ) { + + var oldAppendTitle = __bind(wpWidgets, wpWidgets.appendTitle); + + wpWidgets.appendTitle = function(widget) { + oldAppendTitle(widget); + if ( ( 'object' === typeof widget ) && ( 'function' === typeof widget.find ) ) { + initPostSelectionUIOnEvent( null, widget ); + } + + }; - wpWidgets.fixLabels = function(widget) { - oldSave(widget); - if(typeof console != 'undefined'){ - console.log(widget); } - initPostSelectionUIOnEvent( null, widget ); - }; - } else { + //work around for rebuilding of widget + if ( ( 'object' === typeof wpWidgets ) && ( 'function' === typeof wpWidgets.save ) ) { - $( document ).on( 'widget-added widget-updated', initPostSelectionUIOnEvent ); + var oldSave = __bind(wpWidgets, wpWidgets.save); + + wpWidgets.save = function (widget, del, animate, order) { + oldSave(widget, del, animate, order); + if (( 'object' === typeof widget ) && ( 'function' === typeof widget.find )) { + initPostSelectionUIOnEvent(null, widget); + } + + + }; + } } diff --git a/post-selection-ui.php b/post-selection-ui.php index 64689c7..f8cc86c 100644 --- a/post-selection-ui.php +++ b/post-selection-ui.php @@ -24,6 +24,7 @@ public static function admin_enqueue_scripts() { 'nonce' => wp_create_nonce( 'psu_search' ), 'spinner' => admin_url( 'images/wpspin_light.gif' ), 'clearConfirmMessage' => __( 'Are you sure you want to clear the selected items?' ), + 'wpVersion' => get_bloginfo( 'version' ) ) ); }