Giter Site home page Giter Site logo

nprapps / pym.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from npr/responsiveiframe

804.0 69.0 113.0 1.67 MB

Resize an iframe responsively depending on the height of its content and the width of its container.

Home Page: http://blog.apps.npr.org/pym.js/

License: MIT License

JavaScript 86.74% HTML 11.56% Python 1.70%

pym.js's Issues

Handle iframes created by external javascript

Hi,

The way I understand Pym from looking at its documentation, it currently needs a child HTML URL as a parameter of pym.Parent. What about iframes created by inserting a piece of 3rd-party javascript, is this going to be within the scope of your library? It sounds like a lot of extra work to create chunks of HTML in the CMS to host just the javascript embeds to be inserted in actual entries.

For context about my use case, I'm looking for something akin to FitVids or Fluidvids to make Tableau embeds responsive.

"autoinit" feature

My use-case for pym.js is similar to the motivating example in the project website (embedding an iframe in a CMS document), but I have an additional restriction: the CMS actively scrubs in-line JavaScript. I would like to instruct pym.js to automatically instantiate a parent connection on iframes that opt-in to the functionality. For instance:

<!-- opt in to the "auto initialization" functionality with an HTML5 `data-` attribute -->
<script src="pym.js" data-pym-autoinit="autoinit-target-class"></script>

<div class="autoinit-target-class" data-pym-src="http://example.com/some/child.html"></div>
<!-- optionally specify an `domain` regex: -->
<div class="autoinit-target-class" data-pym-src="http://example.com/some/child.html" data-pym-xdomain="\.npr\.org"></div>

I would be happy to draw up a draft implementation (I'm actively pursuing this in a fork), but I'm interested in gauging interest from the maintainers before submitting a pull request. What do you think?

IE11 compatibility

Since upgrading to the latest version of Pym, we've been getting reports that it's not resizing on load from IE11 users. We haven't been able to reproduce it just yet, but I'm wondering if anyone else has seen this issue.

hash in child_url breaks the params

If I need to load the frame as frame.html#foo, the iframe src will be frame.html#foo?initialWidth=970&childId=frame, it should be frame.html?initialWidth=970&childId=frame#foo

Browser testing

Make sure everything still works the way we expect in all the browsers we support.

Multiple responsive iframes not getting height value till resize

I'm using pym.js to display multiple iframes on a single page, each iframe is contained on a different tab of a javascript tab table (http://publicsource.org/pittsburgh-crime-statistics-2010-2013).

I'm running into issues on Firefox and Internet Explorer where the iframes on tabs 2 and 3 are not receiving a height until the iframe page is manually resized. Not working at all on Internet Explorer.

I'm pretty sure the issues is with how/where I'm calling the pym.js, but I was hoping you could give me a bit of help on this. Using Drupal 7.

Best,
A

Use JSON to pass messages instead of plaintext?

In attempting to utilize Pym with another library, I encountered a situation in which the other library was listening to message events, expecting JSON, and blindly passing the message through JSON.parse(). This 3rd-party would be better served by filtering messages from domains that it cared about instead of everybody and their siblings, and I've filed a bug with that author appropriately.

However, it made me aware of the message format that Pym was using for communication: responsive(parent|child) [id] [height]. Have you considered using JSON instead? This would have the advantage of utilizing JSON.parse() instead of regex parsing and make the communication a little more readable. Just a thought, and I'm happy to send a PR.

Scrollbar quirk in OS X: Inaccurate width calculated on initial load

Found an interesting quirk re: scrollbars in OS X and calculating browser width.

If the content on the page is super-short before the iframe loads (and therefore the page has no scrollbar initially), and you have one of these OS X scrollbar settings set:

image
image

Pym will calculate the width of the browser and without taking into account the width of the scrollbar. So, on initial load, a graphic might be drawn about 15px too wide (but will fix itself onresize).

To replicate, on a Mac, go to System Preferences > General and try one of the two settings above. Then test this URL:

http://apps.npr.org/dailygraphics/graphics/salt-yeast-alcohol-alastair/

When it's misbehaving, the "4" at the end of the x-axis gets cut off / does not appear.

Noted in OS X 10.9.3 in Chrome and Firefox. (Didn't check Safari.)

(Thanks to @dannydb for helping to identify what was causing the problem.)

Shouldn't use HTML tags to select iframe containers

Because that means they all have to be on the page when I run it. And if I run it again now I've initialized them twice. I don't think I would care about this if it was just for us, but a library should be more flexible.

Suggested pattern:

window.responsiveParent('#embed1', {});
window.responsiveParent('#embed2', {});

Link clicking inside <iframe>, explicitly setting child id

I have an <iframe> where normal click-the-link navigation and post-the-form page loading is possible. The child JavaScript re-initializes the Pym messaging on window.load after the page has been reloaded. I am not sure if this is a very common use case or should it have worked out of the box.

The site: http://libertymusicstore.net/

I had to make some changes to Pym to make this work, so that the page inside the iframe can message the parent after clicking the link. Link becomes <iframe src> and because this src doesn't contain Pym-specific query parameters given on the initial Pym embed when parent creates the iframe, the id token needed for postMessage() communication is lost.

When the child in initialized it explicitly gives the id in JavaScript:

/**
* Handle <iframe> embed and signalling with the parent frame.
*/
function initEmbed() {
    pymChild = new pym.Child({id: "store-embed-iframe-wrapper"});

    $(window).load(function() {      
        pymChild.sendHeightToParent();
    });
}

And then Pym can pick this id up from from the settings, instead of link URL

    // Identify what ID the parent knows this child as.
    // Also accept id from the child contruction parameters,
    // so that you can keep sending message to the parent with specific
    // after iframe page loads
    this.id = this.getParameterByName('childId') || this.settings.id; 

If you are interested in pull request, I can create one, now the code lives only here:

https://github.com/miohtama/LibertyMusicStore/blob/master/tatianastore/static/pym.js#L230

body with height: 100% doesn't work with sendHeight()

Child documents which have height: 100% set on their body (which many .css reset libraries do), accessing the document height with:

 document.getElementsByTagName('body')[0].offsetHeight.toString();

will return the initial height of the iframe regardless of additional calls to sendHeight().

A more robust height calculation might be:

var body = document.body,
  html = document.documentElement;

var height = Math.max( body.scrollHeight, body.offsetHeight,
          html.clientHeight, html.scrollHeight, html.offsetHeight );

as referenced here: http://stackoverflow.com/questions/1145850/how-to-get-height-of-entire-document-with-javascript.

I'm not sure that this would cause an issue to existing height calculations, but I'd be happy to go ahead and create a pull request if you guys think that this approach is good.

Jump/anchor links within the iframe don't work on iOS

Use case: A table with information specific to each state โ€” something like this early voting project from 2012:

image

And, when the table is iframed in, it makes total sense that it wouldn't work. But maybe it's not terribly painful to figure out? Initial thought: Get the y-position of the iframe on the parent page and the y-position of the anchor on the child page, and then jump to (iframe-y + anchor-y) on the parent page.

renderCallback arguments

The README might want to specify that renderCallback is passed the new width of the parent. Sort of obvious, but had to go through source to verify.

This is a life changer.

sendMessage documentation is inaccurate

Specifically, this line:

pymParent.sendMessageToChild('navigate', e.target.href);

Looks like we need to update to reflect the pymParent.sendMessage() in the current release and maybe also provide an example using pymChild.sendMessage().

Capture status from the child page inside iframe

Hello,

I am trying to capture error status from a child page that I am loading from pym. When the child page detects invalid user, it will return status 401 on the header and I want to be able to get that status and redirect the user to the parent site's login page.

How can I get this status code from the child page?

Thanks,
Suriyanto

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.