Skip to content

Instantly share code, notes, and snippets.

@nelsonJM
Created October 29, 2013 19:35
Show Gist options
  • Save nelsonJM/7221109 to your computer and use it in GitHub Desktop.
Save nelsonJM/7221109 to your computer and use it in GitHub Desktop.
js: final jn plugin
(function($){
$.fn.printy = function(options) {
settings = $.extend({
limit : 15
}, options);
return this.each(function() {
var $this = $(this);
var str = $(this).html();
var beforePrint = function() {
if(settings.limit) {
console.log(str.substr(0, settings.limit) + "...");
var newStr = str.substr(0, settings.limit) + "...";
$this.html(newStr);
}
};
var afterPrint = function() {
if(settings.limit) {
$this.html(str);
}
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment