Hi guys! I've written some jQuery which creates a textarea based on the selection from an autocomplete.
I'm attempting to turn that textarea into a CKEditor instance, but I'm not having any joy:
var objText = []; $(document).ready(function(){ $("#dialogue-links-bookmarks").hide(); $('.bookmark-links').click(function(event) { $("#dialogue-links-bookmarks").fadeIn('slow'); $('#link-bookmarks').focus(); }); $('#close-bookmarks').click(function() { $("#dialogue-links-bookmarks").fadeOut('slow'); }); $('#link-bookmarks').autocomplete({ source: base_url + "bookmarks/jq_get_bookmarks_by_search_as_object/", appendTo: ".bookmark-link-results", position: { my : "left top", at: "left bottom", collision: "flipfit" }, open: function(event, ui) { $('ul.ui-autocomplete#link-bookmarks') .removeAttr('style') .hide() .appendTo('.bookmark-link-results') .show(); $('#links-bookmarks').show(); }, select: function(event, ui) { $('.bookmark-link-results') .append('<div class="bookmark-link-box" id="bookmark-link-box-' + ui.item.bookmark_id + '"><input type="checkbox" id="bookmark-link-item-' + ui.item.bookmark_id + '" name="bookmark-links-add[]" value="' + ui.item.bookmark_id + '" checked="checked"><a href="' + base_url + 'bookmarks/edit/' + ui.item.bookmark_id + '" title="Edit ' + ui.item.title + '">' + ui.item.title + '</a> <a href="' + base_url + 'bookmarks/view/' + ui.item.bookmark_id + '"><img src="' + base_url + 'library/images/ui/icons/tables/view.png" alt="view" width="14" height="14" class="icons-actions" /></a> <a href="' + base_url + 'bookmarks/visit/' + ui.item.bookmark_id + '" target="_blank" rel="nofollow"><img src="' + base_url + 'library/images/ui/icons/tables/link.png" alt="link" width="14" height="14" class="icons-actions" /></a><br /><textarea class="comment" id="bookmark-link-comment-box-' + ui.item.bookmark_id + '" name="bookmark-link-comments[]"></textarea></div>'); objText.push(ui.item.bookmark_id); CKEDITOR.replace('bookmark-link-comment-box-' + ui.item.bookmark_id, { customConfig: config }); } }).data("uiAutocomplete")._renderItem = function(ul, item) { return $('<li></li>') .data("item.autocomplete", item) .append('<strong>' + item.title + '</strong><br /><em><a>' + item.snippet + '</a></em>') .appendTo(ul); }; var id, element; $('.link-bookmark-comment-edit').click(function(event) { event.preventDefault(); id = $(this).data("link-bookmark-comment"); element = "#bookmark-link-comment-" + $(this).data("link-bookmark-comment"); $(element).fadeToggle('200'); }); $('.link-bookmark-comment-save').click(function(event) { event.preventDefault(); $.ajax({ url: base_url + "bookmarks/jq_set_bookmark_link_comment/" + id, type: 'POST', data: { 'comment': CKEDITOR.instances["link-bookmark-comment-" + id].getData() }, success: function (data) { $("#link-bookmark-comment-display-" + id).html(CKEDITOR.instances["link-bookmark-comment-" + id].getData()); }, error: function () {} }); }); });
I'm guessing the problem is — perhaps — in two parts:
- the append() function, and my attempt to access a dynamic object;
- the actual code I'm using to instantiate CKEditor itself.
Any advice would be great, thanks!
Just for completeness, the
Just for completeness, the problem was the placement of the config variable definition; it needs to be placed at or near the bottom of the page, rather than at the top, prior to code execution.