Skip to content

Instantly share code, notes, and snippets.

@samclarke
Forked from tscolari/headlines.js
Last active December 23, 2015 07:39
Show Gist options
  • Save samclarke/6602168 to your computer and use it in GitHub Desktop.
Save samclarke/6602168 to your computer and use it in GitHub Desktop.
Update [h1] and [h2] BBCodes
/**
* H1 BBCode
*/
$.sceditor.command.set('h1', {
tooltip: 'Heading 1',
state: function(parent, firstBlock) {
var $firstBlock = $(firstBlock);
// < 0 is disabled
// == 0 is enabled but not active
// > 0 is active
return ($firstBlock.is('h1') || $firstBlock.parents('h1').length) ? 1 : 0;
},
exec: function() {
// Insert will wrap the selected text in the tags
this.insert('[h1]', '[/h1]');
},
txtExec: ['[h1]', '[/h1]']
});
$.sceditorBBCodePlugin.bbcode.set('h1', {
allowsEmpty: true,
isInline: false,
tags: {
// Match all <h1> tags?
h1: null
},
format: function(element, content) {
return '[h1]' + content + '[/h1]'
},
html: function(token, attrs, content) {
return '<h1>' + content + '</h1>'
}
});
/**
* H2 BBCode
*/
$.sceditor.command.set('h2', {
tooltip: 'Heading 2',
state: function(parent, firstBlock) {
var $firstBlock = $(firstBlock);
// < 0 is disabled
// == 0 is enabled but not active
// > 0 is active
return ($firstBlock.is('h2') || $firstBlock.parents('h2').length) ? 1 : 0;
},
exec: function() {
// Insert will wrap the selected text in the tags
this.insert('[h2]', '[/h2]');
},
txtExec: ['[h2]', '[/h2]']
});
$.sceditorBBCodePlugin.bbcode.set('h2', {
allowsEmpty: true,
isInline: false,
tags: {
// Match all <h2> tags?
h2: null
},
format: function(element, content) {
return '[h2]' + content + '[/h2]'
},
html: function(token, attrs, content) {
return '<h2>' + content + '</h2>'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment