[wp-trac] [WordPress Trac] #26881: Multiple wp_editor() on one page and link button broken
WordPress Trac
noreply at wordpress.org
Fri Apr 24 15:54:13 UTC 2015
#26881: Multiple wp_editor() on one page and link button broken
-------------------------------+-----------------------
Reporter: machinedean | Owner:
Type: defect (bug) | Status: reopened
Priority: normal | Milestone:
Component: Editor | Version:
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses:
-------------------------------+-----------------------
Changes (by xwolf):
* version: 3.8 =>
Comment:
After updating to 4.2 today this error happens also to my code:
Search field wont get populated anymore, modal window wont get closed.
(it worked fine till 4.1.3)
My code:
{{{
wp_enqueue_script( 'wp-link' );
echo '<div class="linkinput">';
$rand = rand();
echo '<h2 class="label">'.$labeltext.'</h2>';
if (strlen(trim($howtotext))) {
echo '<p class="howto">';
echo $howtotext;
echo "</p>\n";
}
echo '<div class="linkentry" id="container_'.$rand.'">';
echo "<p>\n";
echo '<label
for="title_'.$rand.'_'.$name.'">'.__('Title','wphelper');
echo "</label><br />\n";
echo '<input type="text" class="large-text"
name="'.$name.'_title" id="title_'.$rand.'_'.$name.'"
value="'.$pretitle.'">';
echo "</p>\n";
echo "<p>\n";
echo '<label
for="url_'.$rand.'_'.$name.'">'.__('URL','wphelper');
echo "</label><br />\n";
echo '<input type="url" class="large-text"
name="'.$name.'_url" id="url_'.$rand.'_'.$name.'" value="'.$preurl.'"
placeholder="https://">';
echo "</p>";
echo '<p><input class="button link_button_'.$name.'"
name="link_button_'.$name.'" id="link_button_'.$name.'" type="button"
value="'.__('Chose Link','wphelper').'"></p>';
echo "</div>\n";
?>
<script>
var _link_sideload = false;
var link_btn_<?php echo $name?> = (function($){
var _link_sideload = false;
function _init() {
$('.link_button_<?php echo $name?>').on('click',
function(event) {
_addLinkListeners();
_link_sideload = false;
var link_val_container = $('#url_<?php echo
$rand?>_<?php echo $name?>');
window.wpActiveEditor = true;
_link_sideload = true;
wpLink.open();
wpLink.textarea = $(link_val_container);
return false;
});
}
function _addLinkListeners() {
$('body').on('click', '#wp-link-submit',
function(event) {
var linkAtts = wpLink.getAttrs();
$('#url_<?php echo $rand?>_<?php echo
$name?>').val(linkAtts.href);
$('#title_<?php echo $rand?>_<?php echo
$name?>').val(linkAtts.title);
_removeLinkListeners();
return false;
});
$('body').on('click', '#wp-link-cancel',
function(event) {
_removeLinkListeners();
return false;
});
}
function _removeLinkListeners() {
if(_link_sideload){
if ( typeof wpActiveEditor != 'undefined') {
wpActiveEditor = undefined;
}
}
wpLink.close();
wpLink.textarea = $('html');//focus on document
$('body').off('click', '#wp-link-submit');
$('body').off('click', '#wp-link-cancel');
}
return {
init: _init,
};
})(jQuery);
jQuery(document).ready(function($) {
link_btn_<?php echo $name?>.init();
});
</script>
<?php
echo "</div>\n";
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/26881#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list