{"id":113,"date":"2012-03-06T11:19:10","date_gmt":"2012-03-06T11:19:10","guid":{"rendered":"http:\/\/www.w3.org\/community\/respimg\/?p=113"},"modified":"2012-03-09T18:21:42","modified_gmt":"2012-03-09T18:21:42","slug":"js-implementation-problem-with","status":"publish","type":"post","link":"https:\/\/www.w3.org\/community\/respimg\/2012\/03\/06\/js-implementation-problem-with\/","title":{"rendered":"JS implementation \/ Problem with the source element"},"content":{"rendered":"<p>I&#8217;ve been working on a JS implementation of the picture tag. It is important that a JS implementation is possible &#8211; if a JS implementation isn&#8217;t possible on older\/current browsers, then these older\/current browsers will display the mobile sized image.<\/p>\n<p>Chrome, FF and Opera came together very quickly, as ever though IE7\/8 is slightly more challenging, but the real stumbling block is IE9.<\/p>\n<p>The picture tag version I&#8217;ve been working on implementing is [3] in the etherpad<\/p>\n<p>&lt;picture&gt;<br \/>\n&lt;source \/&gt;<br \/>\n&lt;source \/&gt;<br \/>\n&lt;img&gt;<br \/>\n&lt;\/picture&gt;<\/p>\n<p>Approach One: In non-IE Jquery allows us to select the Elements. This makes life very easy, we can just select the picture elements, loop over the source elements and regex the contents of the media attribute:<\/p>\n<p>http:\/\/jsfiddle.net\/7555C\/4\/<\/p>\n<p>Approach Two: In IE7\/8 it gets a little more tricky as we can&#8217;t directly select the picture element. We can however select the image element, and then get it&#8217;s parent, and then get it&#8217;s parents inner html, and then regex the required information out of it:<\/p>\n<p>http:\/\/jsfiddle.net\/BKAWp\/6\/<\/p>\n<p>Neither of these approaches will work in IE9 though. In IE9 we still can&#8217;t select the picture tag, and the source elements actually get removed from the html. (I&#8217;m assumming this is because they are recognized as elements, which are invalid in that location). If we have no way of accessing the information in the source element then we can&#8217;t use that syntax.<\/p>\n<p>However there is one simple work around:<\/p>\n<p>&lt;picture&gt;<br \/>\n&lt;pic-source \/&gt;<br \/>\n&lt;pic-source \/&gt;<br \/>\n&lt;img&gt;<br \/>\n&lt;\/picture&gt;<\/p>\n<p>Because IE9 doesn&#8217;t recognize pic-source it doesn&#8217;t remove it from the html, and then we can use approach two:<\/p>\n<p>http:\/\/jsfiddle.net\/rerGC\/17\/<\/p>\n<p>There are also a couple of other differences, IE9 doesn&#8217;t like &lt;pic-source \/&gt;, and needs &lt;pic-source&gt;&lt;\/pic-source&gt;, else it places the img in the pic-source element. Also IE7\/8 return the inner html in part upper, part lower case, IE9 returns it all in lower case.<\/p>\n<p>(I&#8217;m not particularly attached to &lt;pic-source \/&gt;, it just needs to be different from &lt;source \/&gt; so IE9 doesn&#8217;t strip it out)<\/p>\n<p>Please don&#8217;t view the code in fiddle as finished, it needs to be combined into one place, and further performance tweaks need to be looked at, however it will provide a proof of concept, and more importantly show the syntax we&#8217;re proposing is usable on older\/current browsers.<\/p>\n<p>Chris.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working on a JS implementation of the picture tag. It is important that a JS implementation is possible &#8211; if a JS implementation isn&#8217;t possible on older\/current browsers, then these older\/current browsers will display the mobile sized image. &hellip; <a href=\"https:\/\/www.w3.org\/community\/respimg\/2012\/03\/06\/js-implementation-problem-with\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1563,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"yes","footnotes":""},"categories":[1],"tags":[],"class_list":["post-113","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.w3.org\/community\/respimg\/wp-json\/wp\/v2\/posts\/113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.w3.org\/community\/respimg\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.w3.org\/community\/respimg\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.w3.org\/community\/respimg\/wp-json\/wp\/v2\/users\/1563"}],"replies":[{"embeddable":true,"href":"https:\/\/www.w3.org\/community\/respimg\/wp-json\/wp\/v2\/comments?post=113"}],"version-history":[{"count":16,"href":"https:\/\/www.w3.org\/community\/respimg\/wp-json\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":129,"href":"https:\/\/www.w3.org\/community\/respimg\/wp-json\/wp\/v2\/posts\/113\/revisions\/129"}],"wp:attachment":[{"href":"https:\/\/www.w3.org\/community\/respimg\/wp-json\/wp\/v2\/media?parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.w3.org\/community\/respimg\/wp-json\/wp\/v2\/categories?post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.w3.org\/community\/respimg\/wp-json\/wp\/v2\/tags?post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}