2014-04-14 00:21:06 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'utils',
|
|
|
|
'constants',
|
2014-04-14 18:00:22 +00:00
|
|
|
'settings',
|
2014-04-14 00:21:06 +00:00
|
|
|
'eventMgr',
|
|
|
|
'crel',
|
|
|
|
'mousetrap',
|
2014-04-20 01:13:43 +00:00
|
|
|
'hammerjs',
|
|
|
|
], function($, _, utils, constants, settings, eventMgr, crel, mousetrap, hammer) {
|
2014-04-14 00:21:06 +00:00
|
|
|
var layout = {};
|
|
|
|
|
|
|
|
var resizerSize = 32;
|
|
|
|
var togglerSize = 60;
|
|
|
|
var navbarHeight = 50;
|
2014-04-14 18:00:22 +00:00
|
|
|
var editorMinSize = {
|
|
|
|
width: 250,
|
|
|
|
height: 180
|
|
|
|
};
|
|
|
|
var previewMinSize = {
|
|
|
|
width: 330,
|
|
|
|
height: 200
|
|
|
|
};
|
2014-04-14 00:21:06 +00:00
|
|
|
var menuPanelWidth = 280;
|
|
|
|
var documentPanelWidth = 320;
|
2014-04-20 01:13:43 +00:00
|
|
|
var titleMinWidth = 200;
|
2014-04-14 00:21:06 +00:00
|
|
|
var windowSize;
|
|
|
|
|
2014-04-14 23:32:10 +00:00
|
|
|
var wrapperL1, wrapperL2, wrapperL3;
|
2014-04-20 01:13:43 +00:00
|
|
|
var navbar, menuPanel, documentPanel, editor, previewPanel, previewContainer, navbarToggler, previewToggler, previewResizer, previewButtons;
|
2014-04-16 18:13:17 +00:00
|
|
|
|
2014-04-14 23:32:10 +00:00
|
|
|
var animate = false;
|
2014-04-16 18:13:17 +00:00
|
|
|
function startAnimation() {
|
|
|
|
animate = true;
|
|
|
|
wrapperL1.$elt.addClass('layout-animate');
|
|
|
|
}
|
|
|
|
function endAnimation() {
|
|
|
|
animate = false;
|
|
|
|
wrapperL1.$elt.removeClass('layout-animate');
|
|
|
|
}
|
2014-04-14 23:32:10 +00:00
|
|
|
|
2014-04-14 00:21:06 +00:00
|
|
|
function DomObject(selector) {
|
|
|
|
this.selector = selector;
|
|
|
|
this.elt = document.querySelector(selector);
|
|
|
|
this.$elt = $(this.elt);
|
|
|
|
}
|
|
|
|
|
|
|
|
var laterCssTimeoutId;
|
|
|
|
var laterCssQueue = [];
|
|
|
|
DomObject.prototype.applyCss = function() {
|
|
|
|
|
|
|
|
// Top/left
|
|
|
|
this.top !== undefined && (this.elt.style.top = this.top + 'px');
|
|
|
|
this.left !== undefined && (this.elt.style.left = this.left + 'px');
|
|
|
|
|
|
|
|
// Translate
|
|
|
|
if(this.x !== undefined || this.y !== undefined) {
|
|
|
|
this.x = this.x || 0;
|
|
|
|
this.y = this.y || 0;
|
|
|
|
this.elt.style['-webkit-transform'] = 'translate(' + this.x + 'px, ' + this.y + 'px)';
|
|
|
|
this.elt.style['-ms-transform'] = 'translate(' + this.x + 'px, ' + this.y + 'px)';
|
|
|
|
this.elt.style.transform = 'translate(' + this.x + 'px, ' + this.y + 'px)';
|
|
|
|
}
|
|
|
|
|
2014-04-16 18:13:17 +00:00
|
|
|
// Width (deferred when animate if new width is smaller)
|
2014-04-14 00:21:06 +00:00
|
|
|
if(animate && this.width < this.oldWidth) {
|
|
|
|
laterCssQueue.push(_.bind(function() {
|
|
|
|
this.elt.style.width = this.width + 'px';
|
|
|
|
}, this));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.width !== undefined && (this.elt.style.width = this.width + 'px');
|
|
|
|
}
|
|
|
|
this.oldWidth = this.width;
|
|
|
|
|
2014-04-16 18:13:17 +00:00
|
|
|
// Height (deferred when animate if new height is smaller)
|
2014-04-14 00:21:06 +00:00
|
|
|
if(animate && this.height < this.oldHeight) {
|
|
|
|
laterCssQueue.push(_.bind(function() {
|
|
|
|
this.elt.style.height = this.height + 'px';
|
|
|
|
}, this));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.height !== undefined && (this.elt.style.height = this.height + 'px');
|
|
|
|
}
|
|
|
|
this.oldHeight = this.height;
|
|
|
|
|
|
|
|
clearTimeout(laterCssTimeoutId);
|
2014-04-16 18:13:17 +00:00
|
|
|
laterCssTimeoutId = setTimeout(function() {
|
|
|
|
laterCssQueue.forEach(function(callback) {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
endAnimation();
|
|
|
|
laterCssQueue.length !== 0 && onResize();
|
|
|
|
laterCssQueue = [];
|
|
|
|
}, 350);
|
2014-04-14 00:21:06 +00:00
|
|
|
};
|
|
|
|
|
2014-04-14 23:32:10 +00:00
|
|
|
DomObject.prototype.createToggler = function(backdrop, onToggle) {
|
2014-04-14 00:21:06 +00:00
|
|
|
var backdropElt;
|
|
|
|
this.toggle = function(show) {
|
|
|
|
if(show === this.isOpen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.isOpen = _.isBoolean(show) ? show : !this.isOpen;
|
|
|
|
if(this.isOpen) {
|
|
|
|
this.$elt.addClass('panel-open');
|
|
|
|
if(backdrop) {
|
2014-04-14 18:00:22 +00:00
|
|
|
$(backdropElt = utils.createBackdrop(wrapperL1.elt)).click(_.bind(function() {
|
2014-04-14 00:21:06 +00:00
|
|
|
this.toggle(false);
|
|
|
|
}, this));
|
|
|
|
this.$elt.addClass('bring-to-front');
|
|
|
|
}
|
2014-04-16 23:29:51 +00:00
|
|
|
laterCssQueue.push(_.bind(function() {
|
|
|
|
onToggle && onToggle(this.isOpen);
|
|
|
|
}, this));
|
2014-04-14 00:21:06 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-04-16 23:29:51 +00:00
|
|
|
onToggle && onToggle(false);
|
2014-04-14 00:21:06 +00:00
|
|
|
backdropElt && backdropElt.removeBackdrop();
|
|
|
|
backdropElt = undefined;
|
|
|
|
laterCssQueue.push(_.bind(function() {
|
|
|
|
!this.isOpen && this.$elt.find('.in').collapse('hide');
|
|
|
|
this.$elt.toggleClass('panel-open', this.isOpen).toggleClass('bring-to-front', (!!backdrop && this.isOpen));
|
|
|
|
}, this));
|
|
|
|
}
|
2014-04-16 18:13:17 +00:00
|
|
|
startAnimation();
|
2014-04-14 00:21:06 +00:00
|
|
|
resizeAll();
|
|
|
|
};
|
|
|
|
};
|
2014-04-20 01:13:43 +00:00
|
|
|
DomObject.prototype.initHammer = function(drag) {
|
|
|
|
this.hammer = hammer(this.elt, {
|
|
|
|
drag: drag ? true : false,
|
|
|
|
drag_max_touches: 0,
|
|
|
|
gesture: false,
|
|
|
|
hold: false,
|
|
|
|
release: false,
|
|
|
|
swipe: drag ? false : true,
|
|
|
|
tap: false,
|
|
|
|
touch: false,
|
|
|
|
transform: false
|
|
|
|
});
|
|
|
|
};
|
2014-04-14 00:21:06 +00:00
|
|
|
|
|
|
|
var maxWidthMap = [
|
|
|
|
{ screenWidth: 0, maxWidth: 600 },
|
|
|
|
{ screenWidth: 1000, maxWidth: 700 },
|
|
|
|
{ screenWidth: 1200, maxWidth: 800 },
|
|
|
|
{ screenWidth: 1400, maxWidth: 900 },
|
|
|
|
];
|
|
|
|
var maxWidthMapReversed = maxWidthMap.slice(0).reverse();
|
|
|
|
function getMaxWidth() {
|
|
|
|
return _.find(maxWidthMapReversed, function(value) {
|
|
|
|
return windowSize.width > value.screenWidth;
|
|
|
|
}).maxWidth;
|
|
|
|
}
|
|
|
|
|
2014-04-14 18:00:22 +00:00
|
|
|
var editorContentElt;
|
2014-04-14 23:32:10 +00:00
|
|
|
var previewContentElt;
|
2014-04-14 18:00:22 +00:00
|
|
|
var editorMarginElt;
|
2014-04-17 23:41:35 +00:00
|
|
|
var navbarInnerElt;
|
|
|
|
var navbarDropdownElt;
|
|
|
|
var $navbarDropdownBtnElt;
|
2014-04-19 01:09:25 +00:00
|
|
|
var navbarTitleContainerElt;
|
|
|
|
var $navbarTitleElt;
|
2014-04-17 23:41:35 +00:00
|
|
|
var navbarBtnGroups = [];
|
|
|
|
var navbarBtnGroupsWidth = [80, 80, 160, 160, 80, 40].map(function(width) {
|
|
|
|
return width + 18; // Add margin
|
|
|
|
});
|
|
|
|
var navbarMarginWidth = 18 * 2 + 25 + 25;
|
|
|
|
var buttonsDropdownWidth = 40;
|
2014-04-19 01:09:25 +00:00
|
|
|
var workingIndicatorWidth = 18 + 70;
|
2014-04-14 00:21:06 +00:00
|
|
|
function onResize() {
|
2014-04-20 01:13:43 +00:00
|
|
|
var paddingBottom = wrapperL3.height - 60;
|
2014-04-14 23:32:10 +00:00
|
|
|
|
|
|
|
var editorPadding = (editor.elt.offsetWidth - getMaxWidth()) / 2;
|
|
|
|
if(editorPadding < constants.EDITOR_DEFAULT_PADDING) {
|
|
|
|
editorPadding = constants.EDITOR_DEFAULT_PADDING;
|
|
|
|
}
|
|
|
|
editorContentElt.style.paddingLeft = editorPadding + 'px';
|
|
|
|
editorContentElt.style.paddingRight = editorPadding + 'px';
|
2014-04-20 01:13:43 +00:00
|
|
|
editorContentElt.style.paddingBottom = paddingBottom + 'px';
|
2014-04-14 23:32:10 +00:00
|
|
|
editorMarginElt.style.width = editorPadding + 'px';
|
|
|
|
|
|
|
|
var previewPadding = (previewContainer.elt.offsetWidth - getMaxWidth()) / 2;
|
|
|
|
if(previewPadding < constants.EDITOR_DEFAULT_PADDING) {
|
|
|
|
previewPadding = constants.EDITOR_DEFAULT_PADDING;
|
2014-04-14 00:21:06 +00:00
|
|
|
}
|
2014-04-14 23:32:10 +00:00
|
|
|
previewContentElt.style.paddingLeft = previewPadding + 'px';
|
|
|
|
previewContentElt.style.paddingRight = previewPadding + 'px';
|
2014-04-20 01:13:43 +00:00
|
|
|
previewContentElt.style.paddingBottom = paddingBottom + 'px';
|
2014-04-14 23:32:10 +00:00
|
|
|
|
2014-04-17 23:41:35 +00:00
|
|
|
if(!window.viewerMode) {
|
2014-04-19 01:09:25 +00:00
|
|
|
var maxWidth = navbarMarginWidth + workingIndicatorWidth + titleMinWidth + buttonsDropdownWidth;
|
|
|
|
var titleWidth = windowSize.width - maxWidth + titleMinWidth;
|
2014-04-17 23:41:35 +00:00
|
|
|
navbarBtnGroups.forEach(function(group, index) {
|
|
|
|
maxWidth += group.width;
|
|
|
|
index === navbarBtnGroups.length - 1 && (maxWidth -= buttonsDropdownWidth);
|
|
|
|
if(windowSize.width < maxWidth) {
|
|
|
|
navbarDropdownElt.appendChild(group.elt);
|
|
|
|
}
|
|
|
|
else {
|
2014-04-19 01:09:25 +00:00
|
|
|
navbarInnerElt.insertBefore(group.elt, navbarTitleContainerElt);
|
|
|
|
titleWidth = windowSize.width - maxWidth + titleMinWidth;
|
2014-04-17 23:41:35 +00:00
|
|
|
}
|
|
|
|
});
|
2014-04-19 01:09:25 +00:00
|
|
|
$navbarTitleElt.css({
|
|
|
|
maxWidth: titleWidth
|
|
|
|
});
|
2014-04-17 23:41:35 +00:00
|
|
|
$navbarDropdownBtnElt.toggleClass('hide', navbarDropdownElt.children.length === 0);
|
|
|
|
}
|
2014-04-14 00:21:06 +00:00
|
|
|
|
|
|
|
eventMgr.onLayoutResize();
|
|
|
|
}
|
|
|
|
|
2014-04-14 18:00:22 +00:00
|
|
|
var isVertical = settings.layoutOrientation == "vertical";
|
2014-04-14 00:21:06 +00:00
|
|
|
function resizeAll() {
|
|
|
|
windowSize = {
|
|
|
|
width: window.innerWidth,
|
|
|
|
height: window.innerHeight
|
|
|
|
};
|
|
|
|
|
2014-04-14 18:00:22 +00:00
|
|
|
// Layout wrapper level 1
|
|
|
|
wrapperL1.y = navbar.isOpen ? 0 : -navbarHeight;
|
|
|
|
wrapperL1.x = menuPanel.isOpen ? 0 : documentPanel.isOpen ? -(menuPanelWidth + documentPanelWidth) : -menuPanelWidth;
|
|
|
|
wrapperL1.width = windowSize.width + menuPanelWidth + documentPanelWidth;
|
|
|
|
wrapperL1.height = windowSize.height - wrapperL1.y;
|
|
|
|
|
|
|
|
// Layout wrapper level 2
|
|
|
|
wrapperL2.left = menuPanelWidth;
|
|
|
|
wrapperL2.width = windowSize.width;
|
|
|
|
wrapperL2.height = wrapperL1.height;
|
|
|
|
|
|
|
|
// Layout wrapper level 3
|
|
|
|
wrapperL3.top = navbarHeight;
|
|
|
|
wrapperL3.width = windowSize.width;
|
|
|
|
wrapperL3.height = wrapperL1.height - navbarHeight;
|
|
|
|
|
2014-04-16 23:29:51 +00:00
|
|
|
if(navbar.isOpen && wrapperL3.height < editorMinSize.height + resizerSize) {
|
|
|
|
navbar.isOpen = false;
|
|
|
|
return resizeAll();
|
|
|
|
}
|
|
|
|
|
2014-04-14 18:00:22 +00:00
|
|
|
if(isVertical) {
|
|
|
|
if(!previewPanel.isOpen) {
|
|
|
|
previewPanel.y = wrapperL3.height - resizerSize;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(previewPanel.halfSize) {
|
|
|
|
previewPanel.height = (wrapperL3.height + resizerSize) / 2;
|
|
|
|
}
|
|
|
|
if(previewPanel.height < previewMinSize.height) {
|
|
|
|
previewPanel.height = previewMinSize.height;
|
|
|
|
}
|
|
|
|
previewPanel.y = wrapperL3.height - previewPanel.height;
|
|
|
|
if(previewPanel.y < editorMinSize.height) {
|
|
|
|
var previewPanelHeight = wrapperL3.height - editorMinSize.height;
|
|
|
|
if(previewPanelHeight < previewMinSize.height) {
|
|
|
|
previewPanel.isOpen = false;
|
2014-04-14 23:32:10 +00:00
|
|
|
return resizeAll();
|
2014-04-14 18:00:22 +00:00
|
|
|
}
|
2014-04-14 23:32:10 +00:00
|
|
|
previewPanel.height = previewPanelHeight;
|
|
|
|
previewPanel.y = wrapperL3.height - previewPanel.height;
|
2014-04-14 18:00:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
previewPanel.width = wrapperL3.width;
|
|
|
|
editor.height = previewPanel.y;
|
|
|
|
editor.width = wrapperL3.width;
|
|
|
|
previewContainer.top = resizerSize;
|
|
|
|
previewContainer.height = previewPanel.height - resizerSize;
|
|
|
|
previewContainer.width = previewPanel.width;
|
|
|
|
navbarToggler.width = togglerSize;
|
|
|
|
previewToggler.width = togglerSize;
|
|
|
|
previewToggler.x = (previewPanel.width - togglerSize) / 2;
|
|
|
|
previewResizer.width = previewContainer.width;
|
2014-04-14 00:21:06 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-04-14 18:00:22 +00:00
|
|
|
if(!previewPanel.isOpen) {
|
|
|
|
previewPanel.x = wrapperL3.width - resizerSize;
|
2014-04-14 00:21:06 +00:00
|
|
|
}
|
2014-04-14 18:00:22 +00:00
|
|
|
else {
|
|
|
|
if(previewPanel.halfSize) {
|
|
|
|
previewPanel.width = (wrapperL3.width + resizerSize) / 2;
|
|
|
|
}
|
|
|
|
if(previewPanel.width < previewMinSize.width) {
|
|
|
|
previewPanel.width = previewMinSize.width;
|
|
|
|
}
|
|
|
|
previewPanel.x = wrapperL3.width - previewPanel.width;
|
|
|
|
if(previewPanel.x < editorMinSize.width) {
|
|
|
|
var previewPanelWidth = wrapperL3.width - editorMinSize.width;
|
|
|
|
if(previewPanelWidth < previewMinSize.width) {
|
|
|
|
previewPanel.isOpen = false;
|
2014-04-14 23:32:10 +00:00
|
|
|
return resizeAll();
|
2014-04-14 18:00:22 +00:00
|
|
|
}
|
2014-04-14 23:32:10 +00:00
|
|
|
previewPanel.width = previewPanelWidth;
|
|
|
|
previewPanel.x = wrapperL3.width - previewPanel.width;
|
2014-04-14 00:21:06 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-14 18:00:22 +00:00
|
|
|
previewPanel.height = wrapperL3.height;
|
|
|
|
editor.width = previewPanel.x;
|
|
|
|
editor.height = wrapperL3.height;
|
|
|
|
previewContainer.left = resizerSize;
|
|
|
|
previewContainer.width = previewPanel.width - resizerSize;
|
|
|
|
previewContainer.height = previewPanel.height;
|
|
|
|
navbarToggler.height = togglerSize;
|
|
|
|
previewToggler.height = togglerSize;
|
|
|
|
previewToggler.y = (previewPanel.height - togglerSize) / 2;
|
|
|
|
previewResizer.height = previewContainer.height;
|
2014-04-14 00:21:06 +00:00
|
|
|
}
|
|
|
|
|
2014-04-14 18:00:22 +00:00
|
|
|
navbarToggler.$elt.toggleClass('open', navbar.isOpen);
|
|
|
|
previewToggler.$elt.toggleClass('open', previewPanel.isOpen);
|
|
|
|
previewResizer.$elt.toggleClass('open', previewPanel.isOpen);
|
2014-04-14 00:21:06 +00:00
|
|
|
|
2014-04-14 18:00:22 +00:00
|
|
|
wrapperL1.applyCss();
|
|
|
|
wrapperL2.applyCss();
|
|
|
|
wrapperL3.applyCss();
|
2014-04-14 00:21:06 +00:00
|
|
|
editor.applyCss();
|
2014-04-14 18:00:22 +00:00
|
|
|
previewPanel.applyCss();
|
2014-04-14 00:21:06 +00:00
|
|
|
previewContainer.applyCss();
|
2014-04-14 18:00:22 +00:00
|
|
|
previewToggler.applyCss();
|
|
|
|
previewResizer.applyCss();
|
2014-04-14 00:21:06 +00:00
|
|
|
navbarToggler.applyCss();
|
|
|
|
|
|
|
|
onResize();
|
|
|
|
}
|
|
|
|
layout.resizeAll = resizeAll;
|
|
|
|
|
|
|
|
layout.init = function() {
|
2014-04-14 18:00:22 +00:00
|
|
|
wrapperL1 = new DomObject('.layout-wrapper-l1');
|
|
|
|
wrapperL2 = new DomObject('.layout-wrapper-l2');
|
|
|
|
wrapperL3 = new DomObject('.layout-wrapper-l3');
|
2014-04-14 00:21:06 +00:00
|
|
|
navbar = new DomObject('.navbar');
|
|
|
|
menuPanel = new DomObject('.menu-panel');
|
|
|
|
documentPanel = new DomObject('.document-panel');
|
|
|
|
editor = new DomObject('#wmd-input');
|
|
|
|
previewPanel = new DomObject('.preview-panel');
|
|
|
|
previewContainer = new DomObject('.preview-container');
|
|
|
|
navbarToggler = new DomObject('.layout-toggler-navbar');
|
|
|
|
previewToggler = new DomObject('.layout-toggler-preview');
|
|
|
|
previewResizer = new DomObject('.layout-resizer-preview');
|
2014-04-20 01:13:43 +00:00
|
|
|
previewButtons = new DomObject('.extension-preview-buttons');
|
2014-04-14 00:21:06 +00:00
|
|
|
|
|
|
|
editorContentElt = editor.elt.querySelector('.editor-content');
|
2014-04-14 23:32:10 +00:00
|
|
|
previewContentElt = document.getElementById('preview-contents');
|
2014-04-14 00:21:06 +00:00
|
|
|
editorMarginElt = editor.elt.querySelector('.editor-margin');
|
2014-04-17 23:41:35 +00:00
|
|
|
navbarInnerElt = navbar.elt.querySelector('.navbar-inner');
|
|
|
|
navbarDropdownElt = navbar.elt.querySelector('.buttons-dropdown .dropdown-menu');
|
|
|
|
$navbarDropdownBtnElt = navbar.$elt.find('.buttons-dropdown');
|
2014-04-19 01:09:25 +00:00
|
|
|
navbarTitleContainerElt = navbar.elt.querySelector('.title-container');
|
|
|
|
$navbarTitleElt = navbar.$elt.find('.file-title-navbar, .input-file-title');
|
2014-04-17 23:41:35 +00:00
|
|
|
|
|
|
|
_.each(navbar.elt.querySelectorAll('.right-buttons'), function(btnGroupElt) {
|
|
|
|
navbarBtnGroups.push({
|
|
|
|
elt: btnGroupElt,
|
|
|
|
width: navbarBtnGroupsWidth.shift()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
_.each(navbar.elt.querySelectorAll('.left-buttons'), function(btnGroupElt) {
|
|
|
|
navbarBtnGroups.push({
|
|
|
|
elt: btnGroupElt,
|
|
|
|
width: navbarBtnGroupsWidth.shift()
|
|
|
|
});
|
|
|
|
});
|
2014-04-14 00:21:06 +00:00
|
|
|
|
2014-04-14 18:00:22 +00:00
|
|
|
wrapperL1.$elt.toggleClass('layout-vertical', isVertical);
|
|
|
|
|
2014-04-14 00:21:06 +00:00
|
|
|
navbar.isOpen = true;
|
|
|
|
navbar.createToggler();
|
|
|
|
navbarToggler.$elt.click(_.bind(navbar.toggle, navbar));
|
|
|
|
|
|
|
|
previewPanel.isOpen = true;
|
2014-04-14 23:32:10 +00:00
|
|
|
previewPanel.createToggler(false, function(isOpen) {
|
2014-04-20 01:13:43 +00:00
|
|
|
previewButtons.$elt.toggleClass('hide', !isOpen);
|
2014-04-16 23:29:51 +00:00
|
|
|
eventMgr.onPreviewToggle(isOpen);
|
2014-04-14 23:32:10 +00:00
|
|
|
});
|
2014-04-14 00:21:06 +00:00
|
|
|
previewPanel.halfSize = true;
|
|
|
|
previewToggler.$elt.click(_.bind(previewPanel.toggle, previewPanel));
|
|
|
|
|
|
|
|
menuPanel.isOpen = false;
|
|
|
|
menuPanel.createToggler(true);
|
|
|
|
menuPanel.$elt.find('.toggle-button').click(_.bind(menuPanel.toggle, menuPanel));
|
|
|
|
|
|
|
|
documentPanel.isOpen = false;
|
|
|
|
documentPanel.createToggler(true);
|
|
|
|
documentPanel.$elt.find('.toggle-button').click(_.bind(documentPanel.toggle, documentPanel));
|
|
|
|
|
2014-04-20 01:13:43 +00:00
|
|
|
// Gesture events
|
|
|
|
previewResizer.initHammer(true);
|
|
|
|
/*
|
|
|
|
navbar.initHammer();
|
|
|
|
menuPanel.initHammer();
|
|
|
|
documentPanel.initHammer();
|
|
|
|
previewButtons.initHammer();
|
|
|
|
|
|
|
|
navbar.hammer.on('swiperight', _.bind(menuPanel.toggle, menuPanel, true));
|
|
|
|
navbar.hammer.on('swipeleft', _.bind(documentPanel.toggle, documentPanel, true));
|
|
|
|
navbar.hammer.on('swipeup', _.bind(navbar.toggle, navbar, false));
|
|
|
|
|
|
|
|
menuPanel.hammer.on('swiperight', _.bind(menuPanel.toggle, menuPanel, true));
|
|
|
|
menuPanel.hammer.on('swipeleft', _.bind(menuPanel.toggle, menuPanel, false));
|
|
|
|
|
|
|
|
documentPanel.hammer.on('swipeleft', _.bind(documentPanel.toggle, documentPanel, true));
|
|
|
|
documentPanel.hammer.on('swiperight', _.bind(documentPanel.toggle, documentPanel, false));
|
|
|
|
*/
|
|
|
|
|
|
|
|
var initialWidth, initialHeight;
|
|
|
|
previewResizer.hammer.on('dragstart', function() {
|
|
|
|
initialWidth = previewPanel.width;
|
|
|
|
initialHeight = previewPanel.height;
|
|
|
|
}).on('drag', function(evt) {
|
|
|
|
if(isVertical) {
|
|
|
|
previewPanel.height = initialHeight - evt.gesture.deltaY;
|
2014-04-14 00:21:06 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-04-20 01:13:43 +00:00
|
|
|
previewPanel.width = initialWidth - evt.gesture.deltaX;
|
2014-04-14 00:21:06 +00:00
|
|
|
}
|
2014-04-20 01:13:43 +00:00
|
|
|
evt.gesture.preventDefault();
|
|
|
|
previewPanel.halfSize = false;
|
|
|
|
resizeAll();
|
2014-04-14 00:21:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var isModalShown = false;
|
|
|
|
$('.modal').on('show.bs.modal', function() {
|
|
|
|
// Close panel if open
|
|
|
|
menuPanel.toggle(false);
|
|
|
|
documentPanel.toggle(false);
|
|
|
|
isModalShown = true;
|
|
|
|
}).on('hidden.bs.modal', function() {
|
|
|
|
isModalShown = false;
|
|
|
|
});
|
|
|
|
|
2014-04-20 01:13:43 +00:00
|
|
|
// Hide panels when clicking on a non collapse element
|
|
|
|
menuPanel.$elt.on('click', 'a[data-toggle!=collapse]', _.bind(menuPanel.toggle, menuPanel, false));
|
|
|
|
documentPanel.$elt.on('click', 'a[data-toggle!=collapse]', _.bind(documentPanel.toggle, documentPanel, false));
|
|
|
|
|
|
|
|
// In menu panel, close all open sub-menus when one submenu opens
|
|
|
|
menuPanel.$elt.on('show.bs.collapse', function() {
|
|
|
|
menuPanel.$elt.find('.in').collapse('hide');
|
|
|
|
});
|
|
|
|
|
2014-04-14 00:21:06 +00:00
|
|
|
// Configure Mousetrap
|
2014-04-16 23:29:51 +00:00
|
|
|
mousetrap.stopCallback = function() {
|
|
|
|
return menuPanel.isOpen || documentPanel.isOpen || isModalShown;
|
2014-04-14 00:21:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$(window).resize(resizeAll);
|
|
|
|
|
|
|
|
var styleContent = '';
|
|
|
|
|
|
|
|
// Apply font
|
|
|
|
function applyFont(size, screenWidth) {
|
|
|
|
screenWidth = screenWidth || 0;
|
|
|
|
//var codeFontSize = settings.editorFontSize;
|
|
|
|
//var codeLineHeight = Math.round(codeFontSize * 20 / 12);
|
|
|
|
var previewFontSize = size; // * 13 / 12;
|
|
|
|
styleContent += [
|
|
|
|
'@media (min-width: ' + screenWidth + 'px) {',
|
|
|
|
'#wmd-input {',
|
|
|
|
' font-size: ' + size + 'px;',
|
|
|
|
//' font-family: ' + settings.editorFontFamily + ';',
|
|
|
|
'}',
|
|
|
|
'#preview-contents {',
|
|
|
|
' font-size: ' + previewFontSize + 'px;',
|
|
|
|
'}',
|
|
|
|
'}',
|
|
|
|
].join('\n');
|
|
|
|
}
|
|
|
|
applyFont(16);
|
|
|
|
applyFont(17, 600);
|
|
|
|
applyFont(18, 1200);
|
|
|
|
|
|
|
|
// Apply dynamic stylesheet
|
|
|
|
var style = crel('style', {
|
|
|
|
type : 'text/css'
|
|
|
|
});
|
|
|
|
style.innerHTML = styleContent;
|
|
|
|
document.head.appendChild(style);
|
|
|
|
|
|
|
|
resizeAll();
|
|
|
|
};
|
|
|
|
|
2014-04-20 01:13:43 +00:00
|
|
|
eventMgr.addListener('onReady', function() {
|
|
|
|
var previewButtonsOffset = previewButtons.elt.offsetWidth + 5;
|
|
|
|
function openPreviewButtons() {
|
|
|
|
clearTimeout(closeTimeoutId);
|
|
|
|
previewButtons.x = 0;
|
|
|
|
previewButtons.applyCss();
|
|
|
|
}
|
|
|
|
var closeTimeoutId;
|
|
|
|
var dropdownOpen = false;
|
|
|
|
function closePreviewButtons() {
|
|
|
|
clearTimeout(closeTimeoutId);
|
|
|
|
closeTimeoutId = setTimeout(function() {
|
|
|
|
if(!dropdownOpen) {
|
|
|
|
previewButtons.x = previewButtonsOffset;
|
|
|
|
previewButtons.applyCss();
|
|
|
|
}
|
|
|
|
}, 3000);
|
|
|
|
}
|
|
|
|
closePreviewButtons();
|
|
|
|
previewButtons.$elt.hover(openPreviewButtons, closePreviewButtons).on('show.bs.dropdown', function() {
|
|
|
|
dropdownOpen = true;
|
|
|
|
}).on('hidden.bs.dropdown', function() {
|
|
|
|
dropdownOpen = false;
|
|
|
|
closePreviewButtons();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-04-16 23:29:51 +00:00
|
|
|
eventMgr.onLayoutCreated(layout);
|
2014-04-14 00:21:06 +00:00
|
|
|
return layout;
|
|
|
|
});
|