|
(function () { |
|
(function (jQuery) { |
|
return jQuery.widget("IKS.blockquotebutton", { |
|
options: { |
|
editable: null, |
|
toolbar: null, |
|
uuid: '', |
|
quotes: { |
|
blockquotebutton: true, |
|
blockquotebuttonwithclass: true, |
|
blockquotebuttoncite: true, |
|
}, |
|
buttonCssClass: null |
|
}, |
|
populateToolbar: function (toolbar) { |
|
var buttonize, buttonset, |
|
_this = this; |
|
buttonset = jQuery("<span class=\"" + this.widgetName + "\"></span>"); |
|
buttonize = function (type, label) { |
|
var buttonElement; |
|
buttonElement = jQuery('<span></span>'); |
|
buttonElement.hallobutton({ |
|
uuid: _this.options.uuid, |
|
editable: _this.options.editable, |
|
label: label, |
|
icon: 'fa fa-' + (type == 'blockquotebutton' ? 'quote-left' : type == 'blockquotebuttoncite' ? 'smile-o' : 'stack-exchange'), |
|
command: null |
|
}); |
|
|
|
buttonset.append(buttonElement); |
|
|
|
if (type === 'blockquotebutton') { |
|
buttonElement.on('click', function (event) { |
|
return _this.options.editable.execute('formatBlock', |
|
'blockquote'); |
|
}); |
|
} |
|
if (type === 'blockquotebuttonwithclass') { |
|
buttonElement.on('click', function (event) { |
|
var insertionPoint, lastSelection; |
|
|
|
lastSelection = _this.options.editable.getSelection(); |
|
insertionPoint = $(lastSelection.endContainer).parentsUntil('.richtext').last(); |
|
var elem; |
|
elem = "<blockquote class='pull-out'>" + lastSelection + "</blockquote>"; |
|
|
|
var node = lastSelection.createContextualFragment(elem); |
|
|
|
lastSelection.deleteContents(); |
|
lastSelection.insertNode(node); |
|
|
|
return _this.options.editable.element.trigger('change'); |
|
}); |
|
} |
|
if (type === 'blockquotebuttoncite') { |
|
buttonElement.on('click', function (event) { |
|
var insertionPoint, lastSelection; |
|
|
|
lastSelection = _this.options.editable.getSelection(); |
|
insertionPoint = $(lastSelection.endContainer).parentsUntil('.richtext').last(); |
|
var elem; |
|
elem = "<cite>" + lastSelection + "</cite>"; |
|
|
|
var node = lastSelection.createContextualFragment(elem); |
|
|
|
lastSelection.deleteContents(); |
|
lastSelection.insertNode(node); |
|
|
|
return _this.options.editable.element.trigger('change'); |
|
}); |
|
} |
|
}; |
|
if (this.options.quotes.blockquotebutton) { |
|
buttonize("blockquotebutton", "Block quote"); |
|
} |
|
if (this.options.quotes.blockquotebuttonwithclass) { |
|
buttonize("blockquotebuttonwithclass", "Pull out quote"); |
|
} |
|
if (this.options.quotes.blockquotebuttoncite) { |
|
buttonize("blockquotebuttoncite", "Cite"); |
|
} |
|
buttonset.hallobuttonset(); |
|
return toolbar.append(buttonset); |
|
} |
|
}); |
|
})(jQuery); |
|
}).call(this); |