Skip to content

Commit

Permalink
loadAdScript: added document.writeln support
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboy committed Aug 12, 2010
1 parent 7d5867c commit f3e6b8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions jquery.ba-loadadscript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jQuery loadAdScript - v1.0 - 3/2/2010
* jQuery loadAdScript - v1.1 - 7/12/2010
* http://benalman.com/projects/jquery-misc-plugins/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
Expand All @@ -13,6 +13,7 @@
// A few references.
var doc = document,
write = doc.write,
writeln = doc.writeln,

// Create queue.
q = $.jqmq({
Expand All @@ -23,8 +24,9 @@
// For each queue item, do this.
callback: function( item ) {

// Override document.write.
doc.write = function( html ) {
// Override document.write and .writeln. Do we care that .writeln
// should append a newline character? Probably not.
doc.write = doc.writeln = function( html ) {
item.elems.append( html );
};

Expand All @@ -39,9 +41,10 @@
});
},

// When the queue completes, set document.write back.
// When the queue completes, set document.write and .writeln back.
complete: function(){
doc.write = write;
doc.writeln = writeln;
}
});

Expand Down
4 changes: 2 additions & 2 deletions jquery.ba-loadadscript.min.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* jQuery loadAdScript - v1.0 - 3/2/2010
* jQuery loadAdScript - v1.1 - 7/12/2010
* http://benalman.com/projects/jquery-misc-plugins/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){var c=document,a=c.write,b=$.jqmq({delay:-1,callback:function(d){c.write=function(e){d.elems.append(e)};$.getScript(d.url,function(){d.callback&&d.callback.call(d.elems);b.next()})},complete:function(){c.write=a}});$.fn.loadAdScript=function(d,e){b.add({elems:this,url:d,callback:e});return this}})(jQuery);
(function($){var c=document,a=c.write,d=c.writeln,b=$.jqmq({delay:-1,callback:function(e){c.write=c.writeln=function(f){e.elems.append(f)};$.getScript(e.url,function(){e.callback&&e.callback.call(e.elems);b.next()})},complete:function(){c.write=a;c.writeln=d}});$.fn.loadAdScript=function(e,f){b.add({elems:this,url:e,callback:f});return this}})(jQuery);

0 comments on commit f3e6b8e

Please sign in to comment.