Permalink
Browse files

Updated to use contents, and fixed Firefox issue

  • Loading branch information...
1 parent cabfd7b commit b480eda7a3dc9624763e98c24a6f842fe9a333c4 @JeffreyWay JeffreyWay committed Nov 21, 2011
Showing with 28 additions and 25 deletions.
  1. +28 −25 iframe.html
View
@@ -12,41 +12,44 @@
<textarea id="html"></textarea>
<h2>CSS</h2>
- <textarea name="" id="css"></textarea>
+ <textarea id="css"></textarea>
</form>
</div>
-<div class="output grid"></div>
-
+<div class="output grid">
+ <iframe></iframe>
+</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
+<script src="http://localhost:35729/livereload.js"></script>
+
<script>
-$(function() {
- // equal-height columns.
- $('.grid').css('height', $(window).height());
-
- var $frame = $('<iframe></iframe>').appendTo('.output'),
- doc = $frame[0].contentWindow.document,
- body = $('body', doc),
- styleTag = $('head', doc).append('<style></style>').children('style');
-
- $('textarea').focus(function() {
- var $this = $(this);
-
- $this.keyup(function() {
- if ($this.attr('id') === 'html') {
- body.html( $this.val() );
- } else {
- // CSS was added
- styleTag.text( $this.val() );
- }
- });
+(function() {
+ $('.grid').height( $(window).height());
+
+ var frame = $('iframe'),
+ // frame[0].contentWindow.document
+ body = frame.contents().find('body');
+ styleTag = frame.contents().find('head').append('<style></style>').children('style');
+
+ $('textarea').focus(function() {
+ console.log('focused');
+ var $this = $(this);
+
+ $this.keyup(function() {
+ if ( $this.attr('id') === 'html' ) {
+ body.html( $this.val() );
+ } else {
+ // css
+ styleTag.text( $this.val() );
+ }
});
-
-});
+ });
+
+})();
</script>

0 comments on commit b480eda

Please sign in to comment.