PageSourceSearch

https://www.sumterschools.org/js/dialog.js?v=U7x_P-RGJm34ojdh0-PjAyhUrO4K1c6FUIthBHbRHag

js sumterschools.org collected 2026-10-01 23:50:11 UTC 11,630 bytes, 375 lines download raw bytes

1$.dialog = function (url, params, validation) {
2    var $body = $(document.body),
3        $modal = $('<div class="csc-modal"></div>'),
4        fn_fail, fn_done, fn_always, fn_load, fn_close;
5        $originFocus = $(document.activeElement);
6
7    var removeModal = function () {
8        // TODO: Destroy all Kendo widgets
9        // destroyKendo();
10        $modal.trigger("close");
11        $modal.remove();
12        $originFocus.focus();
13       
14        if ($(".csc-modal:visible").length == 0)
15            $body.removeClass("csc-modal-open");
16
17        if ($body.hasClass("csc-design-mode") && $body.find(".widget-form-modal").length == 0)
18            designer.showDesignBar();
19    }
20
21    if ($body.hasClass("csc-design-mode"))
22        designer.hideDesignBar();
23
24    var task = $modal.load(url, params)
25        .done(function () {
26            var result;
27
28            $modal.show();
29            $modal.find("[data-dismiss=modal]").on("click", function (event) {
30
31                if ($(this).prop("disabled") || $(this).is(".disabled"))
32                    return;
33
34                if (validation) {
35                    if (!validation.call($modal[0], this.name))
36                        return;
37                }
38
39                if (fn_done) 
40                    result = fn_done.call($modal[0], this.name);
41
42                if (fn_close) 
43                    result = fn_close.call($modal[0], this);
44
45                $.isPromise(result)
46                    ? result.done(removeModal)
47                    : removeModal();
48            });
49            modalFocusTrap($modal);
50            $modal.focusFirst();
51
52            $body.addClass("csc-modal-open");
53            
54            if (fn_load) fn_load.apply($modal[0], arguments);
55        })
56        .fail(function () {
57            if (fn_fail) fn_fail.apply($modal[0], arguments);
58
59            removeModal();
60        })
61        .always(function () {
62            if (fn_always) fn_always.apply($modal[0], arguments);
63        })
64
65    $body.append($modal.css({display: "block"}));
66
67    // builder
68    var builder = {
69        data: function(data){
70            $modal.data($.extend($modal.data(), data)); return builder;
71        },
72        done: function (callback) {
73            fn_done = callback; return builder;
74        },
75        always: function (callback) {
76            fn_always = callback; return builder;
77        },
78        fail: function (callback) {
79            fn_fail = callback; return builder;
80        },
81        load: function (callback) {
82
83            fn_load = callback; return builder;
84        },
85        close: function (callback) {
86            fn_close = callback; return builder;
87        }
88    }
89
90    //api
91    $modal.data({
92        dialog: {
93            builder: builder,
94            close: function (data) {
95                var result;
96
97                if (fn_close) 
98                    result = fn_close.call($modal[0], data);
99
100                $.isPromise(result)
101                    ? result.done(removeModal)
102                    : removeModal();              
103            },
104            hide: function () {
105                $modal.hide();
106
107                if ($(".csc-modal:visible").length == 0)
108                    $body.removeClass("csc-modal-open");
109            },
110            show: function () {
111                $modal.show();
112                $modal.focusFirst();
113            }
114        }
115    });
116
117    return builder;
118}
119
120$.fn.dialog = function () {
121    var $dialog = this.is(".csc-modal") ? this : this.parents(".csc-modal:first");
122    var options = ($dialog.data() || {}).dialog;
123
124    if (options === undefined) {
125
126        options = {
127            close: function () {
128                $dialog.remove();
129
130                if ($(".csc-modal:visible").length == 0)
131                    $body.removeClass("csc-modal-open");
132            },
133            hide: function () {
134                $dialog.hide();
135
136                if ($(".csc-modal:visible").length == 0)
137                    $body.removeClass("csc-modal-open");
138            },
139            show: function () {
140                $dialog.show();
141                $dialog.focusFirst();
142            }
143        }
144
145        $dialog.find("[data-dismiss=modal]").on("click", function () {
146            options.close();
147        });
148    }
149
150    // return the api
151    return options;
152}
153
154$.alert = function (message, options) {
155    var task = $.Deferred()
156    var defaults = {
157        icon: "fa fa-exclamation-triangle",
158        title: "Page Alert",
159        notes: "",
160        isalert: true
161    }
162
163    if (typeof message === "object") {
164        options = message;
165        message = options.message;
166    }
167
168    options = $.extend({}, defaults, options);
169
170    var $message = $('<div class="csc-popup-message"></div>').html(message);
171    var $notes = $('<div class="csc-popup-notes"></div>').html(options.notes);
172
173    $.popup([$message, $notes], options).done(function () {
174        return task.resolve();
175    });
176
177    return task.promise();
178}
179
180$.confirm = function (message, options) {
181    var defaults = {
182        icon: "fa fa-questin-circle",
183        title: "Confirm",
184        notes: "",
185        checkboxConfirm: false
186    }
187
188    if (typeof message === "object") {
189        options = message;
190        message = options.message;
191    }
192
193    options = $.extend({}, defaults, options);
194    options.closeText = "No";
195    options.buttons = ["Yes"];
196
197    var $message = $('<div class="csc-popup-message"></div>').html(message);
198    var $notes = $('<div class="csc-popup-notes"></div>').html(options.notes);
199
200    return $.popup([$message, $notes], options);
201}
202
203$.prompt = function (message, options) {
204    var task = $.Deferred();
205    var defaults = {
206        icon: "fa fa-question-circle",
207        title: "",
208        value: "",
209        placeholder: "",
210        notes: "",
211        required: false
212    };
213
214    if (typeof message === "object") {
215        options = message;
216        message = options.message;
217    }
218
219    options = $.extend({}, defaults, options);
220    options.closeText = "Cancel";
221    options.buttons = ["Submit"];
222
223    var $message = $('<div class="csc-popup-message"></div>').html(message);
224    var $notes = $('<div class="csc-popup-notes"></div>').html(options.notes);
225    var $control;
226
227    if (options.options) {
228        // normalize option data
229        options.options.forEach(function (item) {
230            item.value = item.value || item.id;
231            item.text = item.text || item.name || item.title;
232            item.checked = item.checked || item.selected || item.value === options.value;
233        });
234
235        options.mode = options.mode || (options.length < 5 ? "radio" : "select");
236
237        if (options.mode === "radio") {
238            $control = $("<ul/>").addClass("csc-list-unstyled");
239            options.options.forEach(function (item) {
240                $control.append('<li><label><input type="radio" name="csc-popup-input" value="' + item.value + '"' + (item.checked ? " checked" : "") + '/> ' + item.text + '</label></li>');
241            });
242        }
243        else {
244            $control = $("<select/>").addClass("csc-form-control");
245            options.options.forEach(function (item) {
246                $control.append('<option value="' + item.value + '"' + (item.checked ? " selected" : "") + '>' + item.text + '</option>');
247            });
248        }
249
250        $control.attr("title", options.placeholder);
251        $control.addClass("csc-popup-input");
252    }
253    else {
254        $control = $('<input class="csc-popup-input csc-form-control" />');
255        $control.attr("placeholder", options.placeholder);
256        $control.attr("value", options.value);
257    }
258
259    $.popup([$message, $control, $notes], options).done(function ($btn, $popup) {
260        var $input = $popup.find(".csc-popup-input");
261
262        var value = $input.is("ul")
263            ? $input.find("input:checked").val() // radio buttons
264            : $input.val().trim(); // selectlist or textbox
265
266        if (options.required && value === "")
267            return task.reject();
268
269        return task.resolve(value);
270    });
271
272    return task.promise();
273}
274
275$.popup = function (html, options) {
276    var task = $.Deferred(),
277        promise = task.promise();
278
279    var $popup = $(
280        [
281            '<div class="csc-modal csc-popup">',
282            '   <div class="csc-modal-dialog">',
283            '        <div class="csc-modal-content csc-popup-content">',
284            '            <div class="csc-popup-title"></div>',
285            '            <div class="csc-popup-body"></div>',
286            '            <div class="csc-popup-buttons">',
287            '                <a href="#" onclick="return false;" tabindex="2" name="close">Close</a>',
288            '            </div>',
289            '        </div>',
290            '    </div>',
291            '</div>'
292        ].join("\n")
293    );
294
295    options = $.extend({}, { icon: "", title: "", buttons: [], cancelText: "Cancel", isalert: false }, options);
296
297    $popup.find(".csc-popup-buttons > a:first").text(options.closeText);
298
299    if (options.height)
300        $popup.find(".csc-popup-content").css("height", options.height);
301
302    if (options.icon)
303        $popup.find(".csc-popup-title").append($("<i></i>").addClass(options.icon));
304
305    if (options.title)
306        $popup.find(".csc-popup-title").append(options.title);
307
308    if (options.buttons && options.buttons.length) {
309        for (var i in options.buttons) {
310            var name = options.buttons[i];
311            $popup.find(".csc-popup-buttons").prepend(
312                '<a href="#" onclick="return false;" name="' + name.toLowerCase() + '">' + name + '</a>'
313            );
314        }
315    }
316
317    if (!$.isArray(html)) html = [html];
318    for(var i = 0; i < html.length; i++) {
319        $popup.find(".csc-popup-body").append(html[i]);
320    }
321
322    if (options.checkboxConfirm) {
323        var chkBoxHtml = "<div class='csc-popup-notes' style='padding-bottom:0'><span class='csc-text-default'>Check box to confirm: "
324                        +"<input class='csc-popup-checkbox' type='checkbox' id='dblConfirmCheckbox' name='dblConfirmCheckbox' /></span></div>";
325        $popup.find(".csc-popup-body").append(chkBoxHtml);
326    }
327
328    $popup.appendTo(document.body);
329    
330    $popup.find(".csc-popup-buttons > a").on("click",
331        function () {
332            if ($(this).attr("name") !== "close" || options.isalert) {
333                task.resolve($(this), $popup);
334            }
335            else task.reject();
336          
337            $popup.remove();
338        });
339
340    if (options.checkboxConfirm) {
341        $popup.find(".csc-popup-buttons > a[name=yes]").hide();
342
343        $popup.find("#dblConfirmCheckbox").change(function () {
344            if ($(this).prop("checked"))
345                $popup.find(".csc-popup-buttons > a[name=yes]").show();
346            else
347                $popup.find(".csc-popup-buttons > a[name=yes]").hide();
348        });
349    }
350
351    $popup.focus();
352    $popup.focusFirst();
353
354    $popup.close = function () {
355        $popup.remove();
356    }
357
358    promise.popup = function () {
359        return $popup;
360    }
361
362    return promise;
363}
364
365
366$.fn.focusFirst = function () {
367    var $parent = this;
368
369    $parent.find("input,select,textarea,a,button,object")
370        .not("input[type=hidden],:hidden,:disabled")
371        .first()
372        .focus();
373
374    return $parent;
375}

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.