if (!RedactorPlugins) var RedactorPlugins = {}; (function ($, undefined) { $.fn.getCursorPosition = function () { var el = $(this).get(0); var pos = 0; if ('selectionStart' in el) { pos = el.selectionStart; } else if ('selection' in document) { el.focus(); var Sel = document.selection.createRange(); var SelLength = document.selection.createRange().text.length; Sel.moveStart('character', -el.value.length); pos = Sel.text.length - SelLength; } return pos; } })(jQuery); // When i come back to it, we'll want to use the plugin above to log the cursor position // before the modal is triggered and the position is lost. // $(this).getCursorPosition()); RedactorPlugins.clips = { init: function() { var callback = $.proxy(function() { $('#redactor_modal').find('.redactor_clip_link').each($.proxy(function(i, s) { $(s).click($.proxy(function() { this.insertClip($(s).next().html()); return false; }, this)); }, this)); this.selectionSave(); this.bufferSet(); }, this ); this.buttonAdd('clips', 'Clips', function(e) { this.modalInit('Clips', '#clipsmodal', 500, callback); }); }, insertClip: function(html) { this.selectionRestore(); this.insertHtml($.trim(html)); this.modalClose(); } };