Presentationeditor
This commit is contained in:
parent
e3af6125dd
commit
4fbedc3b7b
|
@ -2,7 +2,196 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Documents</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
|
||||
<!-- debug begin -->
|
||||
<link rel="stylesheet/less" type="text/css" href="resources/less/application.less" />
|
||||
<!-- debug end -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<body class="embed-body">
|
||||
<div id="loading-mask" class="loadmask">
|
||||
<div class="brendpanel">
|
||||
<div>
|
||||
<div class="brand-logo loading-logo">
|
||||
<img src="">
|
||||
</div>
|
||||
<div class="doc-title"></div>
|
||||
<div class="circle"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="placeholder">
|
||||
<div class="slide-h">
|
||||
<div class="slide-v">
|
||||
<div class="slide-container">
|
||||
<div class="line"></div>
|
||||
<div class="line empty"></div>
|
||||
<div class="line"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- debug begin -->
|
||||
<script type="text/javascript">var less=less||{};less.env='development';</script>
|
||||
<script src="../../../vendor/less/dist/less.js" type="text/javascript"></script>
|
||||
<!-- debug end -->
|
||||
|
||||
<script>
|
||||
var userAgent = navigator.userAgent.toLowerCase(),
|
||||
check = function(regex){ return regex.test(userAgent); };
|
||||
if (!check(/opera/) && (check(/msie/) || check(/trident/))) {
|
||||
var m = /msie (\d+\.\d+)/.exec(userAgent);
|
||||
if (m && parseFloat(m[1]) < 10.0) {
|
||||
document.write(
|
||||
'<div id="id-error-mask" class="errormask">',
|
||||
'<div class="error-body" align="center">',
|
||||
'<div id="id-error-mask-title" class="title">Your browser is not supported.</div>',
|
||||
'<div id="id-error-mask-text">Sorry, ONLYOFFICE Document is currently only supported in the latest versions of the Chrome, Firefox, Safari or Internet Explorer web browsers.</div>',
|
||||
'</div>',
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function getUrlParams() {
|
||||
var e,
|
||||
a = /\+/g, // Regex for replacing addition symbol with a space
|
||||
r = /([^&=]+)=?([^&]*)/g,
|
||||
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
|
||||
q = window.location.search.substring(1),
|
||||
urlParams = {};
|
||||
|
||||
while (e = r.exec(q))
|
||||
urlParams[d(e[1])] = d(e[2]);
|
||||
|
||||
return urlParams;
|
||||
}
|
||||
|
||||
function encodeUrlParam(str) {
|
||||
return str.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
}
|
||||
|
||||
var params = getUrlParams(),
|
||||
lang = (params["lang"] || 'en').split(/[\-\_]/)[0],
|
||||
logo = params["headerlogo"] ? encodeUrlParam(params["headerlogo"]) : null;
|
||||
|
||||
window.frameEditorId = params["frameEditorId"];
|
||||
window.parentOrigin = params["parentOrigin"];
|
||||
|
||||
var elem = document.querySelector('.loading-logo');
|
||||
if (elem && logo) {
|
||||
elem.style.backgroundImage= 'none';
|
||||
var img = document.querySelector('.loading-logo img');
|
||||
img && img.setAttribute('src', logo);
|
||||
img.style.opacity = 1;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div id="box-preview">
|
||||
<div id="id-preview" tabindex="-1"></div>
|
||||
</div>
|
||||
<div id="editor_sdk" class="viewer top" style="overflow: hidden;" tabindex="-1"></div>
|
||||
|
||||
<div class="overlay-controls" style="margin-left: -32px">
|
||||
<ul class="left">
|
||||
<li id="btn-left"><button class="overlay svg-icon slide-prev"></button></li>
|
||||
<li id="btn-play"><button class="overlay svg-icon play"></button></li>
|
||||
<li id="btn-right"><button class="overlay svg-icon slide-next"></button></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="toolbar" id="toolbar">
|
||||
<div class="group left">
|
||||
<div class="margin-right-large"><a id="header-logo" class="brand-logo" href="http://www.onlyoffice.com/" target="_blank"></a></div>
|
||||
</div>
|
||||
<div class="group center">
|
||||
<span id="title-doc-name"></span>
|
||||
</div>
|
||||
<div class="group right">
|
||||
<div class="item margin-right-small"><input id="page-number" class="form-control input-xs masked" type="text" value="0"><span class="text" id="pages" tabindex="-1">of 0</span></div>
|
||||
<div id="box-tools" class="dropdown">
|
||||
<button class="control-btn svg-icon more-vertical"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="error modal fade" id="id-critical-error-dialog" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 id="id-critical-error-title"></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p id="id-critical-error-message"></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="id-critical-error-close" class="btn btn-sm btn-primary" data-dismiss="modal" aria-hidden="true">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hyperlink-tooltip" data-toggle="tooltip" title="Press Ctrl and click the link" style="display:none;"></div>
|
||||
|
||||
<!--vendor-->
|
||||
<script type="text/javascript" src="../../../vendor/jquery/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="../../../vendor/jquery.browser/dist/jquery.browser.min.js"></script>
|
||||
<script type="text/javascript" src="../../../vendor/bootstrap/dist/js/bootstrap.js"></script>
|
||||
<script type="text/javascript" src="../../../vendor/sockjs/sockjs.min.js"></script>
|
||||
<script type="text/javascript" src="../../../vendor/xregexp/xregexp-all-min.js"></script>
|
||||
|
||||
<script src="../../../vendor/requirejs/require.js"></script>
|
||||
<script>
|
||||
require.config({
|
||||
baseUrl: '../../'
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="../../../../sdkjs/develop/sdkjs/slide/scripts.js"></script>
|
||||
<script>
|
||||
window.sdk_scripts.forEach(function(item){
|
||||
document.write('<script type="text/javascript" src="' + item + '"><\/script>');
|
||||
});
|
||||
</script>
|
||||
|
||||
<!--application-->
|
||||
<script type="text/javascript" src="../../unit-tests/common/locale.js"></script>
|
||||
<script type="text/javascript" src="../../unit-tests/common/Gateway.js"></script>
|
||||
<script type="text/javascript" src="../../unit-tests/common/main/lib/util/LocalStorage.js"></script>
|
||||
<script type="text/javascript" src="../../unit-tests/common/main/lib/util/utils.js"></script>
|
||||
<script type="text/javascript" src="../../unit-tests/common/main/lib/view/LoadMask.js"></script>
|
||||
<script type="text/javascript" src="js/ApplicationView.js"></script>
|
||||
<script type="text/javascript" src="js/ApplicationController.js"></script>
|
||||
<script type="text/javascript" src="js/application.js"></script>
|
||||
<script type="text/javascript">
|
||||
var isBrowserSupported = function() {
|
||||
return ($.browser.msie && parseFloat($.browser.version) > 9) ||
|
||||
($.browser.chrome && parseFloat($.browser.version) > 7) ||
|
||||
($.browser.safari && parseFloat($.browser.version) > 4) ||
|
||||
($.browser.opera && parseFloat($.browser.version) > 10.4) ||
|
||||
($.browser.mozilla && parseFloat($.browser.version) > 3.9);
|
||||
};
|
||||
|
||||
if (!isBrowserSupported()){
|
||||
document.write(
|
||||
'<div id="id-error-mask" class="errormask">',
|
||||
'<div class="error-body" align="center">',
|
||||
'<div id="id-error-mask-title" class="title">Your browser is not supported.</div>',
|
||||
'<div id="id-error-mask-text">Sorry, ONLYOFFICE Document is currently only supported in the latest versions of the Chrome, Firefox, Safari or Internet Explorer web browsers.</div>',
|
||||
'</div>',
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
729
test/presentationeditor/main/js/ApplicationController.js
Normal file
729
test/presentationeditor/main/js/ApplicationController.js
Normal file
|
@ -0,0 +1,729 @@
|
|||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
PE.ApplicationController = new(function(){
|
||||
var me,
|
||||
api,
|
||||
config = {},
|
||||
docConfig = {},
|
||||
embedConfig = {},
|
||||
permissions = {},
|
||||
maxPages = 0,
|
||||
created = false,
|
||||
currentPage = 0,
|
||||
ttOffset = [0, -10],
|
||||
labelDocName;
|
||||
|
||||
var LoadingDocument = -256;
|
||||
|
||||
// Initialize analytics
|
||||
// -------------------------
|
||||
|
||||
// Common.Analytics.initialize('UA-12442749-13', 'Embedded Presentation Editor');
|
||||
|
||||
|
||||
// Check browser
|
||||
// -------------------------
|
||||
|
||||
if (typeof isBrowserSupported !== 'undefined' && !isBrowserSupported()){
|
||||
Common.Gateway.reportError(undefined, this.unsupportedBrowserErrorText);
|
||||
return;
|
||||
}
|
||||
|
||||
common.localStorage.setId('text');
|
||||
common.localStorage.setKeysFilter('pe-,asc.presentation');
|
||||
common.localStorage.sync();
|
||||
|
||||
// Handlers
|
||||
// -------------------------
|
||||
|
||||
function loadConfig(data) {
|
||||
config = $.extend(config, data.config);
|
||||
embedConfig = $.extend(embedConfig, data.config.embedded);
|
||||
|
||||
//common.controller.modals.init(embedConfig);
|
||||
|
||||
// Docked toolbar
|
||||
/*if (embedConfig.toolbarDocked === 'bottom') {
|
||||
$('#toolbar').addClass('bottom');
|
||||
$('#editor_sdk').addClass('bottom');
|
||||
$('#box-tools').removeClass('dropdown').addClass('dropup');
|
||||
ttOffset[1] = -40;
|
||||
} else {
|
||||
$('#toolbar').addClass('top');
|
||||
$('#editor_sdk').addClass('top');
|
||||
}*/
|
||||
|
||||
config.canBackToFolder = (config.canBackToFolder!==false) && config.customization && config.customization.goback &&
|
||||
(config.customization.goback.url || config.customization.goback.requestClose && config.canRequestClose);
|
||||
}
|
||||
|
||||
function loadDocument(data) {
|
||||
docConfig = data.doc;
|
||||
|
||||
if (docConfig) {
|
||||
permissions = $.extend(permissions, docConfig.permissions);
|
||||
|
||||
var _permissions = $.extend({}, docConfig.permissions),
|
||||
docInfo = new Asc.asc_CDocInfo(),
|
||||
_user = new Asc.asc_CUserInfo();
|
||||
|
||||
var canRenameAnonymous = !((typeof (config.customization) == 'object') && (typeof (config.customization.anonymous) == 'object') && (config.customization.anonymous.request===false)),
|
||||
guestName = (typeof (config.customization) == 'object') && (typeof (config.customization.anonymous) == 'object') &&
|
||||
(typeof (config.customization.anonymous.label) == 'string') && config.customization.anonymous.label.trim()!=='' ?
|
||||
common.utils.htmlEncode(config.customization.anonymous.label) : me.textGuest,
|
||||
value = canRenameAnonymous ? common.localStorage.getItem("guest-username") : null,
|
||||
user = common.utils.fillUserInfo(config.user, config.lang, value ? (value + ' (' + guestName + ')' ) : me.textAnonymous,
|
||||
common.localStorage.getItem("guest-id") || ('uid-' + Date.now()));
|
||||
user.anonymous && common.localStorage.setItem("guest-id", user.id);
|
||||
|
||||
_user.put_Id(user.id);
|
||||
_user.put_FullName(user.fullname);
|
||||
_user.put_IsAnonymousUser(user.anonymous);
|
||||
|
||||
docInfo.put_Id(docConfig.key);
|
||||
docInfo.put_Url(docConfig.url);
|
||||
docInfo.put_Title(docConfig.title);
|
||||
docInfo.put_Format(docConfig.fileType);
|
||||
docInfo.put_VKey(docConfig.vkey);
|
||||
docInfo.put_UserInfo(_user);
|
||||
docInfo.put_Token(docConfig.token);
|
||||
docInfo.put_Permissions(_permissions);
|
||||
docInfo.put_EncryptedInfo(config.encryptionKeys);
|
||||
|
||||
var enable = !config.customization || (config.customization.macros!==false);
|
||||
docInfo.asc_putIsEnabledMacroses(!!enable);
|
||||
enable = !config.customization || (config.customization.plugins!==false);
|
||||
docInfo.asc_putIsEnabledPlugins(!!enable);
|
||||
|
||||
if (api) {
|
||||
api.asc_registerCallback('asc_onGetEditorPermissions', onEditorPermissions);
|
||||
api.asc_registerCallback('asc_onRunAutostartMacroses', onRunAutostartMacroses);
|
||||
api.asc_setDocInfo(docInfo);
|
||||
api.asc_getEditorPermissions(config.licenseUrl, config.customerId);
|
||||
api.asc_enableKeyEvents(true);
|
||||
|
||||
//Common.Analytics.trackEvent('Load', 'Start');
|
||||
}
|
||||
|
||||
embedConfig.docTitle = docConfig.title;
|
||||
labelDocName = $('#title-doc-name');
|
||||
labelDocName.text(embedConfig.docTitle || '')
|
||||
}
|
||||
}
|
||||
|
||||
function onCountPages(count) {
|
||||
maxPages = count;
|
||||
$('#pages').text(me.textOf + " " + count);
|
||||
}
|
||||
|
||||
function onCurrentPage(number) {
|
||||
$('#page-number').val(number + 1);
|
||||
currentPage = number;
|
||||
}
|
||||
|
||||
function onLongActionBegin(type, id) {
|
||||
var text = '';
|
||||
switch (id)
|
||||
{
|
||||
case Asc.c_oAscAsyncAction['Print']:
|
||||
text = me.downloadTextText;
|
||||
break;
|
||||
case LoadingDocument:
|
||||
text = me.textLoadingDocument + ' ';
|
||||
break;
|
||||
default:
|
||||
text = me.waitText;
|
||||
break;
|
||||
}
|
||||
|
||||
if (type == Asc.c_oAscAsyncActionType['BlockInteraction']) {
|
||||
if (!me.loadMask)
|
||||
me.loadMask = new common.view.LoadMask();
|
||||
me.loadMask.setTitle(text);
|
||||
me.loadMask.show();
|
||||
}
|
||||
}
|
||||
|
||||
function onLongActionEnd(){
|
||||
me.loadMask && me.loadMask.hide();
|
||||
}
|
||||
|
||||
function onDocMouseMoveStart() {
|
||||
me.isHideBodyTip = true;
|
||||
}
|
||||
|
||||
var $ttEl, $tooltip;
|
||||
function onDocMouseMoveEnd() {
|
||||
if (me.isHideBodyTip) {
|
||||
if ( $tooltip ) {
|
||||
$tooltip.tooltip('hide');
|
||||
$tooltip = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onDocMouseMove(data) {
|
||||
if (data) {
|
||||
if (data.get_Type() == 1) { // hyperlink
|
||||
me.isHideBodyTip = false;
|
||||
|
||||
if ( !$ttEl ) {
|
||||
$ttEl = $('.hyperlink-tooltip');
|
||||
$ttEl.tooltip({'container':'body', 'trigger':'manual'});
|
||||
$ttEl.on('shown.bs.tooltip', function(e) {
|
||||
$tooltip = $ttEl.data('bs.tooltip').tip();
|
||||
|
||||
$tooltip.css({
|
||||
left: $ttEl.ttpos[0] + ttOffset[0],
|
||||
top: $ttEl.ttpos[1] + ttOffset[1]
|
||||
});
|
||||
|
||||
$tooltip.find('.tooltip-arrow').css({left: 10});
|
||||
});
|
||||
}
|
||||
|
||||
if ( !$tooltip ) {
|
||||
$ttEl.ttpos = [data.get_X(), data.get_Y()];
|
||||
$ttEl.tooltip('show');
|
||||
} else {
|
||||
$tooltip.css({
|
||||
left:data.get_X() + ttOffset[0],
|
||||
top:data.get_Y() + ttOffset[1]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onDownloadUrl(url, fileType) {
|
||||
Common.Gateway.downloadAs(url, fileType);
|
||||
}
|
||||
|
||||
function onPrint() {
|
||||
if (permissions.print!==false)
|
||||
api.asc_Print(new Asc.asc_CDownloadOptions(null, $.browser.chrome || $.browser.safari || $.browser.opera || $.browser.mozilla && $.browser.versionNumber>86));
|
||||
}
|
||||
|
||||
function onPrintUrl(url) {
|
||||
common.utils.dialogPrint(url, api);
|
||||
}
|
||||
|
||||
function hidePreloader() {
|
||||
$('#loading-mask').fadeOut('slow');
|
||||
}
|
||||
|
||||
function onDocumentContentReady() {
|
||||
api.ShowThumbnails(true);
|
||||
//api.asc_DeleteVerticalScroll();
|
||||
|
||||
/*if (!embedConfig.autostart || embedConfig.autostart == 'player') {
|
||||
api.SetDemonstrationModeOnly();
|
||||
onPlayStart();
|
||||
}*/
|
||||
hidePreloader();
|
||||
onLongActionEnd(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument);
|
||||
|
||||
var zf = (config.customization && config.customization.zoom ? parseInt(config.customization.zoom) : -1);
|
||||
(zf == -1) ? api.zoomFitToPage() : ((zf == -2) ? api.zoomFitToWidth() : api.zoom(zf>0 ? zf : 100));
|
||||
|
||||
if ( permissions.print === false)
|
||||
$('#idt-print').hide();
|
||||
|
||||
if (!embedConfig.saveUrl && permissions.print === false)
|
||||
$('#idt-download').hide();
|
||||
|
||||
if ( !embedConfig.shareUrl )
|
||||
$('#idt-share').hide();
|
||||
|
||||
if (!config.canBackToFolder)
|
||||
$('#idt-close').hide();
|
||||
|
||||
if ( !embedConfig.embedUrl )
|
||||
$('#idt-embed').hide();
|
||||
|
||||
if ( !embedConfig.fullscreenUrl )
|
||||
$('#idt-fullscreen').hide();
|
||||
|
||||
if ( !embedConfig.saveUrl && permissions.print === false && !embedConfig.shareUrl && !embedConfig.embedUrl && !embedConfig.fullscreenUrl && !config.canBackToFolder)
|
||||
$('#box-tools').addClass('hidden');
|
||||
else if (!embedConfig.embedUrl && !embedConfig.fullscreenUrl)
|
||||
$('#box-tools .divider').hide();
|
||||
|
||||
/*common.controller.modals.attach({
|
||||
share: '#idt-share',
|
||||
embed: '#idt-embed'
|
||||
});*/
|
||||
|
||||
api.asc_registerCallback('asc_onMouseMoveStart', onDocMouseMoveStart);
|
||||
api.asc_registerCallback('asc_onMouseMoveEnd', onDocMouseMoveEnd);
|
||||
api.asc_registerCallback('asc_onMouseMove', onDocMouseMove);
|
||||
|
||||
api.asc_registerCallback('asc_onDownloadUrl', onDownloadUrl);
|
||||
api.asc_registerCallback('asc_onPrint', onPrint);
|
||||
api.asc_registerCallback('asc_onPrintUrl', onPrintUrl);
|
||||
api.asc_registerCallback('asc_onHyperlinkClick', common.utils.openLink);
|
||||
api.asc_registerCallback('asc_onStartAction', onLongActionBegin);
|
||||
api.asc_registerCallback('asc_onEndAction', onLongActionEnd);
|
||||
|
||||
api.asc_registerCallback('asc_onEndDemonstration', onPlayStop);
|
||||
api.asc_registerCallback('asc_onDemonstrationSlideChanged', onPlaySlideChanged);
|
||||
|
||||
Common.Gateway.on('processmouse', onProcessMouse);
|
||||
Common.Gateway.on('downloadas', onDownloadAs);
|
||||
Common.Gateway.on('requestclose', onRequestClose);
|
||||
|
||||
PE.ApplicationView.tools.get('#idt-fullscreen')
|
||||
.on('click', function(){
|
||||
common.utils.openLink(embedConfig.fullscreenUrl);
|
||||
});
|
||||
|
||||
PE.ApplicationView.tools.get('#idt-download')
|
||||
.on('click', function(){
|
||||
if ( !!embedConfig.saveUrl ){
|
||||
common.utils.openLink(embedConfig.saveUrl);
|
||||
} else
|
||||
if (api && permissions.print!==false){
|
||||
api.asc_Print(new Asc.asc_CDownloadOptions(null, $.browser.chrome || $.browser.safari || $.browser.opera || $.browser.mozilla && $.browser.versionNumber>86));
|
||||
}
|
||||
|
||||
//Common.Analytics.trackEvent('Save');
|
||||
});
|
||||
|
||||
PE.ApplicationView.tools.get('#idt-print')
|
||||
.on('click', function(){
|
||||
api.asc_Print(new Asc.asc_CDownloadOptions(null, $.browser.chrome || $.browser.safari || $.browser.opera || $.browser.mozilla && $.browser.versionNumber>86));
|
||||
//Common.Analytics.trackEvent('Print');
|
||||
});
|
||||
|
||||
PE.ApplicationView.tools.get('#idt-close')
|
||||
.on('click', function(){
|
||||
if (config.customization && config.customization.goback) {
|
||||
if (config.customization.goback.requestClose && config.canRequestClose)
|
||||
Common.Gateway.requestClose();
|
||||
else if (config.customization.goback.url)
|
||||
window.parent.location.href = config.customization.goback.url;
|
||||
}
|
||||
});
|
||||
|
||||
var $pagenum = $('#page-number');
|
||||
$pagenum.on({
|
||||
'keyup': function(e){
|
||||
if ( e.keyCode == 13 ){
|
||||
var newPage = parseInt($('#page-number').val());
|
||||
|
||||
if ( isNaN(newPage) ) {
|
||||
$('#page-number').val(currentPage + 1);
|
||||
} else {
|
||||
if ( newPage > maxPages ) newPage = maxPages; else
|
||||
if ( newPage < 2 ) newPage = 1;
|
||||
|
||||
if ( newPage == currentPage + 1 ) {
|
||||
$('#page-number').val( newPage );
|
||||
} else
|
||||
if (isplaymode) {
|
||||
currentPage = newPage - 1;
|
||||
api.DemonstrationGoToSlide(newPage - 1);
|
||||
} else api.goToPage(newPage - 1);
|
||||
}
|
||||
|
||||
$pagenum.blur();
|
||||
}
|
||||
}
|
||||
, 'focusin' : function(e) {
|
||||
$pagenum.removeClass('masked');
|
||||
}
|
||||
, 'focusout': function(e){
|
||||
!$pagenum.hasClass('masked') && $pagenum.addClass('masked');
|
||||
}
|
||||
});
|
||||
|
||||
$('#pages').on('click', function(e) {
|
||||
$pagenum.focus();
|
||||
});
|
||||
|
||||
$('#btn-left').on('click', function(){
|
||||
if ( isplaymode ) {
|
||||
api.DemonstrationPrevSlide();
|
||||
} else
|
||||
if (currentPage > 0) {
|
||||
api.goToPage(currentPage - 1);
|
||||
}
|
||||
});
|
||||
|
||||
$('#btn-right').on('click', function(){
|
||||
if ( isplaymode ) {
|
||||
api.DemonstrationNextSlide();
|
||||
} else
|
||||
if (currentPage < maxPages - 1) {
|
||||
api.goToPage(currentPage + 1);
|
||||
}
|
||||
});
|
||||
|
||||
var documentMoveTimer;
|
||||
var ismoved = false;
|
||||
$(document).on({
|
||||
'click': function(e) {
|
||||
clearTimeout(documentMoveTimer);
|
||||
documentMoveTimer = undefined;
|
||||
},
|
||||
'mousemove': function (e) {
|
||||
$('#btn-left').fadeIn();
|
||||
$('#btn-right').fadeIn();
|
||||
|
||||
ismoved = true;
|
||||
if ( !documentMoveTimer ) {
|
||||
documentMoveTimer = setInterval(function(){
|
||||
if ( !ismoved ) {
|
||||
// $('#btn-left').fadeOut();
|
||||
// $('#btn-right').fadeOut();
|
||||
clearInterval(documentMoveTimer);
|
||||
documentMoveTimer = undefined;
|
||||
}
|
||||
|
||||
ismoved = false;
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var ismodalshown = false;
|
||||
$(document.body).on('show.bs.modal', '.modal',
|
||||
function(e) {
|
||||
ismodalshown = true;
|
||||
api.asc_enableKeyEvents(false);
|
||||
}
|
||||
).on('hidden.bs.modal', '.modal',
|
||||
function(e) {
|
||||
ismodalshown = false;
|
||||
api.asc_enableKeyEvents(true);
|
||||
}
|
||||
).on('hidden.bs.dropdown', '.dropdown',
|
||||
function(e) {
|
||||
if ( !ismodalshown )
|
||||
api.asc_enableKeyEvents(true);
|
||||
}
|
||||
).on('blur', 'input, textarea',
|
||||
function(e) {
|
||||
if ( !ismodalshown ) {
|
||||
if (!/area_id/.test(e.target.id) ) {
|
||||
api.asc_enableKeyEvents(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$('#editor_sdk').on('click', function(e) {
|
||||
if ( e.target.localName == 'canvas' ) {
|
||||
e.currentTarget.focus();
|
||||
}
|
||||
});
|
||||
|
||||
$('#btn-play').on('click', onPlayStart);
|
||||
Common.Gateway.documentReady();
|
||||
//Common.Analytics.trackEvent('Load', 'Complete');
|
||||
}
|
||||
|
||||
function onEditorPermissions(params) {
|
||||
if ( (params.asc_getLicenseType() === Asc.c_oLicenseResult.Success) && (typeof config.customization == 'object') &&
|
||||
config.customization && config.customization.logo ) {
|
||||
|
||||
var logo = $('#header-logo');
|
||||
if (config.customization.logo.imageEmbedded) {
|
||||
logo.html('<img src="'+config.customization.logo.imageEmbedded+'" style="max-width:124px; max-height:20px;"/>');
|
||||
logo.css({'background-image': 'none', width: 'auto', height: 'auto'});
|
||||
}
|
||||
|
||||
if (config.customization.logo.url) {
|
||||
logo.attr('href', config.customization.logo.url);
|
||||
}
|
||||
}
|
||||
|
||||
var $parent = labelDocName.parent();
|
||||
var _left_width = $parent.position().left,
|
||||
_right_width = $parent.next().outerWidth();
|
||||
|
||||
if ( _left_width < _right_width )
|
||||
$parent.css('padding-left', _right_width - _left_width);
|
||||
else
|
||||
$parent.css('padding-right', _left_width - _right_width);
|
||||
|
||||
onLongActionBegin(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument);
|
||||
api.asc_setViewMode(false);
|
||||
|
||||
api.asc_LoadDocument();
|
||||
api.Resize();
|
||||
}
|
||||
|
||||
function onOpenDocument(progress) {
|
||||
var proc = (progress.asc_getCurrentFont() + progress.asc_getCurrentImage())/(progress.asc_getFontsCount() + progress.asc_getImagesCount());
|
||||
me.loadMask && me.loadMask.setTitle(me.textLoadingDocument + ': ' + common.utils.fixedDigits(Math.min(Math.round(proc*100), 100), 3, " ") + '%');
|
||||
}
|
||||
|
||||
var isplaymode;
|
||||
function onPlayStart(e) {
|
||||
if ( !isplaymode ) {
|
||||
$('#box-preview').show();
|
||||
api.StartDemonstration('id-preview', currentPage);
|
||||
} else {
|
||||
isplaymode == 'play' ?
|
||||
api.DemonstrationPause() : api.DemonstrationPlay();
|
||||
}
|
||||
|
||||
isplaymode != 'play' ? ($('#btn-play button').addClass('pause'), isplaymode = 'play') :
|
||||
($('#btn-play button').removeClass('pause'), isplaymode = 'pause');
|
||||
}
|
||||
|
||||
function onPlayStop() {
|
||||
isplaymode = undefined;
|
||||
$('#page-number').val(currentPage + 1);
|
||||
$('#btn-play button').removeClass('pause');
|
||||
$('#box-preview').hide();
|
||||
}
|
||||
|
||||
function onPlaySlideChanged(number) {
|
||||
if ( number++ < maxPages)
|
||||
$('#page-number').val(number);
|
||||
}
|
||||
|
||||
function onError(id, level, errData) {
|
||||
if (id == Asc.c_oAscError.ID.LoadingScriptError) {
|
||||
$('#id-critical-error-title').text(me.criticalErrorTitle);
|
||||
$('#id-critical-error-message').text(me.scriptLoadError);
|
||||
$('#id-critical-error-close').text(me.txtClose).off().on('click', function(){
|
||||
window.location.reload();
|
||||
});
|
||||
$('#id-critical-error-dialog').css('z-index', 20002).modal('show');
|
||||
return;
|
||||
}
|
||||
|
||||
hidePreloader();
|
||||
onLongActionEnd(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument);
|
||||
|
||||
var message;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case Asc.c_oAscError.ID.Unknown:
|
||||
message = me.unknownErrorText;
|
||||
break;
|
||||
|
||||
case Asc.c_oAscError.ID.ConvertationTimeout:
|
||||
message = me.convertationTimeoutText;
|
||||
break;
|
||||
|
||||
case Asc.c_oAscError.ID.ConvertationError:
|
||||
message = me.convertationErrorText;
|
||||
break;
|
||||
|
||||
case Asc.c_oAscError.ID.DownloadError:
|
||||
message = me.downloadErrorText;
|
||||
break;
|
||||
|
||||
case Asc.c_oAscError.ID.ConvertationPassword:
|
||||
message = me.errorFilePassProtect;
|
||||
break;
|
||||
|
||||
case Asc.c_oAscError.ID.UserDrop:
|
||||
message = me.errorUserDrop;
|
||||
break;
|
||||
|
||||
case Asc.c_oAscError.ID.ConvertationOpenLimitError:
|
||||
message = me.errorFileSizeExceed;
|
||||
break;
|
||||
|
||||
case Asc.c_oAscError.ID.UpdateVersion:
|
||||
message = me.errorUpdateVersionOnDisconnect;
|
||||
break;
|
||||
|
||||
case Asc.c_oAscError.ID.AccessDeny:
|
||||
message = me.errorAccessDeny;
|
||||
break;
|
||||
|
||||
case Asc.c_oAscError.ID.ForceSaveButton:
|
||||
case Asc.c_oAscError.ID.ForceSaveTimeout:
|
||||
message = me.errorForceSave;
|
||||
break;
|
||||
|
||||
case Asc.c_oAscError.ID.LoadingFontError:
|
||||
message = me.errorLoadingFont;
|
||||
break;
|
||||
|
||||
default:
|
||||
message = me.errorDefaultMessage.replace('%1', id);
|
||||
break;
|
||||
}
|
||||
|
||||
if (level == Asc.c_oAscError.Level.Critical) {
|
||||
|
||||
// report only critical errors
|
||||
Common.Gateway.reportError(id, message);
|
||||
|
||||
$('#id-critical-error-title').text(me.criticalErrorTitle);
|
||||
$('#id-critical-error-message').html(message);
|
||||
$('#id-critical-error-close').text(me.txtClose).off().on('click', function(){
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
else {
|
||||
Common.Gateway.reportWarning(id, message);
|
||||
|
||||
$('#id-critical-error-title').text(me.notcriticalErrorTitle);
|
||||
$('#id-critical-error-message').html(message);
|
||||
$('#id-critical-error-close').text(me.txtClose).off().on('click', function(){
|
||||
$('#id-critical-error-dialog').modal('hide');
|
||||
});
|
||||
}
|
||||
|
||||
$('#id-critical-error-dialog').modal('show');
|
||||
|
||||
//Common.Analytics.trackEvent('Internal Error', id.toString());
|
||||
}
|
||||
|
||||
function onExternalMessage(error) {
|
||||
if (error) {
|
||||
hidePreloader();
|
||||
$('#id-error-mask-title').text(me.criticalErrorTitle);
|
||||
$('#id-error-mask-text').text(error.msg);
|
||||
$('#id-error-mask').css('display', 'block');
|
||||
|
||||
//Common.Analytics.trackEvent('External Error');
|
||||
}
|
||||
}
|
||||
|
||||
function onProcessMouse(data) {
|
||||
if (data.type == 'mouseup') {
|
||||
var e = document.getElementById('editor_sdk');
|
||||
if (e) {
|
||||
var r = e.getBoundingClientRect();
|
||||
api.OnMouseUp(
|
||||
data.x - r.left,
|
||||
data.y - r.top
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onRequestClose() {
|
||||
Common.Gateway.requestClose();
|
||||
}
|
||||
|
||||
function onDownloadAs() {
|
||||
if ( permissions.download === false) {
|
||||
Common.Gateway.reportError(Asc.c_oAscError.ID.AccessDeny, me.errorAccessDeny);
|
||||
return;
|
||||
}
|
||||
if (api) api.asc_DownloadAs(new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.PPTX, true));
|
||||
}
|
||||
|
||||
function onRunAutostartMacroses() {
|
||||
if (!config.customization || (config.customization.macros!==false))
|
||||
if (api) api.asc_runAutostartMacroses();
|
||||
}
|
||||
|
||||
function onBeforeUnload () {
|
||||
common.localStorage.save();
|
||||
}
|
||||
// Helpers
|
||||
// -------------------------
|
||||
|
||||
function onDocumentResize() {
|
||||
if (api) {
|
||||
api.Resize();
|
||||
}
|
||||
}
|
||||
|
||||
function createController(){
|
||||
if (created)
|
||||
return me;
|
||||
|
||||
me = this;
|
||||
created = true;
|
||||
|
||||
// popover ui handlers
|
||||
|
||||
$(window).resize(function(){
|
||||
onDocumentResize();
|
||||
});
|
||||
window.onbeforeunload = onBeforeUnload;
|
||||
|
||||
api = new Asc.asc_docs_api({
|
||||
'id-view' : 'editor_sdk',
|
||||
'embedded' : true
|
||||
});
|
||||
|
||||
if (api){
|
||||
api.SetThemesPath("../../../../sdkjs/slide/themes/");
|
||||
|
||||
api.asc_registerCallback('asc_onError', onError);
|
||||
api.asc_registerCallback('asc_onDocumentContentReady', onDocumentContentReady);
|
||||
api.asc_registerCallback('asc_onOpenDocumentProgress', onOpenDocument);
|
||||
api.asc_registerCallback('asc_onCountPages', onCountPages);
|
||||
api.asc_registerCallback('asc_onCurrentPage', onCurrentPage);
|
||||
|
||||
// Initialize api gateway
|
||||
Common.Gateway.on('init', loadConfig);
|
||||
Common.Gateway.on('opendocument', loadDocument);
|
||||
Common.Gateway.on('showmessage', onExternalMessage);
|
||||
Common.Gateway.appReady();
|
||||
}
|
||||
|
||||
return me;
|
||||
}
|
||||
|
||||
return {
|
||||
create : createController,
|
||||
errorDefaultMessage : 'Error code: %1',
|
||||
unknownErrorText : 'Unknown error.',
|
||||
convertationTimeoutText : 'Conversion timeout exceeded.',
|
||||
convertationErrorText : 'Conversion failed.',
|
||||
downloadErrorText : 'Download failed.',
|
||||
criticalErrorTitle : 'Error',
|
||||
notcriticalErrorTitle : 'Warning',
|
||||
scriptLoadError: 'The connection is too slow, some of the components could not be loaded. Please reload the page.',
|
||||
errorFilePassProtect: 'The file is password protected and cannot be opened.',
|
||||
errorAccessDeny: 'You are trying to perform an action you do not have rights for.<br>Please contact your Document Server administrator.',
|
||||
errorUserDrop: 'The file cannot be accessed right now.',
|
||||
unsupportedBrowserErrorText: 'Your browser is not supported.',
|
||||
textOf: 'of',
|
||||
downloadTextText: 'Downloading presentation...',
|
||||
waitText: 'Please, wait...',
|
||||
textLoadingDocument: 'Loading presentation',
|
||||
txtClose: 'Close',
|
||||
errorFileSizeExceed: 'The file size exceeds the limitation set for your server.<br>Please contact your Document Server administrator for details.',
|
||||
errorUpdateVersionOnDisconnect: 'Internet connection has been restored, and the file version has been changed.<br>Before you can continue working, you need to download the file or copy its content to make sure nothing is lost, and then reload this page.',
|
||||
textGuest: 'Guest',
|
||||
textAnonymous: 'Anonymous',
|
||||
errorForceSave: "An error occurred while saving the file. Please use the 'Download as' option to save the file to your computer hard drive or try again later.",
|
||||
errorLoadingFont: 'Fonts are not loaded.<br>Please contact your Document Server administrator.'
|
||||
}
|
||||
})();
|
75
test/presentationeditor/main/js/ApplicationView.js
Normal file
75
test/presentationeditor/main/js/ApplicationView.js
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
if (PE === undefined) {
|
||||
var PE = {};
|
||||
}
|
||||
|
||||
PE.ApplicationView = new(function(){
|
||||
var $btnTools;
|
||||
|
||||
// Initialize view
|
||||
|
||||
function createView(){
|
||||
$btnTools = $('#box-tools button');
|
||||
|
||||
$btnTools.addClass('dropdown-toggle').attr('data-toggle', 'dropdown').attr('aria-expanded', 'true');
|
||||
$btnTools.parent().append(
|
||||
'<ul class="dropdown-menu pull-right">' +
|
||||
'<li><a id="idt-print"><span class="mi-icon svg-icon print"></span>' + this.txtPrint + '</a></li>' +
|
||||
'<li><a id="idt-download"><span class="mi-icon svg-icon download"></span>' + this.txtDownload + '</a></li>' +
|
||||
'<li><a id="idt-share" data-toggle="modal"><span class="mi-icon svg-icon share"></span>' + this.txtShare + '</a></li>' +
|
||||
'<li><a id="idt-close" data-toggle="modal"><span class="mi-icon svg-icon go-to-location"></span>' + this.txtFileLocation + '</a></li>' +
|
||||
'<li class="divider"></li>' +
|
||||
'<li><a id="idt-embed" data-toggle="modal"><span class="mi-icon svg-icon embed"></span>' + this.txtEmbed + '</a></li>' +
|
||||
'<li><a id="idt-fullscreen"><span class="mi-icon svg-icon fullscr"></span>' + this.txtFullScreen + '</a></li>' +
|
||||
'</ul>');
|
||||
}
|
||||
|
||||
function getTools(name) {
|
||||
return $btnTools.parent().find(name);
|
||||
}
|
||||
|
||||
return {
|
||||
create: createView
|
||||
, tools: {
|
||||
get: getTools
|
||||
},
|
||||
|
||||
txtDownload: 'Download',
|
||||
txtPrint: 'Print',
|
||||
txtShare: 'Share',
|
||||
txtEmbed: 'Embed',
|
||||
txtFullScreen: 'Full Screen',
|
||||
txtFileLocation: 'Open file location'
|
||||
}
|
||||
})();
|
38
test/presentationeditor/main/js/application.js
Normal file
38
test/presentationeditor/main/js/application.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
(function ($) {
|
||||
Common.Locale.apply(function() {
|
||||
PE.ApplicationView.create();
|
||||
PE.ApplicationController.create();
|
||||
});
|
||||
})(window.jQuery);
|
1
test/presentationeditor/main/locale/en.json
Normal file
1
test/presentationeditor/main/locale/en.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
34
test/presentationeditor/main/resources/less/application.less
Normal file
34
test/presentationeditor/main/resources/less/application.less
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Bootstrap core variables and mixins
|
||||
@import "../../../../unit-tests/common/main/resources/less/common.less";
|
||||
|
||||
.overlay-controls {
|
||||
/*bottom: 15px;*/
|
||||
}
|
||||
|
||||
.overlay-icon-move-left { background-position: -64px -120px; }
|
||||
.overlay-icon-move-right { background-position: -96px -120px; }
|
||||
|
||||
#box-preview {
|
||||
position:absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
display:none;
|
||||
width:100%;
|
||||
height:100%;
|
||||
z-index: 10;
|
||||
padding: 48px 0 0 0;
|
||||
}
|
||||
|
||||
#id-preview {
|
||||
width:100%;
|
||||
height:100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.svg-icon {
|
||||
&.play {
|
||||
&.pause {
|
||||
background-position: -20px*10 -20px;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
call npm install less
|
||||
call npm install watchr
|
75
test/presentationeditor/main/resources/less/watch.js
Normal file
75
test/presentationeditor/main/resources/less/watch.js
Normal file
|
@ -0,0 +1,75 @@
|
|||
(function() {
|
||||
var path = require('path'),
|
||||
util = require('util'),
|
||||
fs = require('fs'),
|
||||
watchr = require('watchr'),
|
||||
less = require('less'),
|
||||
cwd = process.cwd(),
|
||||
watchPath = process.argv.length === 3 ? path.resolve(cwd, process.argv[2]) : cwd;
|
||||
|
||||
var options = {
|
||||
compress: false,
|
||||
yuicompress: false,
|
||||
optimization: 1,
|
||||
silent: false,
|
||||
paths: [],
|
||||
color: true,
|
||||
strictImports: false
|
||||
};
|
||||
|
||||
var parseLessFile = function(input, output){
|
||||
return function (e, data) {
|
||||
if (e) {
|
||||
console.log('lessc:', e.message);
|
||||
}
|
||||
|
||||
new(less.Parser)({
|
||||
paths: [path.dirname(input)],
|
||||
optimization: options.optimization,
|
||||
filename: input
|
||||
}).parse(data, function (err, tree) {
|
||||
if (err) {
|
||||
less.writeError(err, options);
|
||||
} else {
|
||||
try {
|
||||
var css = tree.toCSS({ compress: options.compress });
|
||||
if (output) {
|
||||
var fd = fs.openSync(output, "w");
|
||||
fs.writeSync(fd, css, 0, "utf8");
|
||||
} else {
|
||||
console.log('WARNING: output is undefined');
|
||||
util.print(css);
|
||||
}
|
||||
} catch (e) {
|
||||
less.writeError(e, options);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
console.log('>>> Script is polling for changes. Press Ctrl-C to Stop.');
|
||||
|
||||
watchr.watch({
|
||||
path: watchPath,
|
||||
listener: function(eventName, filePath, fileCurrentStat, filePreviousStat) {
|
||||
if (eventName == 'change' || eventName == 'update') {
|
||||
console.log('>>> Change detected at', new Date().toLocaleTimeString(), 'to:', path.basename(filePath));
|
||||
|
||||
var baseFilePath = path.basename(filePath, '.less');
|
||||
fs.readFile(filePath, 'utf-8', parseLessFile(filePath, '../css/' + baseFilePath + '.css'));
|
||||
|
||||
console.log('overwrite', baseFilePath + '.css');
|
||||
}
|
||||
},
|
||||
next: function(err, watcher) {
|
||||
if (err) {
|
||||
console.log('!!! epic fail');
|
||||
throw err;
|
||||
}
|
||||
|
||||
console.log('Now watching:', watchPath);
|
||||
}
|
||||
});
|
||||
|
||||
})();
|
Loading…
Reference in a new issue