Talk:CSS Independent Content: Difference between revisions
From GreaseSpot Wiki
Jump to navigationJump to search
→ihp bbt: new section |
m Reverted edits by 80.67.13.96 (Talk) to last revision by Arantius |
||
Line 48: | Line 48: | ||
::and similar, here assuming the UI is an unordered list with two items, rendered from properties of an "items" array. Constructing more advanced UI:s is of course readily doable by setting up an e4x variable you craft mixing code and e4x literals any way you want prior to serializing the e4x variable to XML for the data URL, and adding event handlers works well by stuffing id:s to the nodes you want and fetching them in the load callback via doc.getElementById. Overall a great suggestion, IMO; feel free to improve this even further. | ::and similar, here assuming the UI is an unordered list with two items, rendered from properties of an "items" array. Constructing more advanced UI:s is of course readily doable by setting up an e4x variable you craft mixing code and e4x literals any way you want prior to serializing the e4x variable to XML for the data URL, and adding event handlers works well by stuffing id:s to the nodes you want and fetching them in the load callback via doc.getElementById. Overall a great suggestion, IMO; feel free to improve this even further. | ||
--[[User:Ecmanaut|Ecmanaut]] 19:50, 15 June 2007 (EDT) | --[[User:Ecmanaut|Ecmanaut]] 19:50, 15 June 2007 (EDT) | ||
Revision as of 13:42, 19 December 2010
This might be more suitable in Code snippets?
- I agree. --Henrik 05:47, 5 June 2007 (EDT)
sometimes its blank
Hi, I have a problem with this. It could be that I do something wrong. However: about 1 out of 5 times the content stays blank. I tried to change the timeout to 1000. I tested it 20 times, and it worked all the time.
Isn't there a "domIsNowCreatedAndYouCanGoAhead" event that we can listen to instead of using setTimeout?
Yes: DOMContentLoaded 20:30, 15 June 2007 (EDT)
How about this instead?
It seems it works better
function $(id) {return document.getElementById(id)}; var iframe = document.createElement("iframe"); iframe.setAttribute("id", "settings"); iframe.setAttribute("style", "display:block;z-index:1002;position:fixed;overflow:auto;left:30px;top:30px;right:30px;bottom:30px;background-color:white;padding:15px;border:1px solid black"); iframe.addEventListener('load', showSettings2, false); function showSettings2() { $('LIU_settings').contentDocument.body.innerHTML = '<html><body>test</body></html>'; }
Data URI
Isn't this a prime time to use a data URI?
iframe.src = 'data:text/html;charset=utf-8,'+escape('<html><body>...</body><html>');
Thus avoid all the issues with the DOM rendering and having to wait for load?
- I don't think so. Just working with the iframe contents as a string would probably get frustrating. The
load
event happens pretty quickly since we're just waiting forabout:blank
to load, with no external resources, and once we're there, we can work with that DOM any way we please. Suppose you could mention it in the article as an option, but I don't really see the point. --Henrik 04:37, 7 June 2007 (EDT)
- Actually a rather good idea, IMO, with a few tweaks to the suggestion. The case when it's useful to do node by node creation is when you need to attach event handlers on your own for things, but when you don't, it's a lot easier just writing the markup, rather than coding to the DOM API (even if it was somewhat less bothersome with the tools I quoted in the initial revision). I think this is what you want to do:
iframe.addEventListener("load", function() { ... }); iframe.src = "data:text/html;charset=utf-8,"+(<body> <ul> <li><a href={items[0].url}>{items[0].title}</a></li> <li><a href={items[1].url}>{items[1].title}</a></li> </ul> </body>).toXMLString(); document.body.appendChild(iframe);
- and similar, here assuming the UI is an unordered list with two items, rendered from properties of an "items" array. Constructing more advanced UI:s is of course readily doable by setting up an e4x variable you craft mixing code and e4x literals any way you want prior to serializing the e4x variable to XML for the data URL, and adding event handlers works well by stuffing id:s to the nodes you want and fetching them in the load callback via doc.getElementById. Overall a great suggestion, IMO; feel free to improve this even further.
--Ecmanaut 19:50, 15 June 2007 (EDT)