Skip to content

Commit

Permalink
Refactor video format attribute handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Müller committed Sep 16, 2016
1 parent db1ff85 commit 9b819b2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions formats/video.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { BlockEmbed } from '../blots/block';
import Link from '../formats/link';

const ATTRIBUTES = [
'height',
'width'
];


class Video extends BlockEmbed {
static create(value) {
Expand All @@ -12,10 +17,12 @@ class Video extends BlockEmbed {
}

static formats(domNode) {
let formats = {};
if (domNode.hasAttribute('height')) formats['height'] = domNode.getAttribute('height');
if (domNode.hasAttribute('width')) formats['width'] = domNode.getAttribute('width');
return formats;
return ATTRIBUTES.reduce(function(formats, attribute) {
if (domNode.hasAttribute(attribute)) {
formats[attribute] = domNode.getAttribute(attribute);
}
return formats;
}, {});
}

static sanitize(url) {
Expand All @@ -27,7 +34,7 @@ class Video extends BlockEmbed {
}

format(name, value) {
if (name === 'height' || name === 'width') {
if (ATTRIBUTES.indexOf(name) > -1) {
if (value) {
this.domNode.setAttribute(name, value);
} else {
Expand Down

0 comments on commit 9b819b2

Please sign in to comment.