Ghost/core/client/utils/codemirror-mobile.js
David Arvelo 6658675646 Implement Mobile Editor
closes #2957
- add FastClick library to Gruntfile.js
- add touch-editor to client/assets/lib/
- add mobile-specific utils to util/mobile-utils.js
- add codemirror util to set up TouchEditor only if we're really on mobile
- change gh-codemirror from having a default action to a named action. prevents Ember.TextArea firing action on change
- change gh-codemirror `cm.getDoc().getValue()` to `cm.getValue()` for portability
- change codemirror-shortcuts ES6 export/import style
- changed ghostimagepreview.js to check for Ember.touchEditor in addition to Ghost.touchEditor
2014-06-24 18:33:43 -04:00

46 lines
1.1 KiB
JavaScript

/*global CodeMirror*/
import mobileUtils from 'ghost/utils/mobile-utils';
import createTouchEditor from 'ghost/assets/lib/touch-editor';
var setupMobileCodeMirror,
TouchEditor,
init;
setupMobileCodeMirror = function setupMobileCodeMirror() {
var noop = function () {},
key;
for (key in CodeMirror) {
if (CodeMirror.hasOwnProperty(key)) {
CodeMirror[key] = noop;
}
}
CodeMirror.fromTextArea = function (el, options) {
return new TouchEditor(el, options);
};
CodeMirror.keyMap = { basic: {} };
};
init = function init() {
if (mobileUtils.hasTouchScreen()) {
$('body').addClass('touch-editor');
// make editor tabs touch-to-toggle in portrait mode
$('.floatingheader').on('touchstart', function () {
$('.entry-markdown').toggleClass('active');
$('.entry-preview').toggleClass('active');
});
Ember.touchEditor = true;
mobileUtils.initFastClick();
TouchEditor = createTouchEditor();
setupMobileCodeMirror();
}
};
export default {
createIfMobile: init
};