From 3ca9f41290d27b616af8e3878f488ac441b180cb Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 6 Sep 2017 10:56:27 +0200 Subject: [PATCH] Get embed code for pad and code --- customize.dist/translations/messages.fr.js | 2 +- customize.dist/translations/messages.js | 4 ++- www/common/sframe-channel.js | 4 +-- www/common/sframe-common-interface.js | 10 +++--- www/common/sframe-common.js | 2 +- www/common/toolbar2.js | 4 +-- www/common/toolbar3.js | 36 +++++++++++++++++++++- 7 files changed, 49 insertions(+), 13 deletions(-) diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index e118f8cf9..95a882288 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -172,7 +172,7 @@ define(function () { out.viewOpen = "Voir dans un nouvel onglet"; out.viewOpenTitle = "Ouvrir le lien en lecture seule dans un nouvel onglet"; out.fileShare = "Copier le lien"; - out.fileEmbed = "Obtenir le code d'intégration"; + out.getEmbedCode = "Obtenir le code d'intégration"; out.fileEmbedTitle = "Intégrer le fichier dans une page web"; out.fileEmbedScript = "Pour intégrer un fichier, veuillez inclure le script suivant une fois dans votre page afin de pouvoir charger le Media Tag :"; out.fileEmbedTag = "Ensuite vous pouvez placer ce Media Tag où vous souhaitez dans votre page pour l'intégrer :"; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 3905b7601..51ba6ae4a 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -174,7 +174,9 @@ define(function () { out.viewOpen = "Open read-only link in a new tab"; out.viewOpenTitle = "Open this pad in read-only mode in a new tab"; out.fileShare = "Copy link"; - out.fileEmbed = "Get embed code"; + out.getEmbedCode = "Get embed code"; + out.viewEmbedTitle = ""; + out.viewEmbedTag = ""; out.fileEmbedTitle = "Embed the file in an external page"; out.fileEmbedScript = "To embed this file, include this script once in your page to load the Media Tag:"; out.fileEmbedTag = "Then place this Media Tag wherever in your page you would like to embed:"; diff --git a/www/common/sframe-channel.js b/www/common/sframe-channel.js index fc9bcd0dd..c4aed597b 100644 --- a/www/common/sframe-channel.js +++ b/www/common/sframe-channel.js @@ -7,7 +7,7 @@ define([ return Math.random().toString(16).replace('0.', '') + Math.random().toString(16).replace('0.', ''); }; - var create = function (ow, cb) { + var create = function (ow, cb, isSandbox) { var otherWindow; var handlers = {}; var queries = {}; @@ -131,7 +131,7 @@ define([ console.log(msg); } }); - if (window !== window.top) { + if (isSandbox) { // we're in the sandbox otherWindow = ow; cb(chan); diff --git a/www/common/sframe-common-interface.js b/www/common/sframe-common-interface.js index 459991e1c..c6dff14f6 100644 --- a/www/common/sframe-common-interface.js +++ b/www/common/sframe-common-interface.js @@ -230,31 +230,31 @@ define([ $userAdmin.find('a.logout').click(function () { Common.logout(function () { - window.top.location = origin+'/'; + window.parent.location = origin+'/'; }); }); $userAdmin.find('a.settings').click(function () { if (padType) { window.open(origin+'/settings/'); } else { - window.top.location = origin+'/settings/'; + window.parent.location = origin+'/settings/'; } }); $userAdmin.find('a.profile').click(function () { if (padType) { window.open(origin+'/profile/'); } else { - window.top.location = origin+'/profile/'; + window.parent.location = origin+'/profile/'; } }); $userAdmin.find('a.login').click(function () { Common.setLoginRedirect(function () { - window.top.location = origin+'/login/'; + window.parent.location = origin+'/login/'; }); }); $userAdmin.find('a.register').click(function () { Common.setLoginRedirect(function () { - window.top.location = origin+'/register/'; + window.parent.location = origin+'/register/'; }); }); diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 484c48681..36dd5e6ca 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -357,7 +357,7 @@ define([ Object.freeze(funcs); return { create: function (cb) { nThen(function (waitFor) { - SFrameChannel.create(window.top, waitFor(function (sfc) { ctx.sframeChan = sfc; })); + SFrameChannel.create(window.parent, waitFor(function (sfc) { ctx.sframeChan = sfc; }), true); // CpNfInner.start() should be here.... }).nThen(function () { ctx.metadataMgr = MetadataMgr.create(ctx.sframeChan); diff --git a/www/common/toolbar2.js b/www/common/toolbar2.js index dd2b8c4b2..6909d8c0d 100644 --- a/www/common/toolbar2.js +++ b/www/common/toolbar2.js @@ -491,8 +491,8 @@ define([ }); options.push({ tag: 'a', - attributes: {title: Messages.editShareTitle, 'class': 'fileEmbed'}, - content: ' ' + Messages.fileEmbed + attributes: {title: Messages.fileEmbedTitle, 'class': 'fileEmbed'}, + content: ' ' + Messages.getEmbedCode }); var dropdownConfigShare = { text: $('
').append($shareIcon).html(), diff --git a/www/common/toolbar3.js b/www/common/toolbar3.js index 7c8d4dd1c..436a3e94d 100644 --- a/www/common/toolbar3.js +++ b/www/common/toolbar3.js @@ -408,6 +408,15 @@ define([ content: ' ' + Messages.viewOpen }); } + options.push({tag: 'hr'}); + options.push({ + tag: 'a', + attributes: { + title: Messages.viewEmbedTitle, + 'class': 'cp-toolbar-share-view-embed', + }, + content: ' ' + Messages.getEmbedCode + }); } var dropdownConfigShare = { text: $('
').append($shareIcon).html(), @@ -438,6 +447,31 @@ define([ var success = Cryptpad.Clipboard.copy(url); if (success) { Cryptpad.log(Messages.shareSuccess); } }); + $shareBlock.find('a.cp-toolbar-share-view-embed').click(function () { + var url = origin + pathname + '#' + hashes.viewHash; + var parsed = Cryptpad.parsePadUrl(url); + url = origin + parsed.getUrl({embed: true}); + // Alertify content + var $content = $('
'); + $('', {'style':'display:none;'}).appendTo($content); + $('

').text(Messages.viewEmbedTitle).appendTo($content); + var $tag = $('

').text(Messages.fileEmbedTag).appendTo($content); + $('
').appendTo($tag); + var iframeId = uid(); + var iframeEmbed = ''; + $('', { + type: 'text', + id: iframeId, + readonly: 'readonly', + value: iframeEmbed, + }).appendTo($tag); + Cryptpad.alert($content.html(), null, true); + $('#'+iframeId).click(function () { + this.select(); + }); + //var success = Cryptpad.Clipboard.copy(url); + //if (success) { Cryptpad.log(Messages.shareSuccess); } + }); } toolbar.$leftside.append($shareBlock); @@ -611,7 +645,7 @@ define([ window.open(href); return; } - window.top.location = href; + window.parent.location = href; }; var onContext = function (e) { e.stopPropagation(); };