WordPress Theme Development: Is there a way to trigger a JavaScript function when a particular widget is drag-and-dropped in widgets.php of the admin area?
-
This kind of works but it applies to all widgets. jQuery('div.widgets-sortables').bind('sortstop',function(event,ui){ // run js after widget dropped into sidebar area }); ( http://stackoverflow.com/questions/4087677/how-can-i-hook-into-the-jquery-ui-drop-event-when-moving-widgets-around-in-wordp ) I'm wondering if it could be only applied to the widget that I create for my plugin or theme.
-
Answer:
Hi, just replace 'your_widget' with name of your widget in the code below (two places). 'sortreceive' event is only called when widget is added to sidebar, while 'sortstop' gets called whenever you move the widget around inside sidebar or remove it. 'sortstop' is also called when widget is added, but for some reason ui.input is not set properly, so i used 'sortreceive' to cover that. jQuery('div.widgets-sortables').bind('sortstop',function(event,ui){ var id = jQuery(ui.item).attr('id'); if (id) { var widget_type = id.match(/widget-[0-9]+_(.+)-[0-9]+/i)[1]; if (widget_type == 'your_widget') { // do stuff; } } }) jQuery('div.widgets-sortables').bind('sortreceive',function(event,ui){ var id = jQuery(ui.item).attr('id'); var widget_type = id.match(/widget-[0-9]+_(.+)-__i__/i)[1]; if (widget_type == 'your_widget') { // do stuff; } })
Arūnas Liuiza at Quora Visit the source
Related Q & A:
- Is there a way of creating a interactive word document?Best solution by pcworld.com
- Is there a way to utilize a directv receiver for local HD reception without a subscription?Best solution by Yahoo! Answers
- Is there a way to attach a picture to your question?Best solution by Yahoo! Answers
- Is there a way to edit a line of tracking interference down recorded video tape on computer?Best solution by Yahoo! Answers
- How to graph a quadratic function on a graphing calculator?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.