From f212fd2942874a613c824baf0042064589630a0c Mon Sep 17 00:00:00 2001 From: David Walsh Date: Thu, 15 Nov 2012 15:12:30 -0600 Subject: [PATCH] fix bug 811434 - Add section headers --- media/ckeditor/plugins/mdn-sampler/plugin.js | 37 +++++++++----------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/media/ckeditor/plugins/mdn-sampler/plugin.js b/media/ckeditor/plugins/mdn-sampler/plugin.js index a19c26c2820..0a7fa21623e 100644 --- a/media/ckeditor/plugins/mdn-sampler/plugin.js +++ b/media/ckeditor/plugins/mdn-sampler/plugin.js @@ -18,34 +18,31 @@ CKEDITOR.plugins.add('mdn-sampler', { var doc = editor.document, sampleSlug = $.slugifyString(text); - // Inject heading - var heading = new CKEDITOR.dom.element('h2', doc); - heading.setText(text); - heading.setAttribute('name', sampleSlug); - editor.insertElement(heading); + // Inject main heading + makeElement('h2', text, { name: sampleSlug }); // Inject Pre[html] - var htmlPre = new CKEDITOR.dom.element('pre', doc); - htmlPre.setText(gettext('Sample HTML Content')); - htmlPre.setAttribute('class', 'brush: html'); - editor.insertElement(htmlPre); + makeElement('h3', gettext('HTML Content')); + makeElement('pre', gettext('Sample HTML Content'), { 'class': 'brush: html' }); // Inject Pre[css] - var cssPre = new CKEDITOR.dom.element('pre', doc); - cssPre.setText(gettext('Sample CSS Content')); - cssPre.setAttribute('class', 'brush: css'); - editor.insertElement(cssPre); + makeElement('h3', gettext('CSS Content')); + makeElement('pre', gettext('Sample CSS Content'), { 'class': 'brush: css' }); // Inject Pre[js] - var jsPre = new CKEDITOR.dom.element('pre', doc); - jsPre.setText(gettext('Sample JS Content')); - jsPre.setAttribute('class', 'brush: js'); - editor.insertElement(jsPre); + makeElement('h3', gettext('JavaScript Content')); + makeElement('pre', gettext('Sample JavaScript Content'), { 'class': 'brush: js' }); // Inject the IFrame? - var templateP = new CKEDITOR.dom.element('p', doc); - templateP.setText('{{ EmbedLiveSample(\'' + sampleSlug + '\') }}'); - editor.insertElement(templateP); + makeElement('p', '{{ EmbedLiveSample(\'' + sampleSlug + '\') }}'); + + + function makeElement(type, text, attrs) { + var element = new CKEDITOR.dom.element(type, doc); + if(text) element.setText(gettext(text)); + if(attrs) element.setAttributes(attrs); + editor.insertElement(element); + } } });