define([
'jquery',
'/common/diffMarked.js',
],function ($, DiffMd) {
var Slide = {
index: 0,
lastIndex: 0,
content: [],
changeHandlers: [],
};
var ifrw;
var $modal;
var $content;
var placeholder;
var options;
var separator = '
';
var separatorReg = /
/g;
var slideClass = 'cp-app-slide-frame';
var Title;
var Common;
Slide.onChange = function (f) {
if (typeof(f) === 'function') {
Slide.changeHandlers.push(f);
}
};
var getNumberOfSlides = Slide.getNumberOfSlides = function () {
return $content.find('.' + slideClass).length;
};
var change = function (oldIndex, newIndex) {
if (Slide.changeHandlers.length) {
Slide.changeHandlers.some(function (f) {
f(oldIndex, newIndex, getNumberOfSlides());
});
}
};
var updateFontSize = Slide.updateFontSize = function () {
// 20vh
// 20 * 16 / 9vw
var wbase = 20;
var vh = 20;
var $elem = $(window);
if (!Slide.shown) {
wbase = 10;
vh *= $content.height()/$(window).height();
$elem = $content;
}
if ($elem.width() > 16/9*$elem.height()) {
$content.css('font-size', vh+'vh');
// $print.css('font-size', '20vh');
return;
}
$content.css('font-size', (wbase*9/16)+'vw');
// $print.css('font-size', (20*9/16)+'vw');
};
var goTo = Slide.goTo = function (i) {
i = i || 0;
Slide.index = i;
$content.find('.cp-app-slide-container').first().css('margin-left', -(i*100)+'%');
updateFontSize();
change(Slide.lastIndex, Slide.index);
$modal.find('#cp-app-slide-modal-left > span').css({
opacity: Slide.index === 0? 0: 1
});
$modal.find('#cp-app-slide-modal-right > span').css({
opacity: Slide.index === (getNumberOfSlides() -1)? 0: 1
});
};
var draw = Slide.draw = function (i) {
if (typeof(Slide.content) !== 'string') { return; }
var c = Slide.content;
if (c === '') {
var $empty = $('', {
src: '/customize/main-favicon.png',
alt: '',
class: 'cp-app-code-preview-empty'
});
$content.html('').append($empty);
$content.addClass('cp-app-slide-isempty');
return;
//c = $('').append($empty).html();
}
$content.removeClass('cp-app-slide-isempty');
var mediatagBg = '';
if (options.background && options.background.mt) {
mediatagBg = options.background.mt;
}
var bgColor = '';
if (options.bgColor && !mediatagBg) {
bgColor = 'style="background-color:'+options.bgColor+';"';
}
var m = '' + mediatagBg + ''+DiffMd.render(c).replace(separatorReg, '' + mediatagBg + '')+'';
try { DiffMd.apply(m, $content, Common); } catch (e) { return console.error(e); }
var length = getNumberOfSlides();
$modal.find('style.cp-app-slide-style').remove();
if (options.style) {
$modal.prepend($('