From 7149d714eac46ca4562ba854848271badb89deab Mon Sep 17 00:00:00 2001 From: John Nguyen Date: Sun, 11 Dec 2016 15:57:26 -0800 Subject: [PATCH 1/6] Separate CSS attrs and tag attrs for iframe --- src/featherlight.js | 50 +++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/src/featherlight.js b/src/featherlight.js index a48eff80..ebc511a2 100644 --- a/src/featherlight.js +++ b/src/featherlight.js @@ -54,21 +54,44 @@ return opened; }; - // structure({iframeMinHeight: 44, foo: 0}, 'iframe') - // #=> {min-height: 44} - var structure = function(obj, prefix) { - var result = {}, - regex = new RegExp('^' + prefix + '([A-Z])(.*)'); - for (var key in obj) { - var match = key.match(regex); - if (match) { - var dasherized = (match[1] + match[2].replace(/([A-Z])/g, '-$1')).toLowerCase(); - result[dasherized] = obj[key]; - } + var iframeStructure = { + // iframeStructure.css({iframeMinHeight: 44, foo: 0}, 'iframe') => {min-height: 44} + css: function(obj) { + return parseAttrs(obj, 'iframe'); + }, + // NOTE: List of available [iframe attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe). + attr: function(obj) { + var whiteList = ['allowfullscreen', 'frameborder', 'height', 'longdesc', + 'marginheight', 'marginwidth', 'name', 'referrerpolicy', 'scrolling', + 'sandbox', 'src', 'srcdoc', 'width'], + attrs = {}; + + whiteList.map(function(item) { + var attrValue = parseAttrs(obj, 'iframe')[item]; + + if (attrValue) { + attrs[item] = attrValue; + return attrs[item]; + } + }); + + return attrs; } - return result; }; +function parseAttrs(obj, prefix) { + var attrs = {}, + regex = new RegExp('^' + prefix + '([A-Z])(.*)'); + for (var key in obj) { + var match = key.match(regex); + if (match) { + var dasherized = (match[1] + match[2].replace(/([A-Z])/g, '-$1')).toLowerCase(); + attrs[dasherized] = obj[key]; + } + } + return attrs; +} + /* document wide key handler */ var eventMap = { keyup: 'onKeyUp', resize: 'onResize' }; @@ -384,7 +407,8 @@ var $content = $(' - @@ -155,8 +156,6 @@

Featherlight with custom styles

- -