app/assets/javascripts/annex/jquery.redactor.clips.js in annex-cms-0.1.8 vs app/assets/javascripts/annex/jquery.redactor.clips.js in annex-cms-0.2.0
- old
+ new
@@ -1,56 +1,60 @@
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);
+RedactorPlugins.clips = function()
+{
+ return {
+ init: function()
+ {
+ var items = [
+ ['Lorem ipsum...', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.']
+ ];
-// 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());
+ this.clips.template = $('<ul id="redactor-modal-list">');
-RedactorPlugins.clips = {
- init: function()
- {
- var callback = $.proxy(function()
- {
- $('#redactor_modal').find('.redactor_clip_link').each($.proxy(function(i, s)
+ for (var i = 0; i < items.length; i++)
{
- $(s).click($.proxy(function()
- {
- this.insertClip($(s).next().html());
- return false;
+ var li = $('<li>');
+ var a = $('<a href="#" class="redactor-clip-link">').text(items[i][0]);
+ var div = $('<div class="redactor-clip">').hide().html(items[i][1]);
- }, this));
- }, this));
+ li.append(a);
+ li.append(div);
+ this.clips.template.append(li);
+ }
- this.selectionSave();
- this.bufferSet();
+ this.modal.addTemplate('clips', '<section>' + this.utils.getOuterHtml(this.clips.template) + '</section>');
- }, this );
+ var button = this.button.add('clips', 'Clips');
+ this.button.addCallback(button, this.clips.show);
- this.buttonAdd('clips', 'Clips', function(e)
+ },
+ show: function()
{
- this.modalInit('Clips', '#clipsmodal', 500, callback);
- });
- },
- insertClip: function(html)
- {
- this.selectionRestore();
- this.insertHtml($.trim(html));
- this.modalClose();
- }
+ this.modal.load('clips', 'Insert Clips', 400);
+
+ this.modal.createCancelButton();
+
+ $('#redactor-modal-list').find('.redactor-clip-link').each($.proxy(this.clips.load, this));
+
+ this.selection.save();
+ this.modal.show();
+ },
+ load: function(i,s)
+ {
+ $(s).on('click', $.proxy(function(e)
+ {
+ e.preventDefault();
+ this.clips.insert($(s).next().html());
+
+ }, this));
+ },
+ insert: function(html)
+ {
+ this.selection.restore();
+ this.insert.html(html);
+ this.modal.close();
+ this.observe.load();
+ }
+ };
};