Skip to content

Commit

Permalink
Gutenberg: Introduce internal helper JS function, validateLink().
Browse files Browse the repository at this point in the history
See #13.
  • Loading branch information
r-a-y committed Apr 9, 2020
1 parent c502b26 commit f848bb2
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions block.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
}
}

getType = function( attr ) {
var link = attr.link,
type = '';

validateLink = function( link ) {
if ( ! link ) {
return false;
}
Expand All @@ -33,6 +30,17 @@
return false;
}

return link;
}

getType = function( attr ) {
var link = validateLink( attr.link ),
type = '';

if ( ! link ) {
return false;
}

if ( -1 !== link.indexOf( '/document/' ) ) {
type = 'doc';
} else if ( -1 !== link.indexOf( '/presentation/' ) || -1 !== link.indexOf( '/present/' ) ) {
Expand All @@ -51,7 +59,7 @@
}

renderOutput = function( attr ) {
var link = attr.link,
var link = validateLink( attr.link ),
invalid = false,
width = '100%',
height = '300',
Expand All @@ -62,12 +70,7 @@
output = [];

if ( ! link ) {
link = '';
invalid = true;
}

if ( -1 === link.indexOf( '://docs.google.com' ) && -1 === link.indexOf( '://drive.google.com' ) ) {
invalid = true;
return '';
}

if ( attr.hasOwnProperty( 'width' ) ) {
Expand Down

0 comments on commit f848bb2

Please sign in to comment.