PageSourceSearch

https://seogu.go.kr/pcms/common/pluigs/print/jQuery.print.min.js

js seogu.go.kr collected 2026-10-02 20:17:24 UTC 11,180 bytes, 278 lines download raw bytes

vendor: 11,180 bytes, lines 1-278
1/* @license 
2 * jQuery.print, version 1.6.0
3 *  (c) Sathvik Ponangi, Doers' Guild
4 * Licence: CC-By (http://creativecommons.org/licenses/by/3.0/)
5 *--------------------------------------------------------------------------*/
6(function ($) {
7    "use strict";
8    // A nice closure for our definitions
9
10    function jQueryCloneWithSelectAndTextAreaValues(elmToClone, withDataAndEvents, deepWithDataAndEvents) {
11        // Replacement jQuery clone that also clones the values in selects and textareas as jQuery doesn't for performance reasons - https://stackoverflow.com/questions/742810/clone-isnt-cloning-select-values
12        // Based on https://github.com/spencertipping/jquery.fix.clone
13        var $elmToClone = $(elmToClone),
14            $result           = $elmToClone.clone(withDataAndEvents, deepWithDataAndEvents),
15            $my_textareas     = $elmToClone.find('textarea').add($elmToClone.filter('textarea')),
16            $result_textareas = $result.find('textarea').add($result.filter('textarea')),
17            $my_selects       = $elmToClone.find('select').add($elmToClone.filter('select')),
18            $result_selects   = $result.find('select').add($result.filter('select'));
19
20        for (var i = 0, l = $my_textareas.length; i < l; ++i) {
21            $($result_textareas[i]).val($($my_textareas[i]).val());
22        }
23        for (var i = 0, l = $my_selects.length;   i < l; ++i) {
24            for (var j = 0, m = $my_selects[i].options.length; j < m; ++j) {
25                if ($my_selects[i].options[j].selected === true) {
26                    $result_selects[i].options[j].selected = true;
27                }
28            }
29        }
30        return $result;
31    }
32
33    function getjQueryObject(string) {
34        // Make string a vaild jQuery thing
35        var jqObj = $("");
36        try {
37            jqObj = jQueryCloneWithSelectAndTextAreaValues(string);
38        } catch (e) {
39            jqObj = $("<span />")
40                .html(string);
41        }
42        return jqObj;
43    }
44
45    function printFrame(frameWindow, content, options) {
46        // Print the selected window/iframe
47        var def = $.Deferred();
48        try {
49            frameWindow = frameWindow.contentWindow || frameWindow.contentDocument || frameWindow;
50            var wdoc = frameWindow.document || frameWindow.contentDocument || frameWindow;
51            if(options.doctype) {
52                wdoc.write(options.doctype);
53            }
54            wdoc.write(content);
55            wdoc.close();
56            var printed = false;
57            var callPrint = function () {
58                if(printed) {
59                    return;
60                }
61                // Fix for IE : Allow it to render the iframe
62                frameWindow.focus();
63                try {
64                    // Fix for IE11 - printng the whole page instead of the iframe content
65                    if (!frameWindow.document.execCommand('print', false, null)) {
66                        // document.execCommand returns false if it failed -http://stackoverflow.com/a/21336448/937891
67                        frameWindow.print();
68                    }
69                    // focus body as it is losing focus in iPad and content not getting printed
70                    $('body').focus();
71                } catch (e) {
72                    frameWindow.print();
73                }
74                frameWindow.close();
75                printed = true;
76                def.resolve();
77            }
78            // Print once the frame window loads - seems to work for the new-window option but unreliable for the iframe
79            $(frameWindow).on("load", callPrint);
80            // Fallback to printing directly if the frame doesn't fire the load event for whatever reason
81            setTimeout(callPrint, options.timeout);
82        } catch (err) {
83            def.reject(err);
84        }
85        return def;
86    }
87
88    function printContentInIFrame(content, options) {
89        var $iframe = $(options.iframe + "");
90        var iframeCount = $iframe.length;
91        if (iframeCount === 0) {
92            // Create a new iFrame if none is given
93            $iframe = $('<iframe height="0" width="0" border="0" wmode="Opaque"/>')
94                .prependTo('body')
95                .css({
96                    "position": "absolute",
97                    "top": -999,
98                    "left": -999
99                });
100        }
101        var frameWindow = $iframe.get(0);
102        return printFrame(frameWindow, content, options)
103            .done(function () {
104                // Success
105                setTimeout(function () {
106                    // Wait for IE
107                    if (iframeCount === 0) {
108                        // Destroy the iframe if created here
109                        $iframe.remove();
110                    }
111                }, 1000);
112            })
113            .fail(function (err) {
114                // Use the pop-up method if iframe fails for some reason
115                console.error("Failed to print from iframe", err);
116                printContentInNewWindow(content, options);
117            })
118            .always(function () {
119                try {
120                    options.deferred.resolve();
121                } catch (err) {
122                    console.warn('Error notifying deferred', err);
123                }
124            });
125    }
126
127    function printContentInNewWindow(content, options) {
128        // Open a new window and print selected content
129        var frameWindow = window.open();
130        return printFrame(frameWindow, content, options)
131            .always(function () {
132                try {
133                    options.deferred.resolve();
134                } catch (err) {
135                    console.warn('Error notifying deferred', err);
136                }
137            });
138    }
139
140    function isNode(o) {
141        /* http://stackoverflow.com/a/384380/937891 */
142        return !!(typeof Node === "object" ? o instanceof Node : o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName === "string");
143    }
144    $.print = $.fn.print = function () {
145        // Print a given set of elements
146        var options, $this, self = this;
147        // console.log("Printing", this, arguments);
148        if (self instanceof $) {
149            // Get the node if it is a jQuery object
150            self = self.get(0);
151        }
152        if (isNode(self)) {
153            // If `this` is a HTML element, i.e. for
154            // $(selector).print()
155            $this = $(self);
156            if (arguments.length > 0) {
157                options = arguments[0];
158            }
159        } else {
160            if (arguments.length > 0) {
161                // $.print(selector,options)
162                $this = $(arguments[0]);
163                if (isNode($this[0])) {
164                    if (arguments.length > 1) {
165                        options = arguments[1];
166                    }
167                } else {
168                    // $.print(options)
169                    options = arguments[0];
170                    $this = $("html");
171                }
172            } else {
173                // $.print()
174                $this = $("html");
175            }
176        }
177        // Default options
178        var defaults = {
179            globalStyles: true,
180            mediaPrint: false,
181            stylesheet: null,
182            noPrintSelector: ".no-print",
183            iframe: true,
184            append: null,
185            prepend: null,
186            manuallyCopyFormValues: true,
187            deferred: $.Deferred(),
188            timeout: 750,
189            title: null,
190            doctype: '<!doctype html>'
191        };
192        // Merge with user-options
193        options = $.extend({}, defaults, (options || {}));
194        var $styles = $("");
195        if (options.globalStyles) {
196            // Apply the stlyes from the current sheet to the printed page
197            $styles = $("style, link, meta, base, title");
198        } else if (options.mediaPrint) {
199            // Apply the media-print stylesheet
200            $styles = $("link[media=print]");
201        }
202        if (options.stylesheet) {
203            // Add a custom stylesheet if given
204            $styles = $.merge($styles, $('<link rel="stylesheet" href="' + options.stylesheet + '">'));
205        }
206        // Create a copy of the element to print
207        var copy = jQueryCloneWithSelectAndTextAreaValues($this);
208        // Wrap it in a span to get the HTML markup string
209        copy = $("<span/>")
210            .append(copy);
211        // Remove unwanted elements
212        copy.find(options.noPrintSelector)
213            .remove();
214        // Add in the styles
215        copy.append(jQueryCloneWithSelectAndTextAreaValues($styles));
216        // Update title
217        if (options.title) {
218            var title = $("title", copy);
219            if (title.length === 0) {
220                title = $("<title />");
221                copy.append(title);                
222            }
223            title.text(options.title);            
224        }
225        // Appedned content
226        copy.append(getjQueryObject(options.append));
227        // Prepended content
228        copy.prepend(getjQueryObject(options.prepend));
229        if (options.manuallyCopyFormValues) {
230            // Manually copy form values into the HTML for printing user-modified input fields
231            // http://stackoverflow.com/a/26707753
232            copy.find("input")
233                .each(function () {
234                    var $field = $(this);
235                    if ($field.is("[type='radio']") || $field.is("[type='checkbox']")) {
236                        if ($field.prop("checked")) {
237                            $field.attr("checked", "checked");
238                        }
239                    } else {
240                        $field.attr("value", $field.val());
241                    }
242                });
243            copy.find("select").each(function () {
244                var $field = $(this);
245                $field.find(":selected").attr("selected", "selected");
246            });
247            copy.find("textarea").each(function () {
248                // Fix for https://github.com/DoersGuild/jQuery.print/issues/18#issuecomment-96451589
249                var $field = $(this);
250                $field.text($field.val());
251            });
252        }
253        // Get the HTML markup string
254        var content = copy.html();
255        // Notify with generated markup & cloned elements - useful for logging, etc
256        try {
257            options.deferred.notify('generated_markup', content, copy);
258        } catch (err) {
259            console.warn('Error notifying deferred', err);
260        }
261        // Destroy the copy
262        copy.remove();
263        if (options.iframe) {
264            // Use an iframe for printing
265            try {
266                printContentInIFrame(content, options);
267            } catch (e) {
268                // Use the pop-up method if iframe fails for some reason
269                console.error("Failed to print from iframe", e.stack, e.message);
270                printContentInNewWindow(content, options);
271            }
272        } else {
273            // Use a new window for printing
274            printContentInNewWindow(content, options);
275        }
276        return this;
277    };
278})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.