Last active
March 2, 2016 21:30
-
-
Save bbrown/49037176976e5d8cad11 to your computer and use it in GitHub Desktop.
Angular directive that sets the page's orientation to landscape for printing
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
angular.module("app").directive("setPrintToLandscape", function($document) | |
{ | |
return { | |
restrict: "AE", | |
link: function link(scope) | |
{ | |
// Currently only supported in Chrome. | |
// FF - https://bugzilla.mozilla.org/show_bug.cgi?id=851441 | |
// Safari - https://bugs.webkit.org/show_bug.cgi?id=63575 | |
var newSheet = angular.element("<style/>").attr({ "type":"text/css", "media":"print" }); | |
newSheet[0].appendChild(document.createTextNode("")); | |
$document.find("head").append(newSheet); | |
newSheet[0].sheet.insertRule("@page { size:landscape }", 0); | |
scope.$on("$destroy", function() | |
{ | |
newSheet.remove(); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment