-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(texteditor sections plugin): create the responsive sections plugin
- Loading branch information
1 parent
281ad58
commit a55ec9d
Showing
14 changed files
with
230 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
10 changes: 10 additions & 0 deletions
10
features/texteditor/views/tinymce-plugins/sections/css/sections.css
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.mce-plugin-sections-section { | ||
display: inline-block; | ||
width: 24px; | ||
height: 24px; | ||
margin: 0; | ||
padding: 0.5rem; | ||
border: 0; | ||
background-repeat: no-repeat; | ||
background-position: center center; | ||
} |
8 changes: 8 additions & 0 deletions
8
features/texteditor/views/tinymce-plugins/sections/langs/en.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
window.tinymce.addI18n('en', { | ||
'Sections': 'Sections' | ||
}); | ||
|
||
})(); |
81 changes: 81 additions & 0 deletions
81
features/texteditor/views/tinymce-plugins/sections/plugin.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
var tinymce = window.tinymce; | ||
|
||
tinymce.PluginManager.requireLangPack('sections'); | ||
tinymce.PluginManager.add('sections', function(editor, pluginUrl) { | ||
|
||
var LAYOUTS = ['6-6', '4-4-4', '3-6-3', '3-9', '4-8', '9-3', '8-4'], | ||
|
||
_ = tinymce.util.I18n.translate, | ||
_addedCss = false, | ||
_numbers = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve']; | ||
|
||
function _insertSection(layout) { | ||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers | ||
|
||
var html = ['<div class="row" id="__mcenew">']; | ||
|
||
layout.split('-').forEach(function(number, i) { | ||
html.push('<div class="' + _numbers[parseInt(number, 10)] + ' columns' + '">column ' + (i + 1) + '</div>'); | ||
}); | ||
|
||
html.push('<div class="clear"></div>'); | ||
html.push('</div>'); | ||
|
||
editor.insertContent(html.join('')); | ||
|
||
var section = editor.dom.get('__mcenew'); | ||
editor.dom.setAttrib(section, 'id', null); | ||
|
||
while (!editor.dom.is(section.parentNode, 'body')) { | ||
editor.dom.insertAfter(section, section.parentNode); | ||
} | ||
|
||
editor.selection.select($(section).find('div')[0]); | ||
} | ||
|
||
editor.addContextToolbar( | ||
function(element) { | ||
if (!editor.getBody().contains(element) || !tinymce.dom.DomQuery(element).hasClass('row')) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}, | ||
'backcolor' | ||
); | ||
|
||
editor.addButton('sections', { | ||
type: 'menubutton', | ||
tooltip: _('Responsive sections'), | ||
icon: 'none fa fa-pause', | ||
menu: LAYOUTS.map(function(layout) { | ||
return { | ||
classes: 'plugin-sections-section', | ||
style: 'background-image: url(\'' + pluginUrl + '/resources/' + layout + '.png\')', | ||
onclick: function() { | ||
_insertSection(layout); | ||
} | ||
}; | ||
}) | ||
}); | ||
|
||
editor.on('init', function() { | ||
var linkElm; | ||
|
||
if (!_addedCss) { | ||
_addedCss = true; | ||
|
||
var linkElm = editor.dom.create('link', { | ||
rel: 'stylesheet', | ||
href: pluginUrl + '/css/sections.css' | ||
}); | ||
|
||
document.getElementsByTagName('head')[0].appendChild(linkElm); | ||
} | ||
}); | ||
}); | ||
|
||
})(); |
Binary file added
BIN
+174 Bytes
features/texteditor/views/tinymce-plugins/sections/resources/3-6-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+172 Bytes
features/texteditor/views/tinymce-plugins/sections/resources/3-9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+176 Bytes
features/texteditor/views/tinymce-plugins/sections/resources/4-4-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+176 Bytes
features/texteditor/views/tinymce-plugins/sections/resources/4-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+169 Bytes
features/texteditor/views/tinymce-plugins/sections/resources/6-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+174 Bytes
features/texteditor/views/tinymce-plugins/sections/resources/8-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+171 Bytes
features/texteditor/views/tinymce-plugins/sections/resources/9-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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