diff --git a/www/common/common-interface.js b/www/common/common-interface.js index e23756cec..cc3f838f6 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -130,5 +130,92 @@ define([ Alertify.error(Util.fixHTML(msg)); }; + /* + * spinner + */ + UI.spinner = function (parent) { + var $target = $('', { + 'class': 'fa fa-spinner fa-pulse fa-4x fa-fw' + }).hide(); + + $(parent).append($target); + + return { + show: function () { + $target.show(); + return this; + }, + hide: function () { + $target.hide(); + return this; + }, + get: function () { + return $target; + }, + }; + }; + + var LOADING = 'loading'; + + var getRandomTip = function () { + if (!Messages.tips || !Object.keys(Messages.tips).length) { return ''; } + var keys = Object.keys(Messages.tips); + var rdm = Math.floor(Math.random() * keys.length); + return Messages.tips[keys[rdm]]; + }; + UI.addLoadingScreen = function (loadingText, hideTips) { + var $loading, $container; + if ($('#' + LOADING).length) { + $loading = $('#' + LOADING).show(); + if (loadingText) { + $('#' + LOADING).find('p').text(loadingText); + } + $container = $loading.find('.loadingContainer'); + } else { + $loading = $('
', {id: LOADING}); + $container = $('
', {'class': 'loadingContainer'}); + $container.append(''); + var $spinner = $('
', {'class': 'spinnerContainer'}); + UI.spinner($spinner).show(); + var $text = $('

').text(loadingText || Messages.loading); + $container.append($spinner).append($text); + $loading.append($container); + $('body').append($loading); + } + if (Messages.tips && !hideTips) { + var $loadingTip = $('

', {'id': 'loadingTip'}); + var $tip = $('', {'class': 'tips'}).text(getRandomTip()).appendTo($loadingTip); + $loadingTip.css({ + 'top': $('body').height()/2 + $container.height()/2 + 20 + 'px' + }); + $('body').append($loadingTip); + } + }; + UI.removeLoadingScreen = function (cb) { + $('#' + LOADING).fadeOut(750, cb); + $('#loadingTip').css('top', ''); + window.setTimeout(function () { + $('#loadingTip').fadeOut(750); + }, 3000); + }; + UI.errorLoadingScreen = function (error, transparent) { + if (!$('#' + LOADING).is(':visible')) { UI.addLoadingScreen(undefined, true); } + $('.spinnerContainer').hide(); + if (transparent) { $('#' + LOADING).css('opacity', 0.8); } + $('#' + LOADING).find('p').html(error || Messages.error); + }; + + var importContent = UI.importContent = function (type, f) { + return function () { + var $files = $('').click(); + $files.on('change', function (e) { + var file = e.target.files[0]; + var reader = new FileReader(); + reader.onload = function (e) { f(e.target.result, file); }; + reader.readAsText(file, type); + }); + }; + }; + return UI; }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 68d5204fb..620445bce 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -31,7 +31,6 @@ define([ var userNameKey = common.userNameKey = 'User_name'; var fileHashKey = common.fileHashKey = 'FS_hash'; var displayNameKey = common.displayNameKey = 'cryptpad.username'; - var LOADING = 'loading'; var newPadNameKey = common.newPadNameKey = "newPadName"; var newPadPathKey = common.newPadPathKey = "newPadPath"; var storageKey = common.storageKey = 'CryptPad_RECENTPADS'; @@ -49,6 +48,10 @@ define([ common.confirm = UI.confirm; common.log = UI.log; common.warn = UI.warn; + common.spinner = UI.spinner; + common.addLoadingScreen = UI.addLoadingScreen; + common.removeLoadingScreen = UI.removeLoadingScreen; + common.errorLoadingScreen = UI.errorLoadingScreen; // import common utilities for export var find = common.find = Util.find; @@ -155,7 +158,6 @@ define([ return url; }; - var login = common.login = function (hash, name, cb) { if (!hash) { throw new Error('expected a user hash'); } if (!name) { throw new Error('expected a user name'); } @@ -566,66 +568,6 @@ define([ }); }; - var getRandomTip = function () { - if (!Messages.tips || !Object.keys(Messages.tips).length) { return ''; } - var keys = Object.keys(Messages.tips); - var rdm = Math.floor(Math.random() * keys.length); - return Messages.tips[keys[rdm]]; - }; - common.addLoadingScreen = function (loadingText, hideTips) { - var $loading, $container; - if ($('#' + LOADING).length) { - $loading = $('#' + LOADING).show(); - if (loadingText) { - $('#' + LOADING).find('p').text(loadingText); - } - $container = $loading.find('.loadingContainer'); - } else { - $loading = $('
', {id: LOADING}); - $container = $('
', {'class': 'loadingContainer'}); - $container.append(''); - var $spinner = $('
', {'class': 'spinnerContainer'}); - common.spinner($spinner).show(); - var $text = $('

').text(loadingText || Messages.loading); - $container.append($spinner).append($text); - $loading.append($container); - $('body').append($loading); - } - if (Messages.tips && !hideTips) { - var $loadingTip = $('

', {'id': 'loadingTip'}); - var $tip = $('', {'class': 'tips'}).text(getRandomTip()).appendTo($loadingTip); - $loadingTip.css({ - 'top': $('body').height()/2 + $container.height()/2 + 20 + 'px' - }); - $('body').append($loadingTip); - } - }; - common.removeLoadingScreen = function (cb) { - $('#' + LOADING).fadeOut(750, cb); - $('#loadingTip').css('top', ''); - window.setTimeout(function () { - $('#loadingTip').fadeOut(750); - }, 3000); - }; - common.errorLoadingScreen = function (error, transparent) { - if (!$('#' + LOADING).is(':visible')) { common.addLoadingScreen(undefined, true); } - $('.spinnerContainer').hide(); - if (transparent) { $('#' + LOADING).css('opacity', 0.8); } - $('#' + LOADING).find('p').html(error || Messages.error); - }; - - var importContent = common.importContent = function (type, f) { - return function () { - var $files = $('').click(); - $files.on('change', function (e) { - var file = e.target.files[0]; - var reader = new FileReader(); - reader.onload = function (e) { f(e.target.result, file); }; - reader.readAsText(file, type); - }); - }; - }; - /* * Buttons */ @@ -748,7 +690,7 @@ define([ title: Messages.importButtonTitle, }).append($('', {'class':'fa fa-upload', style: 'font:'+size+' FontAwesome'})); if (callback) { - button.click(common.importContent('text/plain', function (content, file) { + button.click(UI.importContent('text/plain', function (content, file) { callback(content, file); })); } @@ -1172,31 +1114,6 @@ define([ }; - /* - * spinner - */ - common.spinner = function (parent) { - var $target = $('', { - 'class': 'fa fa-spinner fa-pulse fa-4x fa-fw' - }).hide(); - - $(parent).append($target); - - return { - show: function () { - $target.show(); - return this; - }, - hide: function () { - $target.hide(); - return this; - }, - get: function () { - return $target; - }, - }; - }; - // local name? common.ready = function (f) { var block = 0;