Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit 1560751

Browse files
Upload SuperEmbed 3.1
1 parent 3d7156b commit 1560751

File tree

4 files changed

+117
-30
lines changed

4 files changed

+117
-30
lines changed

README.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ I created SuperEmbed to fix all my issues with existing solutions, including (bu
1010
* Works without external libraries like JQuery
1111
* Responsive videos maintain their original aspect ratio
1212
* Responsive layout can be forced or blocked with classes applied to the embed code
13-
* Extremely tiny, the minified version is only 2 KB
13+
* Extremely tiny, the minified version is only 3 KB
1414

1515
**Supported Services**
1616

17-
Embeded videos from the following sites are supported:
17+
SuperEmbed can automatically detect and resize embedded content from these sites:
1818
* YouTube
1919
* Vimeo
20+
* SoundCloud
2021
* Kickstarter
2122
* CollegeHumor
2223
* Hulu
@@ -29,6 +30,7 @@ Embeded videos from the following sites are supported:
2930
* Facebook
3031
* Gfycat
3132
* LiveLeak
33+
* MSDN Channel 9
3234
* MySpace
3335
* Archive.org
3436

@@ -67,24 +69,8 @@ And finally, you can force a 1:1 aspect ratio by adding the `.superembed-square`
6769

6870
---------------------------------------------------------
6971

70-
__New in SuperEmbed.js 3.0:__
71-
* Improved performance and cleaner code
72-
* Added support for Facebook, Gfycat, LiveLeak, MySpace, and Archive.org embeds
73-
74-
__New in SuperEmbed.js 2.3:__
75-
* Now uses getComputedStyle to calculate width and height on supported browsers
76-
77-
__New in SuperEmbed.js 2.2:__
78-
* Fixes to avoid conflict with other libraries
79-
80-
__New in SuperEmbed.js 2.1:__
81-
* Now optionally uses JQuery for detecting page load and page resize, if JQuery is loaded before SuperEmbed
82-
83-
__New in SuperEmbed.js 2.0:__
84-
* Almost completely re-written, resizing is now handled by JS instead of CSS
85-
* Now videos maintain their original aspect ratio when resized, no more letterboxing
86-
* Minimum Internet Explorer version dropped to IE 9
87-
* The `.superembed-square` class now applies a 1:1 ratio, instead of a 4:3 ratio
72+
__New in SuperEmbed.js 3.1:__
73+
* Added support for SoundCloud and MSDN Channel 9 embeds
8874

8975
---------------------------------------------------------
9076

extra/classlist.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,67 @@ if (objCtr.defineProperty) {
240240

241241
}
242242

243+
/**
244+
* Shim for "fixing" IE's lack of support (IE < 9) for applying slice
245+
* on host objects like NamedNodeMap, NodeList, and HTMLCollection
246+
* (technically, since host objects have been implementation-dependent,
247+
* at least before ES2015, IE hasn't needed to work this way).
248+
* Also works on strings, fixes IE < 9 to allow an explicit undefined
249+
* for the 2nd argument (as in Firefox), and prevents errors when
250+
* called on other DOM objects.
251+
*/
252+
(function () {
253+
'use strict';
254+
var _slice = Array.prototype.slice;
255+
256+
try {
257+
// Can't be used with DOM elements in IE < 9
258+
_slice.call(document.documentElement);
259+
} catch (e) { // Fails in IE < 9
260+
// This will work for genuine arrays, array-like objects,
261+
// NamedNodeMap (attributes, entities, notations),
262+
// NodeList (e.g., getElementsByTagName), HTMLCollection (e.g., childNodes),
263+
// and will not fail on other DOM objects (as do DOM elements in IE < 9)
264+
Array.prototype.slice = function(begin, end) {
265+
// IE < 9 gets unhappy with an undefined end argument
266+
end = (typeof end !== 'undefined') ? end : this.length;
267+
268+
// For native Array objects, we use the native slice function
269+
if (Object.prototype.toString.call(this) === '[object Array]'){
270+
return _slice.call(this, begin, end);
271+
}
272+
273+
// For array like object we handle it ourselves.
274+
var i, cloned = [],
275+
size, len = this.length;
276+
277+
// Handle negative value for "begin"
278+
var start = begin || 0;
279+
start = (start >= 0) ? start : Math.max(0, len + start);
280+
281+
// Handle negative value for "end"
282+
var upTo = (typeof end == 'number') ? Math.min(end, len) : len;
283+
if (end < 0) {
284+
upTo = len + end;
285+
}
286+
287+
// Actual expected size of the slice
288+
size = upTo - start;
289+
290+
if (size > 0) {
291+
cloned = new Array(size);
292+
if (this.charAt) {
293+
for (i = 0; i < size; i++) {
294+
cloned[i] = this.charAt(start + i);
295+
}
296+
} else {
297+
for (i = 0; i < size; i++) {
298+
cloned[i] = this[start + i];
299+
}
300+
}
301+
}
302+
303+
return cloned;
304+
};
305+
}
306+
}());

superembed.js

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@
2727
selectors.push(start + superEmbed.services[type].join(end + ',' + start) + end);
2828
}
2929

30-
if (!(document.querySelectorAll("div") instanceof Object)) { // For IE8, because it can't handle using slice on NodeList
31-
return document.body.querySelectorAll(selectors.join(','));
32-
} else { // For other browsers
33-
// Transform NodeList object into plain array.
34-
// @see http://stackoverflow.com/a/6545450
35-
return [].slice.call(document.body.querySelectorAll(selectors.join(',')));
36-
}
30+
// Transform NodeList object into plain array.
31+
// @see http://stackoverflow.com/a/6545450
32+
return [].slice.call(document.body.querySelectorAll(selectors.join(',')));
3733
};
3834

3935
/**
@@ -71,6 +67,23 @@
7167
iframe.setAttribute('data-height', '9');
7268
}
7369

70+
// SoundCloud has two embed types, a "Visual Embed" that shows the full album art, and a "Classic Embed" that is not as tall
71+
// SuperEmbed will force the visual embed to be square, and leave alone the classic embed (besides making sure width is set to 100%)
72+
if ((iframe.getAttribute('src').indexOf('w.soundcloud.com') != -1) && (!(iframe.getAttribute('data-width')))) {
73+
// Remove existing responsive code
74+
iframe.setAttribute('width', '');
75+
iframe.setAttribute('height', '');
76+
if (iframe.getAttribute('src').indexOf('visual=true') != -1) {
77+
// Visual embed
78+
iframe.setAttribute('data-width', '1');
79+
iframe.setAttribute('data-height', '1');
80+
} else {
81+
// Classic Embed
82+
iframe.setAttribute('data-width', '10');
83+
iframe.setAttribute('data-height', '4');
84+
}
85+
}
86+
7487
// Original aspect ratio is kept in data attribute to maintain scaling.
7588
if (iframe.hasAttribute('data-width')) {
7689
width = iframe.getAttribute('data-width');
@@ -94,12 +107,35 @@
94107

95108
// Get width and height of parent container.
96109
// @see http://stackoverflow.com/a/3971875
110+
111+
if (!window.getComputedStyle) {
112+
window.getComputedStyle = function(el, pseudo) {
113+
this.el = el;
114+
this.getPropertyValue = function(prop) {
115+
var re = /(\-([a-z]){1})/g;
116+
if (prop == 'float') prop = 'styleFloat';
117+
if (re.test(prop)) {
118+
prop = prop.replace(re, function () {
119+
return arguments[2].toUpperCase();
120+
});
121+
}
122+
return el.currentStyle[prop] ? el.currentStyle[prop] : null;
123+
}
124+
return this;
125+
}
126+
}
127+
97128
if (window.getComputedStyle) {
98129
maxWidth = parseInt(window.getComputedStyle(iframe.parentElement, null).getPropertyValue('width'));
99130
maxHeight = parseInt(window.getComputedStyle(document.body, null).getPropertyValue('height'));
131+
} else if (iframe.currentStyle) {
132+
maxWidth = iframe.parentElement.clientWidth;
133+
maxHeight = document.body.clientHeight;
134+
console.log(maxWidth + ' ' + maxHeight + ', ' + iframe.currentStyle.margin);
100135
} else {
101136
maxWidth = iframe.parentElement.offsetWidth;
102137
maxHeight = document.body.clientHeight;
138+
console.log(maxWidth + ' ' + maxHeight);
103139
}
104140

105141
if (width != maxWidth) {
@@ -117,7 +153,6 @@
117153
if (needsUpdate) {
118154
iframe.setAttribute('width', maxWidth);
119155
iframe.setAttribute('height', maxHeight);
120-
121156
// Reset width and height to match scaled video.
122157
width *= ratio;
123158
height *= ratio;
@@ -145,7 +180,9 @@
145180
'gfycat.com/ifr/',
146181
'liveleak.com/ll_embed',
147182
'media.myspace.com',
148-
'archive.org/embed'
183+
'archive.org/embed',
184+
'w.soundcloud.com/player',
185+
'channel9.msdn.com'
149186
],
150187
// object[data*="//www.flickr.com/apps/video"]
151188
object: [

superembed.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)