define([ 'jquery', 'json.sortify', '/bower_components/nthen/index.js', '/common/sframe-common.js', '/slide/slide.js', '/common/sframe-app-framework.js', '/common/sframe-common-codemirror.js', '/common/common-util.js', '/common/common-hash.js', '/common/common-interface.js', '/common/hyperscript.js', '/customize/messages.js', 'cm/lib/codemirror', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/slide/app-slide.less', 'css!cm/lib/codemirror.css', 'css!cm/addon/dialog/dialog.css', 'css!cm/addon/fold/foldgutter.css', 'cm/mode/markdown/markdown', 'cm/addon/mode/loadmode', 'cm/mode/meta', 'cm/addon/mode/overlay', 'cm/addon/mode/multiplex', 'cm/addon/mode/simple', 'cm/addon/edit/closebrackets', 'cm/addon/edit/matchbrackets', 'cm/addon/edit/trailingspace', 'cm/addon/selection/active-line', 'cm/addon/search/search', 'cm/addon/search/match-highlighter', 'cm/addon/search/searchcursor', 'cm/addon/dialog/dialog', 'cm/addon/fold/foldcode', 'cm/addon/fold/foldgutter', 'cm/addon/fold/brace-fold', 'cm/addon/fold/xml-fold', 'cm/addon/fold/markdown-fold', 'cm/addon/fold/comment-fold', 'cm/addon/display/placeholder', ], function ( $, JSONSortify, nThen, SFCommon, Slide, Framework, SFCodeMirror, Util, Hash, UI, h, Messages, CMeditor) { window.CodeMirror = CMeditor; var SLIDE_BACKCOLOR_ID = "cp-app-slide-toolbar-backcolor"; var SLIDE_COLOR_ID = "cp-app-slide-toolbar-color"; var mkLess = function (less) { return ( '#cp-app-slide-print .cp-app-slide-frame, ' + '#cp-app-slide-modal #cp-app-slide-modal-content .cp-app-slide-frame {\r\n' + less + '\r\n}' ); }; var mkSlidePreviewPane = function (framework, $contentContainer) { var $previewButton = framework._.sfCommon.createButton('preview', true); $previewButton.click(function () { var $c = $contentContainer; if ($c.hasClass('cp-app-slide-preview')) { framework._.sfCommon.setPadAttribute('previewMode', false, function (e) { if (e) { return console.log(e); } }); $previewButton.removeClass('cp-toolbar-button-active'); return void $c.removeClass('cp-app-slide-preview'); } framework._.sfCommon.setPadAttribute('previewMode', true, function (e) { if (e) { return console.log(e); } }); $c.addClass('cp-app-slide-preview'); $previewButton.addClass('cp-toolbar-button-active'); Slide.updateFontSize(); }); framework._.toolbar.$bottomM.append($previewButton); framework._.sfCommon.getPadAttribute('previewMode', function (e, data) { if (e) { return void console.error(e); } if (data !== false && $previewButton) { $previewButton.click(); } }); }; var mkThemeButton = function (framework) { Messages.toolbar_theme = "Theme"; // XXX var $theme = $(h('button.cp-toolbar-appmenu', [ h('i.cptools.cptools-palette'), h('span.cp-button-name', Messages.toolbar_theme) ])); var $content = $(h('div.cp-toolbar-drawer-content', { tabindex: 1 })).hide(); $theme.click(function () { $content.toggle(); $theme.removeClass('cp-toolbar-button-active'); if ($content.is(':visible')) { $theme.addClass('cp-toolbar-button-active'); $content.focus(); var wh = $(window).height(); var topPos = $theme[0].getBoundingClientRect().bottom; $content.css('max-height', Math.floor(wh - topPos - 1)+'px'); } }); var onBlur = function (e) { if (e.relatedTarget) { if ($(e.relatedTarget).is('.cp-toolbar-drawer-button')) { return; } if ($(e.relatedTarget).parents('.cp-toolbar-drawer-content').length) { $(e.relatedTarget).blur(onBlur); return; } } $theme.removeClass('cp-toolbar-button-active'); $content.hide(); }; $content.blur(onBlur).appendTo($theme); framework._.toolbar.$theme = $content; framework._.toolbar.$bottomL.append($theme); }; var mkPrintButton = function (framework, editor, $content, $print) { var $printButton = framework._.sfCommon.createButton('print', true); $printButton.click(function () { Slide.update(editor.getValue(), true); $print.html($content.html()); window.focus(); window.print(); framework.feedback('PRINT_SLIDES'); }); framework._.toolbar.$drawer.append($printButton); }; // Flag to check if a file from the filepicker is a mediatag for the slides or a background image var Background = { isBackground: false }; var mkSlideOptionsButton = function (framework, slideOptions) { var metadataMgr = framework._.cpNfInner.metadataMgr; var updateSlideOptions = function (newOpt) { if (JSONSortify(newOpt) !== JSONSortify(slideOptions)) { $.extend(true, slideOptions, newOpt); // TODO: manage realtime + cursor in the "options" modal ?? Slide.updateOptions(); } }; var updateLocalOptions = function (newOpt) { updateSlideOptions(newOpt); var metadata = JSON.parse(JSON.stringify(metadataMgr.getMetadata())); metadata.slideOptions = slideOptions; metadataMgr.updateMetadata(metadata); framework.localChange(); }; var common = framework._.sfCommon; var createPrintDialog = function (invalidStyle) { var slideOptionsTmp = { title: false, slide: false, date: false, background: false, transition: true, style: '', styleLess: '' }; $.extend(true, slideOptionsTmp, slideOptions); var $container = $('
', {'class': 'msg'}).appendTo($div);
$('').text(Messages.printOptions).appendTo($p);
$p.append($('
'));
// Slide number
var cbox = UI.createCheckbox('cp-app-slide-options-number', Messages.printSlideNumber,
slideOptionsTmp.slide);
$(cbox).appendTo($p).find('input').on('change', function () {
var c = this.checked;
slideOptionsTmp.slide = c;
}).css('width', 'auto');
// Date
var cboxDate = UI.createCheckbox('cp-app-slide-options-date', Messages.printDate,
slideOptionsTmp.date);
$(cboxDate).appendTo($p).find('input').on('change', function () {
var c = this.checked;
slideOptionsTmp.date = c;
}).css('width', 'auto');
// Title
var cboxTitle = UI.createCheckbox('cp-app-slide-options-title', Messages.printTitle,
slideOptionsTmp.title);
$(cboxTitle).appendTo($p).find('input').on('change', function () {
var c = this.checked;
slideOptionsTmp.title = c;
}).css('width', 'auto');
// Transition
var cboxTransition = UI.createCheckbox('cp-app-slide-options-transition', Messages.printTransition,
slideOptionsTmp.transition);
$(cboxTransition).appendTo($p).find('input').on('change', function () {
var c = this.checked;
slideOptionsTmp.transition = c;
}).css('width', 'auto');
$p.append($('
'));
// Background image
$('