Permalink
Browse files

Refactored JS

  • Loading branch information...
JeffreyWay committed Nov 21, 2011
1 parent b480eda commit fb873bcf4f36582c128df4bfa691c1ae8d543b0e
Showing with 20 additions and 13 deletions.
  1. +20 −13 iframe.html
View
@@ -20,39 +20,46 @@ <h2>CSS</h2>
<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() {
- $('.grid').height( $(window).height());
+ $('.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');
+ var contents = $('iframe').contents(),
+ body = contents.find('body'),
+ styleTag = 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' ) {
+ if ( $this.attr('id') === 'html') {
body.html( $this.val() );
} else {
- // css
+ // it had to be css
styleTag.text( $this.val() );
}
});
});
-
+
})();
-
</script>
</body>
-</html>
+</html>
+
+
+
+
+
+
+
+
+

0 comments on commit fb873bc

Please sign in to comment.