Skip to content

Added new attribute to provide factory function for additional buttons #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/angular-markdown-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ angular
return {
restrict: 'A',
require: 'ngModel',
scope: {
additionalButtonsFactory: "&additionalButtons"
},
link: function(scope, element, attrs, ngModel) {
var options = scope.$eval(attrs.markdownEditor);

// Additional buttons were passed via attribute?
var additionalButtons = scope.additionalButtonsFactory();
additionalButtons = additionalButtons || [];

// Only initialize the $.markdown plugin once.
if (! element.hasClass('processed')) {
element.addClass('processed');
Expand All @@ -30,7 +37,13 @@ angular
dropZoneOptions: options.dropZoneOptions || {},
enableDropDataUri: options.enableDropDataUri || false,
showButtons: options.showButtons || {},
additionalButtons: options.additionalButtons || (options.addExtraButtons ? addNewButtons() : []),

// Here, instead of using only externally defined buttons or the additional ones defined by angular-markdown-editor, both are merged if required.
additionalButtons: [
additionalButtons.concat(
options.addExtraButtons ? getNewButtons() : []
)
],

//-- Events/Hooks --
// each of them are defined as callback available in the directive
Expand Down Expand Up @@ -82,8 +95,8 @@ angular
* Add new extra buttons: Strikethrough & Table
* @return mixed additionButtons
*/
function addNewButtons() {
return [[{
function getNewButtons() {
return [{
name: "groupFont",
data: [{
name: "cmdStrikethrough",
Expand Down Expand Up @@ -149,7 +162,7 @@ function addNewButtons() {
e.setSelection(cursor,cursor+chunk.length);
}
}]
}]];
}];
}

/** Evaluate a function name passed as string and run it from the scope.
Expand Down