Validation for embed plugin added

This commit is contained in:
George Berezhnoy 2017-01-26 04:34:00 +03:00
parent 1269a84f95
commit a8cf1bcdd6
3 changed files with 33 additions and 18 deletions

View file

@ -183,6 +183,7 @@
settings: null, settings: null,
render: embed.render, render: embed.render,
save: embed.save, save: embed.save,
validate: embed.validate,
displayInToolbox: false, displayInToolbox: false,
enableLineBreaks: false, enableLineBreaks: false,
allowedToPaste: false allowedToPaste: false

View file

@ -28,6 +28,22 @@ var embed = function(embed){
wrapper.innerHTML = html; wrapper.innerHTML = html;
return wrapper; return wrapper;
},
getRemoteId: function(source, execArray) {
switch(source) {
case 'yandex-music-track':
id = execArray[2]+'/'+execArray[1];
break;
case 'yandex-music-playlist':
id = execArray[1]+'/'+execArray[2];
break;
default:
id = execArray[1];
}
return id;
} }
}; };
@ -82,19 +98,19 @@ var embed = function(embed){
width: 600 width: 600
}, },
'yandex-music-album': { 'yandex-music-album': {
regex: '', regex: /https?:\/\/music.yandex.ru\/album\/([0-9]*)/,
html: "<iframe frameborder=\"0\" style=\"border:none;width:540px;height:400px;\" width=\"540\" height=\"400\" src=\"https://music.yandex.ru/iframe/#album/<%= remote_id %>/\"></iframe>", html: "<iframe frameborder=\"0\" style=\"border:none;width:540px;height:400px;\" width=\"540\" height=\"400\" src=\"https://music.yandex.ru/iframe/#album/<%= remote_id %>/\"></iframe>",
height: 400, height: 400,
width: 540 width: 540
}, },
'yandex-music-track': { 'yandex-music-track': {
regex: '', regex: /https?:\/\/music.yandex.ru\/album\/([0-9]*)\/track\/([0-9]*)/,
html: "<iframe frameborder=\"0\" style=\"border:none;width:540px;height:100px;\" width=\"540\" height=\"100\" src=\"https://music.yandex.ru/iframe/#track/<%= remote_id %>/\"></iframe>", html: "<iframe frameborder=\"0\" style=\"border:none;width:540px;height:100px;\" width=\"540\" height=\"100\" src=\"https://music.yandex.ru/iframe/#track/<%= remote_id %>/\"></iframe>",
height: 100, height: 100,
width: 540 width: 540
}, },
'yandex-music-playlist': { 'yandex-music-playlist': {
regex: '', regex: /https?:\/\/music.yandex.ru\/users\/([^\/\?\&]*)\/playlists\/([0-9]*)/,
html: "<iframe frameborder=\"0\" style=\"border:none;width:540px;height:400px;\" width=\"540\" height=\"400\" src=\"https://music.yandex.ru/iframe/#playlist/<%= remote_id %>/show/cover/description/\"></iframe>", html: "<iframe frameborder=\"0\" style=\"border:none;width:540px;height:400px;\" width=\"540\" height=\"400\" src=\"https://music.yandex.ru/iframe/#playlist/<%= remote_id %>/show/cover/description/\"></iframe>",
height: 400, height: 400,
width: 540 width: 540
@ -162,19 +178,7 @@ var embed = function(embed){
embed.urlPastedCallback = function(url, pattern) { embed.urlPastedCallback = function(url, pattern) {
var execArray = pattern.regex.exec(url), var execArray = pattern.regex.exec(url),
id; id = methods.getRemoteId(pattern.type, execArray);
switch(pattern.type) {
case 'yandex-music-track':
id = execArray[2]+'/'+execArray[1];
break;
case 'yandex-music-playlist':
id = execArray[1]+'/'+execArray[2];
break;
default:
id = execArray[1];
}
var data = { var data = {
source: pattern.type, source: pattern.type,
@ -185,6 +189,16 @@ var embed = function(embed){
embed.make(data, true); embed.make(data, true);
}; };
embed.validate = function(savedData) {
var source = savedData.source,
execArray = services[source].regex.exec(savedData.thumbnailUrl),
remoteId = methods.getRemoteId(source, execArray);
return remoteId == savedData.remote_id;
};
return embed; return embed;
}({}); }({});

View file

@ -20,12 +20,12 @@ paste.patterns = [
}, },
{ {
type: 'instagram', type: 'instagram',
regex: new RegExp("http?.+instagram.com\/p?."), regex: /http?.+instagram.com\/p\/([a-zA-Z0-9]*)/,
callback: instagram.urlPastedCallback callback: instagram.urlPastedCallback
}, },
{ {
type: 'twitter', type: 'twitter',
regex: new RegExp("http?.+twitter.com?.+\/"), regex: /http?.+twitter.com?.+\//,
callback: twitter.urlPastedCallback callback: twitter.urlPastedCallback
}, },
{ {