Skip to content

Instantly share code, notes, and snippets.

@SalahAdDin
Last active August 29, 2015 14:22
Show Gist options
  • Save SalahAdDin/347e4fab78a64eaadd5c to your computer and use it in GitHub Desktop.
Save SalahAdDin/347e4fab78a64eaadd5c to your computer and use it in GitHub Desktop.
Custom simple blockquote buttons for hallo.js
(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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment