define([ 'jquery', '/api/config', '/common/common-util.js', '/common/common-hash.js', '/common/common-language.js', '/common/common-interface.js', '/common/common-constants.js', '/common/common-feedback.js', '/common/hyperscript.js', '/common/media-tag.js', '/common/clipboard.js', '/customize/messages.js', '/customize/application_config.js', '/customize/pages.js', '/bower_components/nthen/index.js', '/common/inner/invitation.js', 'css!/customize/fonts/cptools/style.css', '/bower_components/croppie/croppie.min.js', 'css!/bower_components/croppie/croppie.css', ], function ($, Config, Util, Hash, Language, UI, Constants, Feedback, h, MediaTag, Clipboard, Messages, AppConfig, Pages, NThen, InviteInner) { var UIElements = {}; // Configure MediaTags to use our local viewer if (MediaTag) { MediaTag.setDefaultConfig('pdf', { viewer: '/common/pdfjs/web/viewer.html' }); } UIElements.prettySize = function (bytes) { var kB = Util.bytesToKilobytes(bytes); if (kB < 1024) { return kB + Messages.KB; } var mB = Util.bytesToMegabytes(bytes); return mB + Messages.MB; }; UIElements.updateTags = function (common, href) { var existing, tags; NThen(function(waitFor) { common.getSframeChannel().query("Q_GET_ALL_TAGS", null, waitFor(function(err, res) { if (err || res.error) { return void console.error(err || res.error); } existing = Object.keys(res.tags).sort(); })); }).nThen(function (waitFor) { common.getPadAttribute('tags', waitFor(function (err, res) { if (err) { if (err === 'NO_ENTRY') { UI.alert(Messages.tags_noentry); } waitFor.abort(); return void console.error(err); } tags = res || []; }), href); }).nThen(function () { UI.dialog.tagPrompt(tags, existing, function (newTags) { if (!Array.isArray(newTags)) { return; } common.setPadAttribute('tags', newTags, null, href); }); }); }; var dcAlert; UIElements.disconnectAlert = function () { if (dcAlert && $(dcAlert.element).length) { return; } dcAlert = UI.alert(Messages.common_connectionLost, undefined, true); }; UIElements.reconnectAlert = function () { if (!dcAlert) { return; } if (!dcAlert.delete) { dcAlert = undefined; return; } dcAlert.delete(); dcAlert = undefined; }; var importContent = function (type, f, cfg) { return function () { var $files = $('', {type:"file"}); if (cfg && cfg.accept) { $files.attr('accept', cfg.accept); } $files.click(); $files.on('change', function (e) { var file = e.target.files[0]; var reader = new FileReader(); var parsed = file && file.name && /.+\.([^.]+)$/.exec(file.name); var ext = parsed && parsed[1]; reader.onload = function (e) { f(e.target.result, file, ext); }; if (cfg && cfg.binary && cfg.binary.indexOf(ext) !== -1) { reader.readAsArrayBuffer(file, type); } else { reader.readAsText(file, type); } }); }; }; var getPadProperties = function (common, data, opts, cb) { opts = opts || {}; var $d = $('
'); if (!data) { return void cb(void 0, $d); } var priv = common.getMetadataMgr().getPrivateData(); var edPublic = priv.edPublic; if (data.href) { $('