From bd19d1dd2bc97ffcd63544270b641a7cdac60897 Mon Sep 17 00:00:00 2001 From: Jos van den Oever Date: Mon, 21 May 2012 00:27:10 +0200 Subject: [PATCH] Compile webodf.css into webodf.js and webodf-debug.js. In this way, there is no need to separately add webodf.css when using WebODF. webodf.js is now all that is needed. --- CMakeLists.txt | 4 ++-- webodf/CMakeLists.txt | 10 +++++++++- webodf/lib/odf/OdfCanvas.js | 34 +++++++++++++++++++++++++--------- webodf/odf.html | 1 - 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2821ae2..d90fe632 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,9 +93,9 @@ if (NOT ANT) find_file(ANT NAMES ant ant.exe /usr/bin /usr/local/bin) endif(NOT ANT) - - set(LIBJSFILES lib/packages.js lib/runtime.js lib/core/Base64.js + webodf.css.js + lib/core/RawDeflate.js lib/core/ByteArray.js lib/core/ByteArrayWriter.js lib/core/RawInflate.js lib/core/Cursor.js lib/core/UnitTester.js diff --git a/webodf/CMakeLists.txt b/webodf/CMakeLists.txt index 247ff5c6..9db8bf19 100644 --- a/webodf/CMakeLists.txt +++ b/webodf/CMakeLists.txt @@ -25,6 +25,13 @@ add_custom_target(jslintcheck ALL SOURCES ${LIBJSFILES} ${TESTJSFILES} ) +add_custom_target(webodf.css.js ALL + COMMAND ${NODE} lib/runtime.js tools/css2js.js webodf.css webodf.css.js + DEPENDS NodeJS + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + SOURCES webodf.css +) + if (Java_JAVA_EXECUTABLE) # nonStandardJsDocs is not used because we use @licstart @licend and @source set(SHARED_CLOSURE_ARGS --warning_level VERBOSE --jscomp_error accessControls --jscomp_error ambiguousFunctionDecl --jscomp_error checkRegExp --jscomp_error checkTypes --jscomp_error checkVars --jscomp_error constantProperty --jscomp_error deprecated --jscomp_error externsValidation --jscomp_error fileoverviewTags --jscomp_error globalThis --jscomp_error invalidCasts --jscomp_error missingProperties --jscomp_error strictModuleDepCheck --jscomp_error typeInvalidation --jscomp_error undefinedVars --jscomp_error unknownDefines --jscomp_error uselessCode --jscomp_error visibility --jscomp_off nonStandardJsDocs --summary_detail_level 3) @@ -73,7 +80,8 @@ if (Java_JAVA_EXECUTABLE) --formatting PRINT_INPUT_DELIMITER --externs ${CMAKE_CURRENT_SOURCE_DIR}/tools/externs.js --js_output_file ${CMAKE_CURRENT_BINARY_DIR}/webodf.js - DEPENDS ClosureCompiler ${LIBJSFILES} tools/externs.js + DEPENDS ClosureCompiler ${LIBJSFILES} tools/externs.js webodf.css + tools/css2js.js ) add_custom_target(webodf.js SOURCES ${CMAKE_CURRENT_BINARY_DIR}/webodf.js diff --git a/webodf/lib/odf/OdfCanvas.js b/webodf/lib/odf/OdfCanvas.js index 2f1c4b7b..6f08d56d 100644 --- a/webodf/lib/odf/OdfCanvas.js +++ b/webodf/lib/odf/OdfCanvas.js @@ -31,7 +31,7 @@ * @source: http://gitorious.org/odfkit/webodf/ */ /*jslint sub: true*/ -/*global runtime, odf, xmldom */ +/*global runtime, odf, xmldom, webodf_css */ runtime.loadClass("odf.OdfContainer"); runtime.loadClass("odf.Formatting"); runtime.loadClass("xmldom.XPath"); @@ -611,14 +611,28 @@ odf.OdfCanvas = (function () { } // embedded video is stored in a draw:plugin element plugins = odffragment.getElementsByTagNameNS(drawns, 'plugin'); - runtime.log('Loading Videos:'); for (i = 0; i < plugins.length; i += 1) { - runtime.log('...Found a video.'); node = /**@type{!Element}*/(plugins.item(i)); loadVideo('video' + String(i), container, node, stylesheet); } } + function addWebODFStyleSheet(document) { + var head = document.getElementsByTagName('head')[0], + style; + if (typeof (webodf_css) !== 'undefined') { + style = document.createElementNS(head.namespaceURI, 'style'); + style.setAttribute('media', 'screen, print, handheld, projection'); + style.appendChild(document.createTextNode(webodf_css)); + } else { + style = document.createElementNS(head.namespaceURI, 'link'); + style.setAttribute('href', 'webodf.css'); + style.setAttribute('rel', 'stylesheet'); + } + style.setAttribute('type', 'text/css'); + head.appendChild(style); + return style; + } /** * @param {Document} document Put and ODF Canvas inside this element. */ @@ -626,9 +640,7 @@ odf.OdfCanvas = (function () { var head = document.getElementsByTagName('head')[0], style = document.createElementNS(head.namespaceURI, 'style'), text = '', - prefix, - a = "", - b; + prefix; style.setAttribute('type', 'text/css'); style.setAttribute('media', 'screen, print, handheld, projection'); for (prefix in namespaces) { @@ -652,11 +664,15 @@ odf.OdfCanvas = (function () { /**@type{!odf.Formatting}*/ formatting = new odf.Formatting(), selectionWatcher = new SelectionWatcher(element), slidecssindex = 0, - pageSwitcher = new PageSwitcher(addStyleSheet(document)), - stylesxmlcss = addStyleSheet(document), - positioncss = addStyleSheet(document), + pageSwitcher, + stylesxmlcss, + positioncss, editable = false, zoomLevel = 1; + addWebODFStyleSheet(document); + pageSwitcher = new PageSwitcher(addStyleSheet(document)); + stylesxmlcss = addStyleSheet(document); + positioncss = addStyleSheet(document); function fixContainerSize() { var sizer = element.firstChild, diff --git a/webodf/odf.html b/webodf/odf.html index 1bc867fa..99796743 100644 --- a/webodf/odf.html +++ b/webodf/odf.html @@ -17,7 +17,6 @@ background: black; } -