Last active
August 29, 2015 14:06
-
-
Save Schepp/af47847104cfc6cb7c78 to your computer and use it in GitHub Desktop.
How to add stylesets to CKEditor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
var selectorMain = '.richtext,.ckeditor', | |
eventNamespace = 'richtext', | |
cssRootfolder = './../../css/', // Will probably change in production | |
// Andi, das nachfolgende ist neu: | |
stylesets = { | |
standard: [ | |
{ | |
name: 'Link intern', | |
element: 'a', | |
attributes: { | |
'class': 'internal' | |
} | |
}, | |
{ | |
name: 'Link extern', | |
element: 'a', | |
attributes: { | |
'class': 'external' | |
} | |
} | |
] | |
}, | |
// ------- | |
configs = { | |
standard: { | |
toolbar: [{ | |
name: 'basicstyles', | |
groups: [ 'basicstyles', 'cleanup' ], | |
items: [ | |
'Bold', | |
'Italic', | |
'Underline', | |
'Strike', | |
'RemoveFormat', | |
'Styles' // NEU!!! | |
] | |
},{ | |
name: 'links', | |
items: [ 'Link', 'Unlink' ] | |
}], | |
removeButtons: 'Underline,Subscript,Superscript', | |
format_tags: 'p;h1;h2;h3;pre', | |
// Andi, nachfolgende Zeile ist neu: | |
stylesSet: 'standard', | |
removeDialogTabs: 'image:advanced;link:advanced', | |
skin: 'mascara,' + cssRootfolder + 'richtext/', | |
} | |
}, | |
richtextify = function($elem) { | |
if (!window.CKEDITOR) { | |
console.error('CKEditor not loaded. Aborting'); | |
return; | |
} | |
// Andi, das nachfolgende ist neu: | |
$.each(stylesets, function (key, value) { | |
CKEDITOR.stylesSet.add(key, value); | |
}); | |
// ------- | |
var elem = $elem.get(0), | |
config = configs.standard, | |
configName = $elem.data('richtext-config'); | |
if (configName && configs[configName]) { | |
config = configs[configName]; | |
} | |
CKEDITOR.replace(elem, config); | |
}, | |
init = function() { | |
$(selectorMain).each(function() { | |
richtextify($(this)); | |
}); | |
$(document) | |
.on(eventNamespace + ':created', selectorMain, function(e) { | |
richtextify($(this)); | |
}); | |
mascara.autoinitialize(selectorMain, eventNamespace); | |
}; | |
$(document).ready(function() { | |
init(); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment