Skip to content
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

Tab indent #386

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libs/tabIndent"]
path = libs/tabIndent
url = https://github.com/Jonybang/tabIndent.js
26 changes: 26 additions & 0 deletions epiceditor/js/epiceditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@
headID.appendChild(cssNode);
}

/**
* Inserts a <script> tag specifically for JS
* @param {string} path The path to the JS file
* @param {object} context In what context you want to apply this to (document, iframe, etc)
* @param {string} id An id for you to reference later for changing properties of the <script>
* @returns {undefined}
*/
function _insertJSScript(path, context, id) {
id = id || '';
var headID = context.getElementsByTagName("head")[0]
, jsNode = context.createElement('script');

_applyAttrs(jsNode, {
type: 'text/javascript'
, id: id
, src: path
});

headID.appendChild(jsNode);
}

// Simply replaces a class (o), to a new class (n) on an element provided (e)
function _replaceClass(e, o, n) {
e.className = e.className.replace(o, n);
Expand Down Expand Up @@ -632,6 +653,10 @@

// Insert Editor Stylesheet
_insertCSSLink(self.settings.theme.editor, self.editorIframeDocument, 'theme');

// Insert Editor Javascript
_insertJSScript('libs/tabIndent/js/tabIndent.js', self.editorIframeDocument, 'tab-indent');
_insertJSScript('src/init-tab-indent.js', self.editorIframeDocument, 'init-tab-indent');

// Insert Previewer Stylesheet
_insertCSSLink(self.settings.theme.preview, self.previewerIframeDocument, 'theme');
Expand All @@ -648,6 +673,7 @@
self.previewer = self.previewerIframeDocument.getElementById('epiceditor-preview');

self.editor.contentEditable = true;
self.editor.setAttribute("id", "epiceditor-editor-body");

// Firefox's <body> gets all fucked up so, to be sure, we need to hardcode it
self.iframe.body.style.height = this.element.offsetHeight + 'px';
Expand Down
1 change: 1 addition & 0 deletions libs/tabIndent
Submodule tabIndent added at 44ee05
26 changes: 26 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@
headID.appendChild(cssNode);
}

/**
* Inserts a <script> tag specifically for JS
* @param {string} path The path to the JS file
* @param {object} context In what context you want to apply this to (document, iframe, etc)
* @param {string} id An id for you to reference later for changing properties of the <script>
* @returns {undefined}
*/
function _insertJSScript(path, context, id) {
id = id || '';
var headID = context.getElementsByTagName("head")[0]
, jsNode = context.createElement('script');

_applyAttrs(jsNode, {
type: 'text/javascript'
, id: id
, src: path
});

headID.appendChild(jsNode);
}

// Simply replaces a class (o), to a new class (n) on an element provided (e)
function _replaceClass(e, o, n) {
e.className = e.className.replace(o, n);
Expand Down Expand Up @@ -632,6 +653,10 @@

// Insert Editor Stylesheet
_insertCSSLink(self.settings.theme.editor, self.editorIframeDocument, 'theme');

// Insert Editor Javascript
_insertJSScript('libs/tabIndent/js/tabIndent.js', self.editorIframeDocument, 'tab-indent');
_insertJSScript('src/init-tab-indent.js', self.editorIframeDocument, 'init-tab-indent');

// Insert Previewer Stylesheet
_insertCSSLink(self.settings.theme.preview, self.previewerIframeDocument, 'theme');
Expand All @@ -648,6 +673,7 @@
self.previewer = self.previewerIframeDocument.getElementById('epiceditor-preview');

self.editor.contentEditable = true;
self.editor.setAttribute("id", "epiceditor-editor-body");

// Firefox's <body> gets all fucked up so, to be sure, we need to hardcode it
self.iframe.body.style.height = this.element.offsetHeight + 'px';
Expand Down
22 changes: 22 additions & 0 deletions src/init-tab-indent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
window.readyHandlers = [];
window.ready = function ready(handler) {
window.readyHandlers.push(handler);
handleState();
};

window.handleState = function handleState () {
if (['interactive', 'complete'].indexOf(document.readyState) > -1) {
while(window.readyHandlers.length > 0) {
(window.readyHandlers.shift())();
}
}
};

document.onreadystatechange = window.handleState;

ready(function () {
var el = document.getElementById('epiceditor-editor-body');
tabIndent.config.focusDelay = 200;
tabIndent.config.tab = '\u00A0 \u00A0 \u00A0 ';
tabIndent.render(el);
});