From 9c9471fea2d87dac16f962f12226c4e264fad703 Mon Sep 17 00:00:00 2001 From: Mottie Date: Fri, 21 Aug 2015 22:34:34 -0500 Subject: Save each replaced background image for undo method --- js/printliminator.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/js/printliminator.js b/js/printliminator.js index 4cb5650..a58ad18 100644 --- a/js/printliminator.js +++ b/js/printliminator.js @@ -96,13 +96,29 @@ function csstricksPrintliminator( jQ ) { // Remove Graphics $( '
' ) .click( function() { - var done = $('img,iframe,object,embed,input[type=image],ins').addClass( '_print_removed' ), - bg = $('body *:not(._print_controls, ._print_controls *)').css('background'), - item = $('body *:not(._print_controls, ._print_controls *)').css('background', 'none'); - done.addClass("_print_removed"); - history.push(function() { - done.show(); - item.css('background', bg); + var indx, $el, bkgd, + bkgds = [], + $done = $( 'img, iframe, object, embed, input[type=image], ins' ), + $item = $( 'body *:not(._print_controls, ._print_controls *)' ), + len = $item.length; + for ( indx = 0; indx < len; indx++ ) { + $el = $item.eq( indx ); + bkgd = $el.css( 'background-image' ); + if ( bkgd !== 'none' ) { + bkgds.push( [ $el, bkgd ] ); + $el.css( 'background-image', 'none' ); + } + } + $done.addClass( '_print_removed' ); + + history.push( function() { + $done.removeClass( '_print_removed' ); + var $el, + len = bkgds.length; + for ( indx = 0; indx < len; indx++ ) { + $el = bkgds[ indx ][ 0 ]; + $el.css( 'background-image', bkgds[ indx ][ 1 ] ); + } }); }) .appendTo( $controls ); -- cgit v1.2.3