diff --git a/customize.dist/template.js b/customize.dist/template.js index 062be4308..3c6585dce 100644 --- a/customize.dist/template.js +++ b/customize.dist/template.js @@ -4,7 +4,7 @@ define([ '/common/cryptpad-common.js', '/customize/pages.js', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', ], function ($, h, Cryptpad, Pages) { $(function () { var $body = $('body'); diff --git a/www/code/inner.js b/www/code/inner.js index 53d852ebd..306b57ff5 100644 --- a/www/code/inner.js +++ b/www/code/inner.js @@ -16,7 +16,7 @@ define([ 'cm/lib/codemirror', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less2/main.less', 'css!cm/lib/codemirror.css', diff --git a/www/common/LessLoader.js b/www/common/LessLoader.js index 61cacfbeb..c7b015655 100644 --- a/www/common/LessLoader.js +++ b/www/common/LessLoader.js @@ -18,9 +18,18 @@ define([ localStorage = {}; } - var fixURL = function (url) { - var mark = (url.indexOf('?') !== -1) ? '&' : '?'; - return url + mark + key; + var fixURL = function (url, parent) { + // data: blob: etc + if (/^[a-zA-Z0-9]*:/.test(url)) { return url; } + var ua = url.split('#'); + var mark = (ua[0].indexOf('?') !== -1) ? '&' : '?'; + ua[0] = ua[0] + mark + key; + if (ua[0].indexOf(':') === -1 && ua[0].indexOf('/') && parent) { + ua[0] = parent.replace(/\/[^\/]*$/, '/') + ua[0]; + } + var out = ua.join('#'); + //console.log(url + " --> " + out); + return out; }; var doXHR = Less.FileManager.prototype.doXHR; @@ -48,6 +57,40 @@ define([ localStorage['LESS_CACHE'] = key; }; + var fixAllURLs = function (source, parent) { + var urlRegEx = /@import\s*("([^"]*)"|'([^']*)')|url\s*\(\s*(\s*"([^"]*)"|'([^']*)'|[^\)]*\s*)\s*\)/ig; + var result, url; + + while (!!(result = urlRegEx.exec(source))) { + url = result[3] || result[2] || result[5] || result[6] || result[4]; + var newUrl = fixURL(url, parent); + var quoteLen = result[5] || result[6] ? 1 : 0; + source = source.substr(0, urlRegEx.lastIndex - url.length - quoteLen - 1) + + newUrl + source.substr(urlRegEx.lastIndex - quoteLen - 1); + urlRegEx.lastIndex = urlRegEx.lastIndex + (newUrl.length - url.length); + } + + return source; + }; + + var loadCSS = function (url, cb) { + var xhr = new window.XMLHttpRequest(); + xhr.open("GET", fixURL(url), true); + xhr.responseType = 'text'; + xhr.onload = function () { + if (/^4/.test('' + this.status)) { return cb("error loading " + url); } + cb(undefined, xhr.response); + }; + xhr.send(null); + }; + + var loadLess = function (url, cb) { + Less.render('@import (multiple) "' + url + '";', {}, function(err, css) { + if (err) { return void cb(err); } + cb(undefined, css.css); + }, window.less); + }; + module.exports.load = function (url /*:string*/, cb /*:()=>void*/) { checkCache(); if (localStorage['LESS_CACHE|' + key + '|' + url]) { @@ -55,15 +98,12 @@ define([ cb(); return; } - Less.render('@import (multiple) "' + url + '";', {}, function(err, css) { - if (err) { - console.log(err); - return; - } - localStorage['LESS_CACHE|' + key + '|' + url] = css.css; - inject(css.css, url); + ((/\.less([\?\#].*)?$/.test(url)) ? loadLess : loadCSS)(url, function (err, css) { + var output = fixAllURLs(css, url); + localStorage['LESS_CACHE|' + key + '|' + url] = output; + inject(output, url); cb(); - }, window.less); + }); }; return module.exports; diff --git a/www/contacts/inner.js b/www/contacts/inner.js index 556f37ee3..aee04ded1 100644 --- a/www/contacts/inner.js +++ b/www/contacts/inner.js @@ -1,6 +1,6 @@ define([ 'jquery', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/contacts/main.less', 'less!/customize/src/less/toolbar.less', diff --git a/www/contacts/main.js b/www/contacts/main.js index 29583c07e..95642b503 100644 --- a/www/contacts/main.js +++ b/www/contacts/main.js @@ -7,7 +7,7 @@ define([ '/common/common-messenger.js', '/contacts/messenger-ui.js', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less/cryptpad.less', ], function ($, Crypto, Toolbar, Cryptpad, Messenger, UI) { var Messages = Cryptpad.Messages; diff --git a/www/drive/inner.js b/www/drive/inner.js index da7ddbe1f..e1779778b 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -1,5 +1,5 @@ define([ - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/drive/file.less', 'less!/customize/src/less/cryptpad.less', diff --git a/www/drive/main.js b/www/drive/main.js index f415ad49e..a57c0687c 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -11,7 +11,7 @@ define([ '/common/cryptget.js', '/common/mergeDrive.js', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less/cryptpad.less', ], function ($, Listmap, Crypto, TextPatcher, JSONSortify, Cryptpad, FO, Toolbar, AppConfig, Get, Merge) { var module = window.MODULE = {}; diff --git a/www/file/inner.js b/www/file/inner.js index 1ada1f817..6b8ebfa75 100644 --- a/www/file/inner.js +++ b/www/file/inner.js @@ -13,7 +13,7 @@ define([ '/bower_components/file-saver/FileSaver.min.js', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less2/main.less', ], function ( diff --git a/www/filepicker/inner.js b/www/filepicker/inner.js index d5c655cb8..62b798f8d 100644 --- a/www/filepicker/inner.js +++ b/www/filepicker/inner.js @@ -9,7 +9,7 @@ define([ 'json.sortify', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less2/main.less', ], function ( $, diff --git a/www/login/main.js b/www/login/main.js index ac4baf860..5637fd4a3 100644 --- a/www/login/main.js +++ b/www/login/main.js @@ -3,7 +3,7 @@ define([ '/common/cryptpad-common.js', '/common/login.js', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less/loading.less', ], function ($, Cryptpad, Login) { $(function () { diff --git a/www/oldcode/inner.js b/www/oldcode/inner.js index d36a7acd2..f6b83beee 100644 --- a/www/oldcode/inner.js +++ b/www/oldcode/inner.js @@ -3,7 +3,7 @@ define([ 'cm/lib/codemirror', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/code/code.less', 'less!/customize/src/less/toolbar.less', diff --git a/www/oldcode/main.js b/www/oldcode/main.js index 5e06572b6..53ca1c5d8 100644 --- a/www/oldcode/main.js +++ b/www/oldcode/main.js @@ -10,7 +10,7 @@ define([ '/common/cryptget.js', '/common/diffMarked.js', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less/cryptpad.less' ], function ($, Crypto, Realtime, TextPatcher, Toolbar, JSONSortify, JsonOT, Cryptpad, Cryptget, DiffMd) { diff --git a/www/oldfile/inner.js b/www/oldfile/inner.js index 4be0b8483..c476c5108 100644 --- a/www/oldfile/inner.js +++ b/www/oldfile/inner.js @@ -1,6 +1,6 @@ define([ 'jquery', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/file/file.less', 'less!/customize/src/less/cryptpad.less', diff --git a/www/oldfile/main.js b/www/oldfile/main.js index 136702c47..22c9c9051 100644 --- a/www/oldfile/main.js +++ b/www/oldfile/main.js @@ -12,7 +12,7 @@ define([ '/bower_components/file-saver/FileSaver.min.js', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less/cryptpad.less', ], function ($, Crypto, realtimeInput, Toolbar, Cryptpad, Visible, Notify, FileCrypto, MediaTag) { var Messages = Cryptpad.Messages; diff --git a/www/oldslide/main.js b/www/oldslide/main.js index da133ce46..cffff94e1 100644 --- a/www/oldslide/main.js +++ b/www/oldslide/main.js @@ -10,7 +10,7 @@ define([ '/common/cryptget.js', '/slide/slide.js', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less/cryptpad.less', ], function ($, Crypto, Realtime, TextPatcher, Toolbar, JSONSortify, JsonOT, Cryptpad, Cryptget, Slide) { var Messages = Cryptpad.Messages; diff --git a/www/pad/inner.js b/www/pad/inner.js index 3bb73d6ad..fde4a04ff 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -38,7 +38,7 @@ define([ '/bower_components/diff-dom/diffDOM.js', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less2/main.less', ], function ( $, diff --git a/www/poll/main.js b/www/poll/main.js index 8a36ecd37..eaadb2114 100644 --- a/www/poll/main.js +++ b/www/poll/main.js @@ -10,7 +10,7 @@ define([ '/common/toolbar2.js', '/bower_components/file-saver/FileSaver.min.js', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/customize/src/less/toolbar.less', 'less!/customize/src/less/cryptpad.less', diff --git a/www/register/main.js b/www/register/main.js index 3e57006f5..b3bbed8ab 100644 --- a/www/register/main.js +++ b/www/register/main.js @@ -5,7 +5,7 @@ define([ '/common/test.js', '/common/credential.js', // preloaded for login.js - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less/loading.less', ], function ($, Login, Cryptpad, Test, Cred) { var Messages = Cryptpad.Messages; diff --git a/www/settings/main.js b/www/settings/main.js index 5fc6e6825..a94cf7141 100644 --- a/www/settings/main.js +++ b/www/settings/main.js @@ -7,7 +7,7 @@ define([ '/bower_components/file-saver/FileSaver.min.js', 'less!/customize/src/less/cryptpad.less', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/customize/src/less/toolbar.less', 'less!/settings/main.less', diff --git a/www/slide/inner.js b/www/slide/inner.js index 80fb3e02d..8233f21f1 100644 --- a/www/slide/inner.js +++ b/www/slide/inner.js @@ -17,7 +17,7 @@ define([ 'cm/lib/codemirror', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less2/main.less', 'css!cm/lib/codemirror.css', diff --git a/www/todo/inner.js b/www/todo/inner.js index 69ef53f73..79ef5783d 100644 --- a/www/todo/inner.js +++ b/www/todo/inner.js @@ -1,6 +1,6 @@ define([ 'jquery', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/todo/todo.less', //'less!/customize/src/less/cryptpad.less', diff --git a/www/todo/main.js b/www/todo/main.js index 4ed134701..abb732661 100644 --- a/www/todo/main.js +++ b/www/todo/main.js @@ -9,7 +9,7 @@ define([ //'/common/media-tag.js', //'/bower_components/file-saver/FileSaver.min.js', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less/cryptpad.less', ], function ($, Crypto, Listmap, Toolbar, Cryptpad, Todo) { var Messages = Cryptpad.Messages; diff --git a/www/whiteboard/main.js b/www/whiteboard/main.js index 3871337cd..17e929d9b 100644 --- a/www/whiteboard/main.js +++ b/www/whiteboard/main.js @@ -15,7 +15,7 @@ define([ '/bower_components/secure-fabric.js/dist/fabric.min.js', '/bower_components/file-saver/FileSaver.min.js', - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/customize/src/less/cryptpad.less', 'less!/whiteboard/whiteboard.less',