Created
October 29, 2013 19:35
-
-
Save nelsonJM/7221109 to your computer and use it in GitHub Desktop.
js: final jn plugin
This file contains hidden or 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($){ | |
$.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