Created
May 16, 2011 13:00
-
-
Save olamedia/974401 to your computer and use it in GitHub Desktop.
core.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window, undefined) { | |
var document = window.document, $ = window.jQuery; | |
var iframe = function(element) { | |
console.log('make jquery iframe element'); | |
var iframe = $('<iframe frameborder=1 style="border: solid 1px #f00;" width="800" height="400"></iframe>'); | |
console.log('append iframe to body'); | |
$(element).after(iframe); | |
//$(element).hide(); | |
// $("body").append(iframe); | |
return iframe; | |
} | |
/*var designMode = function(element) { | |
try { | |
element.designMode = "on"; | |
} catch (e) { | |
} | |
if ("on" === element.designMode) { | |
return true; | |
} | |
return false; | |
}*/ | |
/*$.fn.designMode = function() { | |
console.log('design mode'); | |
return designMode(this); | |
};*/ | |
$.fn.iframe = function() { | |
console.log('make iframe'); | |
return iframe(this); | |
}; | |
// focus = $.fn.focus; | |
$.fn.getDocument = function() { | |
var e = this.get(0); | |
if (e.nodeName.toLowerCase() === 'iframe') { | |
console.log('contentWindow document'); | |
return e.contentWindow.document; | |
} | |
console.log('default document'); | |
return document; | |
} | |
$.fn.viewSource = function(){ | |
var e = this.get(0); | |
var body = $(e); | |
if (e.nodeName.toLowerCase() === 'iframe') { | |
body = $(body.getDocument()).find('body'); | |
} | |
body.text(body.html()); | |
return this; | |
} | |
$.fn.viewHtml = function(){ | |
var e = this.get(0); | |
var body = $(e); | |
if (e.nodeName.toLowerCase() === 'iframe') { | |
body = $(body.getDocument()).find('body'); | |
} | |
body.html(body.text()); | |
return this; | |
} | |
$.fn.print = function(){ | |
this.getWindow().print(); | |
} | |
$.fn.getWindow = function() { | |
console.log(this); | |
var e = this.get(0); | |
if (e.nodeName.toLowerCase() === 'iframe') { | |
return e.contentWindow; | |
} | |
return window; | |
} | |
}(window)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
$(function(){ | |
var iframe = $("#content").iframe(); | |
var idoc = iframe.getDocument(); | |
$(idoc).find('body').html($("#content").html()); | |
idoc.designMode = "on"; | |
var idoc = iframe.getDocument(); | |
iframe.viewSource(); | |
iframe.viewHtml(); | |
$(iframe.getWindow()).focus(); | |
}); | |
</script> |
Author
olamedia
commented
May 16, 2011
<script type="text/javascript">
$(function(){
var iframe = $("#content").iframe();
var idoc = iframe.getDocument();
$(idoc).find('body').html($("#content").html());
idoc.designMode = "on";
var idoc = iframe.getDocument();
$(iframe.getWindow()).focus();
});
</script>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment