Skip to content

Instantly share code, notes, and snippets.

@chriscoyier
Created April 20, 2017 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriscoyier/b3c576387285984c53554f0d50858833 to your computer and use it in GitHub Desktop.
Save chriscoyier/b3c576387285984c53554f0d50858833 to your computer and use it in GitHub Desktop.
// Fires when __CodePenIFrameAddedToPage() fires.
makeCodePenEmbedsResizeable: function() {
if (window.innerWidth > 625) {
var maxWidth = 1000; // calculated below
var minWidth = 320;
var minHeight = 150;
$(".cp_embed_wrapper").each(function() {
var $wrapper = $(this);
var $iframe = $wrapper.find("iframe");
$wrapper.append("<div class='win-size-grip'></div>");
var originalHeight = $iframe.outerHeight();
$wrapper.css("height", originalHeight);
// Can't set this in CSS, otherwise height measurement will be wrong
$iframe.css("height", "100%");
$wrapper.resizable({
handleSelector: "> .win-size-grip",
onDragStart: function (e, $el, opt) {
$el.addClass("dragging");
maxWidth = $(".article-content").width();
if ($(".page-wrap").width() > $(".article-content").outerWidth()) {
maxWidth += ($(".page-wrap").width() - $(".article-content").outerWidth());
}
},
onDragEnd: function (e, $el, opt) {
$el.removeClass("dragging");
},
onDrag: function (e, $el, newWidth, newHeight, opt) {
if (newWidth > maxWidth) {
newWidth = maxWidth;
}
if (newWidth < minWidth) {
newWidth = minWidth;
}
if (newHeight < minHeight) {
newHeight = minHeight;
}
$el.width(newWidth);
$el.height(newHeight);
return false;
}
});
});
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment