Skip to content

Instantly share code, notes, and snippets.

@ckknight
Forked from NeilHanlon/inhouse.js
Last active December 18, 2015 22:38

Revisions

  1. ckknight revised this gist Jun 25, 2013. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions inhouse.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,14 @@
    (function(){
    var oldPrint = window.print;
    var slice = Array.prototype.slice;

    window.print = function () {
    if (typeof window.onbeforeprint === "function") {
    window.onbeforeprint.apply(this, arguments);
    window.onbeforeprint.apply(this, slice.call(arguments));
    }
    oldPrint.apply(this, arguments);
    oldPrint.apply(this, slice.call(arguments));
    if (typeof window.onafterprint === "function") {
    window.onafterprint.apply(this, arguments);
    window.onafterprint.apply(this, slice.call(arguments));
    }
    };
    }());
  2. ckknight revised this gist Jun 25, 2013. 1 changed file with 10 additions and 13 deletions.
    23 changes: 10 additions & 13 deletions inhouse.js
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,13 @@
    (function(){
    var oldPrint = window.print;

    // make a copy of the native window.print
    var _print = this.print;

    // create a new window.print
    window.print = function (window) {
    // if `onbeforeprint` exists, call it.
    if(this.onbeforeprint) onbeforeprint(this);
    // call the original `window.print`.
    _print.apply(this);
    // if `onafterprint` exists, call it.
    if (this.onafterprint) onafterprint(this);
    }

    window.print = function () {
    if (typeof window.onbeforeprint === "function") {
    window.onbeforeprint.apply(this, arguments);
    }
    oldPrint.apply(this, arguments);
    if (typeof window.onafterprint === "function") {
    window.onafterprint.apply(this, arguments);
    }
    };
    }());
  3. @NeilHanlon NeilHanlon revised this gist Jun 25, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions inhouse.js
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,11 @@
    var _print = this.print;

    // create a new window.print
    window.print = function () {
    window.print = function (window) {
    // if `onbeforeprint` exists, call it.
    if (this.onbeforeprint) onbeforeprint(this);
    if(this.onbeforeprint) onbeforeprint(this);
    // call the original `window.print`.
    _print();
    _print.apply(this);
    // if `onafterprint` exists, call it.
    if (this.onafterprint) onafterprint(this);
    }
  4. @NeilHanlon NeilHanlon created this gist Jun 25, 2013.
    16 changes: 16 additions & 0 deletions inhouse.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    (function(){

    // make a copy of the native window.print
    var _print = this.print;

    // create a new window.print
    window.print = function () {
    // if `onbeforeprint` exists, call it.
    if (this.onbeforeprint) onbeforeprint(this);
    // call the original `window.print`.
    _print();
    // if `onafterprint` exists, call it.
    if (this.onafterprint) onafterprint(this);
    }

    }());