PageSourceSearch

https://www.mortgagenewsdaily.com/js/utilities.js?v=RSWKUb6kFnoiDjdwegWl5OJCYMN-okHd7RlwQd10m2o

js mortgagenewsdaily.com collected 2026-10-02 02:45:16 UTC 85,943 bytes, 1,668 lines download raw bytes

1//import * as _ from "underscore";
2//import * as $ from "jquery";
3//import * as moment from "moment";
4//import * as store from "store";
5var mnd;
6(function (mnd) {
7    var utilities;
8    (function (utilities) {
9        //declare var store: any;
10        var today = new Date();
11        _.templateSettings = {
12            evaluate: /\{\[([\s\S]+?)\]\}/g,
13            interpolate: /\{\{(.+?)\}\}/g
14        };
15        var modalTemplate = _.template("<div class=\"modal fade {{modalClass}}\">\n\t  <div class=\"modal-dialog\">\n\t\t<div class=\"modal-content\">\n      {[ if(title) { ]}\t\n\t\t  <div class=\"modal-header\">\n\t\t\t<button type=\"button\" class=\"close\" data-dismiss=\"modal\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>\n\t\t\t<h4 class=\"modal-title\">{{title}}</h4>\n\t\t  </div>\n      {[ } ]}\n\t\t  <div class=\"modal-body\">\n\t\t\t{{formContent}}  \n\t\t  </div>\n\t\t  <div class=\"modal-footer\">\n\t\t\t<button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">{{cancelButtonText}}</button>\n\t\t\t<button type=\"button\" class=\"btn btn-primary save\">{{saveButtonText}}</button>\n\t\t  </div>\n\t\t</div>\n\t  </div>\n\t</div>");
16        var previewTemplate = _.template("<div class=\"modal fade {{modalClass}}\">\n\t  <div class=\"modal-dialog\">\n\t\t<div class=\"modal-content\">\n\t\t  <div class=\"modal-header\">\n\t\t\t<button type=\"button\" class=\"close\" data-dismiss=\"modal\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>\n\t\t\t<h4 class=\"modal-title\">{{title}}</h4>\n\t\t  </div>\n\t\t  <div class=\"modal-body\">\n\t\t\t{{body}}\n\t\t  </div>\n\t\t  <div class=\"modal-footer\">\n\t\t\t<button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button>\n            {[ if(showSave) { ]}\t\t\n                <button type=\"button\" class=\"btn btn-{{saveButtonClass}} save\" data-dismiss=\"modal\">{{saveButtonText}}</button>\t\n            {[ } ]}\n\t\t  </div>\n\t\t</div>\n\t  </div>\n\t</div>");
17        var shareTemplate = _.template("<div class=\"modal fade {{modalClass}}\">\n\t  <div class=\"modal-dialog\">\n\t\t\n\t\t\t{{body}}\n\t\t  \n\t  </div>\n\t</div>");
18        var previewIFrameTemplate = _.template("<div class=\"modal fade {{modalClass}}\">\n\t  <div class=\"modal-dialog\">\n\t\t<div class=\"modal-content\">\n\t\t  <div class=\"modal-header\">\n\t\t\t<button type=\"button\" class=\"close\" data-dismiss=\"modal\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>\n\t\t\t<h4 class=\"modal-title\">{{title}}</h4>\n\t\t  </div>\n\t\t  <div class=\"modal-body\">\n\t\t\t<iframe id=\"modal-iframe\" src=\"{{url}}\"></iframe>\n\t\t  </div>\n\t\t  <div class=\"modal-footer\">\n\t\t\t<button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button>\n            {[ if(showSave) { ]}\t\t\n                <button type=\"button\" class=\"btn btn-{{saveButtonClass}} save\" data-dismiss=\"modal\">{{saveButtonText}}</button>\t\n            {[ } ]}\n\t\t  </div>\n\t\t</div>\n\t  </div>\n\t</div>");
19        var imageTemplate = _.template("<div class=\"modal fade image-selector\" id=\"imageModal\">\n\t  <div class=\"modal-dialog\">\n\t\t<div class=\"modal-content\">\n\t\t  <div class=\"modal-header\">\n\t\t\t<button type=\"button\" class=\"close\" data-dismiss=\"modal\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>\n\t\t\t<h4 class=\"modal-title\">Select an Image</h4>\n\t\t  </div>\n\t\t  <div class=\"modal-body\">\n\t\t\t<div class=\"image-selector\">\t\t\t\t\n\t\t\t\t{[ _.each(images, function(image) { ]}\n\t\t\t\t\t<div class=\"single-image\">\n\t\t\t\t\t\t<div class=\"thumbnail\">\n\t\t\t\t\t\t\t<a href=\"#\" class=\"image\" data-link=\"{{image.link}}\" data-imageurl=\"{{image.url}}\" data-title=\"{{image.title}}\" data-assetid=\"{{image.id}}\"><img src=\"{{image.url}}\" border=\"0\"></a>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t{{image.title}}\n\t\t\t\t\t</div>\n\t\t\t\t{[ }); ]}\n\t\t\t</div>            \n\t\t  </div>\t\n          {[ if(showUpload) { ]}\n          <div class=\"modal-footer image-upload\">            \n             <h4 class=\"modal-title\">Upload an Image</h4>\n            <form action=\"/asset/new\" method=\"post\" class=\"form-horizontal\" enctype=\"multipart/form-data\">\n\t\t\t\t<div class=\"form-fields\">\n\t\t\t\t\t<div class=\"form-group\">\n\t                    <label class=\"control-label col-md-3\" for=\"Name\">Name</label>\n\t                    <div class=\"col-md-9\">\n\t\t                    <input class=\"form-control\" placeholder=\"\" data-val=\"true\" data-val-required=\"The Name field is required.\" id=\"Name\" name=\"Name\" value=\"\" type=\"text\">
19\n\t\t                    <span class=\"field-validation-valid\" data-valmsg-for=\"Name\" data-valmsg-replace=\"true\"></span>\n\t                    </div>\n                    </div>\n                    <div class=\"form-group\">\n\t                    <label class=\"control-label col-md-3\">Contents</label>\n\t                    <div class=\"col-md-9\">\n\t\t                    <div id=\"file-content\" class=\"form-control file-content\">\n                                <label for=\"uploadfile\" class=\"file-to-upload\"><strong>Choose a file</strong> or drag it here.</label>\n                                <input type=\"file\" name=\"uploadfile\" id=\"uploadfile\" class=\"hidden-file\" />\t\t\t                    \n\t\t                    </div>\n\t\t                    <span class=\"field-validation-valid\" data-valmsg-for=\"Location\" data-valmsg-replace=\"true\"></span>\n\t                    </div>\n                    </div>\n                    <input type=\"hidden\" name=\"InputAssetTags\" id=\"InputAssetTags\" value=\"{{tags}}\" />\n\t\t\t\t</div>\n\t\t\t\t<button type=\"submit\" class=\"btn btn-primary\">Add Image</button>\n\t\t\t</form>\n          </div> \n          {[ } ]}\n\t\t</div>\n\t  </div>\n\t</div>");
20        var editCommentTemplate = _.template("\n    <form class=\"edit-comment-form\">\n        <div class=\"form-group\">\n            <textarea class=\"form-control\" style=\"height: {{height}}px;\" name=\"Content\">{{content}}</textarea>\n        </div>\n        <div class=\"form-group\">\n            <div class=\"text-right\">\n                <button type=\"button\" class=\"btn btn-default cancel\">Cancel</button>\n\t\t\t    <button type=\"button\" class=\"btn btn-primary save\">Update Comment</button>\n            </div>\n        </div>\n    </form>\n");
21        var editAnswerTemplate = _.template("\n    <form class=\"edit-answer-form\">\n        <div class=\"form-group\">\n            <textarea class=\"form-control answer-body\" style=\"height: {{height}}px;\" name=\"Body\">{{content}}</textarea>\n        </div>\n        <div class=\"form-group\">\n            <div class=\"text-right\">\n                <button type=\"button\" class=\"btn btn-default cancel\">Cancel</button>\n\t\t\t    <button type=\"button\" class=\"btn btn-primary save\">Update Answer</button>\n            </div>\n        </div>\n    </form>\n");
22        var flashTemplate = _.template("<div class=\"alert {{alertClass}} fade in \">\n\t\t    <a class=\"close\" data-dismiss=\"alert\" href=\"#\">x</a>\n\t\t    <h4 class=\"alert-heading\">{{ title }}</h4> \n\t\t    <p>{{ message }}</p>\n\t    </div>");
23        var acceptedFileTypes = {
24            'image/png': true,
25            'image/jpeg': true,
26            'image/gif': true,
27            'image/jpg': true,
28            'application/x-pdf': true
29        };
30        function showModal(vm, template, onShown, onSave) {
31            var modalContent = template(vm);
32            var modal = $(modalContent).on('hidden.bs.modal', function () {
33                $(this).remove();
34            }).on('shown.bs.modal', function () {
35                if (onShown != null) {
36                    onShown.apply(this, [modal]);
37                }
38            }).on('click', '.btn.save', function (e) {
39                if (onSave != null) {
40                    onSave.apply(this, [modal]);
41                }
42            }).modal();
43        }
44        function formatFileSize(bytes) {
45            if (typeof bytes !== 'number') {
46                return '';
47            }
48            if (bytes >= 1000000000) {
49                return (bytes / 1000000000).toFixed(2) + ' GB';
50            }
51            if (bytes >= 1000000) {
52                return (bytes / 1000000).toFixed(2) + ' MB';
53            }
54            return (bytes / 1000).toFixed(2) + ' KB';
55        }
56        function formatLargeNumber(number, decimals) {
57            if (decimals === void 0) { decimals = 2; }
58            if (typeof number !== 'number') {
59                return '';
60            }
61            if (number >= 1000000000000) {
62                return (number / 1000000000000).toFixed(decimals) + 'T';
63            }
64            if (number >= 1000000000) {
65                return (number / 1000000000).toFixed(decimals) + 'B';
66            }
67            if (number >= 1000000) {
68                return (number / 1000000).toFixed(decimals) + 'M';
69            }
70            if (number >= 1000) {
71                return (number / 1000).toFixed(decimals) + 'k';
72            }
73            return number.toFixed(decimals);
74        }
75        utilities.formatLargeNumber = formatLargeNumber;
76        function tryParseInt(str, defaultValue) {
77            if (defaultValue === void 0) { defaultValue = 0; }
78            return parseInt(str) || defaultValue;
79        }
80        function showHtmlFromPost(url, postData, modalClass, title) {
81            postData = postData || {};
82            $.post(url, postData, function (data) {
83                var html = '';
84                var holder = $('<div />').append(data);
85                if (holder.find('body').length > 0) {
86                    html = holder.find('body').html();
87                }
88                else {
89                    html = holder.html();
90                }
91                var vm = {
92                    body: html,
93                    modalClass: modalClass,
94                    title: title == null ? 'Preview' : title,
95                    showSave: false
96                };
97                showModal(vm, previewTemplate);
98            });
99        }
100        utilities.showHtmlFromPost = showHtmlFromPost;
101        function showHtmlInIframePopup(url, modalClass, title) {
102            var vm = {
103                modalClass: modalClass,
104                title: title == null ? 'Preview' : title,
105                showSave: false,
106                url: url
107            };
108            showModal(vm, previewIFrameTemplate);
109        }
110        utilities.showHtmlInIframePopup = showHtmlInIframePopup;
111        function showHtmlPopup(url, title, onShown, modalClass) {
112            $.post(url, function (data) {
113                var html = '';
114                var holder = $('<div />').append(data);
115                if (holder.find('body').length > 0) {
116                    html = holder.find('body').html();
117                }
118                else {
119                    html = holder.html();
120                }
121                var vm = {
122                    body: html,
123                    modalClass: modalClass || '',
124                    title: title == null ? 'Preview' : title,
125                    showSave: false
126                };
127                showModal(vm, previewTemplate, onShown);
128            });
129        }
130        utilities.showHtmlPopup = showHtmlPopup;
131        function showPopup(body, title, modalClass, onShown) {
132            var vm = {
133                body: body,
134                modalClass: modalClass,
135                title: title == null ? 'Preview' : title,
136                showSave: false
137            };
138            showModal(vm, previewTemplate, onShown);
139        }
140        utilities.showPopup = showPopup;
141        function showSharePopup(body, title, modalClass, onShown) {
142            var vm = {
143                body: body,
144                modalClass: modalClass,
145                title: title == null ? 'Preview' : title
146            };
147            showModal(vm, shareTemplate, onShown);
148        }
149        utilities.showSharePopup = showSharePopup;
150        function setupDragDropBox(input, name, setupCallback) {
151            var _this = this;
152            var files, form, setupDragging, showFiles;
153            form = input.closest('form');
154            files = null;
155            showFiles = function (files) {
156                var firstFile;
157                if (files.length > 0) {
158                    if (files[0].name === void 0 && (files[0].fileName != null)) {
159                        $.each(files, function (index, file) {
160                            file.name = file.fileName;
161                            return file.size = file.fileSize;
162                        });
163                    }
164                    firstFile = files[0];
165                    firstFile.sizeFormatted = formatFileSize(firstFile.size);
166                    if (acceptedFileTypes[firstFile.type] === true) {
167                        $('.file-to-upload').html("Uploading: " + firstFile.name + " - " + firstFile.sizeFormatted);
168                        if ($(name).val().length === 0) {
169                            $(name).val(firstFile.name);
170                        }
171                    }
172                    else {
173                        $('.file-to-upload').html("Invalid File Type: '" + firstFile.type + "'");
174                    }
175                }
176            };
177            input.on('change', 'input', function (e) {
178                files = e.target.files;
179                showFiles(files);
180            });
181            setupDragging = function (dragInput) {
182                var dragEnter, dragLeave, dragOver, drop;
183                dragEnter = function (evt) {
184                    evt.stopPropagation();
185                    evt.preventDefault();
186                    $(evt.target).addClass('over');
187                };
188                dragOver = function (evt) {
189                    evt.stopPropagation();
190                    evt.preventDefault();
191                };
192                dragLeave = function (evt) {
193                    evt.stopPropagation();
194                    evt.preventDefault();
195                    $(evt.target).removeClass('over');
196                };
197                drop = function (evt) {
198                    evt.stopPropagation();
199                    evt.preventDefault();
200                    $(evt.target).removeClass('over');
201                    files = evt.originalEvent.dataTransfer.files || evt.originalEvent.target.files;
202                    showFiles(files);
203                    return false;
204                };
205                dragInput.bind('dragenter', dragEnter).bind('dragover', dragOver).bind('dragleave', dragLeave).bind('drop', drop);
206            };
207            setupDragging(input);
208            if ((form != null) && form.length) {
209                form.on('submit', function (e) {
210                    var action, data, firstFile;
211                    action = form.attr('action');
212                    data = new FormData(form[0]);
213                    data.delete('uploadfile');
214                    if (files != null) {
215                        firstFile = files[0];
216                        data.append(firstFile.name, firstFile);
217                    }
218                    $.ajax({
219                        type: 'POST',
220                        url: action,
221                        contentType: false,
222                        processData: false,
223                        data: data,
224                        success: function (result) {
225                            var newDragInput;
226                            if (result.success) {
227                                return window.location.href = result.redirectUrl;
228                            }
229                            else {
230                                $('.form-fields', form).empty().append(result.form);
231                                newDragInput = $(form).find(input);
232                                setupDragging(newDragInput);
233                                if (setupCallback != null) {
234                                    return setupCallback.apply(_this, [form]);
235                                }
236                            }
237                        },
238                        error: function (e, f, g) { }
239                    });
240                    return false;
241                });
242            }
243        }
244        utilities.setupDragDropBox = setupDragDropBox;
245        function showImageBrowser(fieldName, tags, showUpload, editor, zIndex) {
246            var data = {
247                imageTags: tags
248            };
249            $.post('/asset/images', data, function (images) {
250                var vm = {
251                    images: images,
252                    tags: tags,
253                    showUpload: showUpload
254                };
255                var modalContent = $(imageTemplate(vm));
256                var modal = $(modalContent)
257                    .css('z-index', zIndex++)
258                    .on('hidden.bs.modal', function () {
259                    $(this).remove();
260                }).modal();
261                var updateImage = function (url, title, link) {
262                    var fixedUrl = editor.convertURL(url, null, null);
263                    var fieldElm = document.getElementById(fieldName);
264                    fieldElm.value = fixedUrl;
265                    if (fieldElm['fireEvent'] != null) {
266                        fieldElm['fireEvent']('onchange');
267                    }
268                    else {
269                        var evt = document.createEvent('HTMLEvents');
270                        evt.initEvent("change", false, true);
271                        fieldElm.dispatchEvent(evt);
272                    }
273                    if (editor.windowManager.windows.length > 0) {
274                        var altCtrl = editor.windowManager.windows[0].find('#alt');
275                        var hrefCtrl = editor.windowManager.windows[0].find('#href');
276                        if (altCtrl != null) {
277                            altCtrl.value(title);
278                        }
279                        if (hrefCtrl != null) {
280                            hrefCtrl.value(link);
281                        }
282                    }
283                };
284                modalContent.on('click', 'a.image', function (e) {
285                    var link = $(e.currentTarget);
286                    updateImage(link.data('imageurl'), link.data('title'), link.data('link'));
287                    modal.modal('hide');
288                    return false;
289                });
290                if (showUpload === true) {
291                    setupImagePickerDropBox(modalContent.find('#file-content'), modalContent.find('#Name'), null, function (url, id, title, link) {
292                        updateImage(url, title, link);
293                        modal.modal('hide');
294                    });
295                }
296            });
297        }
298        utilities.showImageBrowser = showImageBrowser;
299        function setupImagePickerDropBox(input, name, setupCallback, successCallback) {
300            var _this = this;
301            var files, form, setupDragging, showFiles;
302            form = $(input).closest('form');
303            files = null;
304            showFiles = function (files) {
305                var firstFile;
306                if (files.length > 0) {
307                    if (files[0].name === void 0 && (files[0].fileName != null)) {
308                        $.each(files, function (index, file) {
309                            file.name = file.fileName;
310                            return file.size = file.fileSize;
311                        });
312                    }
313                    firstFile = files[0];
314                    firstFile.sizeFormatted = formatFileSize(firstFile.size);
315                    if (acceptedFileTypes[firstFile.type] === true) {
316                        $('.file-to-upload').html("Uploading: " + firstFile.name + " - " + firstFile.sizeFormatted);
317                        if ($(name).val().length === 0) {
318                            $(name).val(firstFile.name);
319                        }
320                    }
321                    else {
322                        $('.file-to-upload').html("Invalid File Type: '" + firstFile.type + "'");
323                    }
324                }
325            };
326            input.on('change', 'input', function (e) {
327                files = e.target.files;
328                showFiles(files);
329            });
330            setupDragging = function (dragInput) {
331                var dragEnter, dragLeave, dragOver, drop;
332                dragEnter = function (evt) {
333                    evt.stopPropagation();
334                    evt.preventDefault();
335                    $(evt.target).addClass('over');
336                };
337                dragOver = function (evt) {
338                    evt.stopPropagation();
339                    evt.preventDefault();
340                };
341                dragLeave = function (evt) {
342                    evt.stopPropagation();
343                    evt.preventDefault();
344                    $(evt.target).removeClass('over');
345                };
346                drop = function (evt) {
347                    evt.stopPropagation();
348                    evt.preventDefault();
349                    $(evt.target).removeClass('over');
350                    files = evt.originalEvent.dataTransfer.files || evt.originalEvent.target.files;
351                    showFiles(files);
352                    return false;
353                };
354                dragInput.bind('dragenter', dragEnter).bind('dragover', dragOver).bind('dragleave', dragLeave).bind('drop', drop);
355            };
356            setupDragging($(input));
357            if ((form != null) && form.length) {
358                form.on('submit', function (e) {
359                    var action, data, firstFile;
360                    action = form.attr('action');
361                    data = new FormData(form[0]);
362                    data.delete('uploadfile');
363                    if (files != null) {
364                        firstFile = files[0];
365                        data.append(firstFile.name, firstFile);
366                    }
367                    $('.asset-errors', form).remove();
368                    $.ajax({
369                        type: 'POST',
370                        url: action,
371                        contentType: false,
372                        processData: false,
373                        data: data,
374                        success: function (result) {
375                            var newDragInput;
376                            if (result.success) {
377                                if (successCallback != null) {
378                                    return successCallback.apply(_this, [result.url, result.id, result.title, result.link]);
379                                }
380                            }
381                            else {
382                                $('<div class="asset-errors alert alert-danger" />').html(result.errors).prependTo(form);
383                                newDragInput = $(form).find(input);
384                                setupDragging(newDragInput);
385                                if (setupCallback != null) {
386                                    return setupCallback.apply(_this, [form]);
387                                }
388                            }
389                        },
390                        error: function (e, f, g) { }
391                    });
392                    return false;
393                });
394            }
395        }
396        function showImagePicker(tags, showUpload, callback) {
397            var _this = this;
398            var data = {
399                imageTags: tags
400            };
401            $.post('/asset/ImagesByTags', data, function (images) {
402                var vm = {
403                    images: images,
404                    tags: tags,
405                    showUpload: showUpload
406                };
407                var modalContent = $(imageTemplate(vm));
408                var modal = $(modalContent)
409                    .on('hidden.bs.modal', function () {
410                    $(this).remove();
411                }).modal();
412                modalContent.on('click', 'a.image', function (e) {
413                    var link = $(e.currentTarget);
414                    var url = link.data('imageurl');
415                    var id = link.data('assetid');
416                    var title = link.data('title');
417                    if (callback != null) {
418                        callback.apply(_this, [url, id, title]);
419                    }
420                    modal.modal('hide');
421                    return false;
422                });
423                if (showUpload === true) {
424                    setupImagePickerDropBox(modalContent.find('#file-content'), modalContent.find('#Name'), null, function (url, id, title, link) {
425                        if (callback != null) {
426                            callback.apply(_this, [url, id, title]);
427                        }
428                        modal.modal('hide');
429                    });
430                }
431            });
432        }
433        utilities.showImagePicker = showImagePicker;
434        function showMarketNewsImagePicker(baseUrl, tags, callback) {
435            var _this = this;
436            var data = {
437                imageTags: tags
438            };
439            $.ajax({
440                type: 'POST',
441                url: "".concat(baseUrl, "/asset/ImagesByTags"),
442                data: data,
443                dataType: 'json',
444                traditional: true,
445                crossDomain: true,
446                success: function (images, status, xhr) {
447                    var vm = {
448                        images: images,
449                        tags: tags,
450                        showUpload: false
451                    };
452                    var modalContent = $(imageTemplate(vm));
453                    var modal = $(modalContent)
454                        .on('hidden.bs.modal', function () {
455                        $(this).remove();
456                    }).modal();
457                    modalContent.on('click', 'a.image', function (e) {
458                        var link = $(e.currentTarget);
459                        var url = link.data('imageurl');
460                        var id = link.data('assetid');
461                        var title = link.data('title');
462                        if (callback != null) {
463                            callback.apply(_this, [url, id, title]);
464                        }
465                        modal.modal('hide');
466                        return false;
467                    });
468                }
469            });
470        }
471        utilities.showMarketNewsImagePicker = showMarketNewsImagePicker;
472        function showConfirmDialog(url, postData, confirmText, title, saveButtonText, callbackConfirmed, callbackUnconfirmed, cancelButtonText) {
473            var vm = {
474                title: title,
475                formContent: confirmText,
476                saveButtonText: saveButtonText,
477                modalClass: '',
478                cancelButtonText: 'Cancel'
479            };
480            var clicked = false;
481            var confirmed = false;
482            showModal(vm, modalTemplate, function (modal) {
483                $(modal).on('click', '.btn.save', function (evt) {
484                    if (!clicked) {
485                        clicked = true;
486                        modal.modal('hide');
487                        confirmed = true;
488                        $.post(url, postData || {}, function (data) {
489                            if (callbackConfirmed != null) {
490                                callbackConfirmed.apply(modal, [data]);
491                            }
492                        });
493                    }
494                    return false;
495                }).on('hidden.bs.modal', function () {
496                    if (confirmed == false) {
497                        if (callbackUnconfirmed != null) {
498                            callbackUnconfirmed.apply(modal, [true]);
499                        }
500                    }
501                    modal.remove();
502                });
503                modal.find('input:visible:enabled').first().focus();
504            });
505        }
506        utilities.showConfirmDialog = showConfirmDialog;
507        function showConfirm(confirmText, title, saveButtonText, callbackConfirmed, callbackUnconfirmed, cancelButtonText) {
508            var vm = {
509                title: title,
510                formContent: confirmText,
511                saveButtonText: saveButtonText,
512                cancelButtonText: cancelButtonText || 'Cancel',
513                modalClass: ''
514            };
515            var clicked = false;
516            var confirmed = false;
517            showModal(vm, modalTemplate, function (modal) {
518                $(modal).on('click', '.btn.save', function (evt) {
519                    if (!clicked) {
520                        clicked = true;
521                        modal.modal('hide');
522                        confirmed = true;
523                        if (callbackConfirmed != null) {
524                            callbackConfirmed.apply(modal);
525                        }
526                    }
527                    return false;
528                }).on('hidden.bs.modal', function () {
529                    if (confirmed == false) {
530                        if (callbackUnconfirmed != null) {
531                            callbackUnconfirmed.apply(modal, [true]);
532                        }
533                    }
534                    modal.remove();
535                });
536                modal.find('input:visible:enabled').first().focus();
537            });
538        }
539        utilities.showConfirm = showConfirm;
540        function showModalFromScreen(title, content, modalClass, onShown, onSave, saveButtonClass, saveButtonText) {
541            if (saveButtonClass === void 0) { saveButtonClass = 'success'; }
542            if (saveButtonText === void 0) { saveButtonText = 'Save'; }
543            var vm = {
544                title: title,
545                body: content,
546                modalClass: modalClass,
547                showSave: onSave != null,
548                saveButtonClass: saveButtonClass,
549                saveButtonText: saveButtonText
550            };
551            showModal(vm, previewTemplate, onShown, onSave);
552        }
553        utilities.showModalFromScreen = showModalFromScreen;
554        function modalFormFromLinkTemplated(link, title, saveButtonText, callbackShown, callbackHidden, modalClass) {
555            var url = $(link).data('target') || $(link).prop('href');
556            if (url != null && url.length > 0) {
557                return modalFormFromUrlTemplated(url, title, saveButtonText, callbackShown, callbackHidden, modalClass);
558            }
559        }
560        utilities.modalFormFromLinkTemplated = modalFormFromLinkTemplated;
561        function modalFormFromUrlTemplated(url, title, saveButtonText, callbackShown, callbackHidden, modalClass) {
562            var _this = this;
563            if (url && url.length) {
564                $.get(url, { "_": $.now() }, function (formData) {
565                    var vm = {
566                        title: title,
567                        formContent: formData,
568                        saveButtonText: saveButtonText,
569                        modalClass: modalClass || '',
570                        cancelButtonText: 'Cancel'
571                    };
572                    var modalContent = $(modalTemplate(vm));
573                    var form = modalContent.find('form');
574                    modalContent.on('keypress', function (e) {
575                        if (e.which === 13) {
576                            modalContent.find('.btn.save').trigger('click');
577                            return false;
578                        }
579                    });
580                    if (form.length > 0) {
581                        modalContent.on('click', '.btn.save', function () {
582                            var $frm = modal.find('form');
583                            var url = $frm.prop('action');
584                            var data = $frm.serialize();
585                            $.post(url, data, function (returnData) {
586                                if (callbackHidden != null) {
587                                    callbackHidden.apply(_this, [returnData, modal]);
588                                }
589                            });
590                            return false;
591                        });
592                    }
593                    else {
594                        modalContent.find('.modal-footer').hide();
595                    }
596                    var modal = modalContent.on('hidden.bs.modal', function () {
597                        $(modal).remove();
598                    }).modal();
599                    setTimeout(function () {
600                        modal.find(':text,textarea,select').filter(':visible:first').focus();
601                    }, 300);
602                    if (callbackShown != null) {
603                        callbackShown.apply(_this, [form]);
604                    }
605                });
606                return false;
607            }
608        }
609        utilities.modalFormFromUrlTemplated = modalFormFromUrlTemplated;
610        function showFlash(alertTitle, alertMessage, location, closeTimer, alertClass) {
611            var vm = {
612                title: alertTitle,
613                message: alertMessage,
614                alertClass: alertClass
615            };
616            var alertDiv = $('<div />').html(flashTemplate(vm));
617            $(location).prepend(alertDiv);
618            alertDiv.alert();
619            if (closeTimer != null) {
620                window.setTimeout(function () {
621                    alertDiv.remove();
622                }, closeTimer);
623            }
624        }
625        utilities.showFlash = showFlash;
626        function showError(alertTitle, alertMessage, location, closeTimer, alertClass) {
627            showFlash(alertTitle, alertMessage, location, closeTimer, (alertClass || '') + ' alert-danger error');
628        }
629        utilities.showError = showError;
630        function showAlert(alertTitle, alertMessage, location, closeTimer, alertClass) {
631            showFlash(alertTitle, alertMessage, location, closeTimer, (alertClass || '') + ' alert-warning');
632        }
633        utilities.showAlert = showAlert;
634        function showSuccess(alertTitle, alertMessage, location, closeTimer, alertClass) {
635            showFlash(alertTitle, alertMessage, location, closeTimer, (alertClass || '') + ' alert-success');
636        }
637        utilities.showSuccess = showSuccess;
638        function showInfo(alertTitle, alertMessage, location, closeTimer, alertClass) {
639            showFlash(alertTitle, alertMessage, location, closeTimer, (alertClass || '') + ' alert-info');
640        }
641        utilities.showInfo = showInfo;
642        function setupBreakingNewsDismiss() {
643            $('body').on('click', '[data-cid] .close', function () {
644                var banner = $(this).closest('[data-cid]');
645                banner.remove();
646                return false;
647            });
648        }
649        utilities.setupBreakingNewsDismiss = setupBreakingNewsDismiss;
650        function showBreakingNewsHeader(template, news) {
651            if (news.canShowBanner === true) {
652                var banner = template(news);
653                var existing = $('[data-cid="' + news.id + '"]');
654                if (existing.length > 0) {
655                    existing.replaceWith(banner);
656                }
657                else {
658                    $('body>.body-content').prepend(banner);
659                    existing = $('[data-cid="' + news.id + '"]');
660                }
661                existing.on('click', '.close', function () {
662                    //console.log('closed');
663                    existing.remove();
664                });
665            }
666            else {
667                $('body>.body-content').find('[data-cid="' + news.id + '"]').remove();
668            }
669        }
670        utilities.showBreakingNewsHeader = showBreakingNewsHeader;
671        function addTemplatedItem(template, item, selector) {
672            var container = $(selector);
673            if (item.canDisplay === true) {
674                var existing = container.find('[data-cid="' + item.id + '"]');
675                item.isNew = existing.length === 0;
676                var tplItem = template(item);
677                if (existing.length > 0) {
678                    existing.replaceWith(tplItem);
679                }
680                else {
681                    container.prepend(tplItem);
682                }
683            }
684            else {
685                container.find('[data-cid="' + item.id + '"]').remove();
686            }
687            var maxListLength = tryParseInt(container.data('list-max'), 0);
688            if (maxListLength > 0) {
689                var existingLength = container.find('[data-cid]').length;
690                while (existingLength > maxListLength) {
691                    container.find('[data-cid]:last-child').remove();
692                    existingLength = container.find('[data-cid]').length;
693                }
694            }
695            setupViewSectionsNewLabels(selector);
696        }
697        function addAroundTheWebItem(template, atw, selector) {
698            addTemplatedItem(template, atw, selector);
699        }
700        utilities.addAroundTheWebItem = addAroundTheWebItem;
701        function addVideoItem(template, video, selector) {
702            addTemplatedItem(template, video, selector);
703        }
704        utilities.addVideoItem = addVideoItem;
705        function addArticleItem(template, article, selector) {
706            //console.log(template, article, selector);
707            addTemplatedItem(template, article, selector);
708        }
709        utilities.addArticleItem = addArticleItem;
710        function addMainArticleItem(template, article, selector, secondarySelector) {
711            if (secondarySelector != null && secondarySelector.length > 0) {
712                var mainContainer = $(selector);
713                var existing = mainContainer.find('[data-cid="' + article.i
713d + '"]');
714                if (existing.length > 0) {
715                    if (article.canDisplay === true) {
716                        var tplItem = template(article);
717                        existing.replaceWith(tplItem);
718                    }
719                    else {
720                        mainContainer.find('[data-cid="' + article.id + '"]').remove();
721                    }
722                    return;
723                }
724                var secondaryContainer = $(secondarySelector);
725                existing = secondaryContainer.find('[data-cid="' + article.id + '"]');
726                if (existing.length > 0) {
727                    if (article.canDisplay === true) {
728                        var secondaryTplItem = template(article);
729                        existing.replaceWith(secondaryTplItem);
730                    }
731                    else {
732                        secondaryContainer.find('[data-cid="' + article.id + '"]').remove();
733                    }
734                    return;
735                }
736                var crntPrimary = $(selector).find('[data-cid]').detach();
737                if (crntPrimary.length > 0) {
738                    secondaryContainer.prepend(crntPrimary);
739                    var maxListLength = tryParseInt(secondaryContainer.data('list-max'), 0);
740                    if (maxListLength > 0) {
741                        var existingLength = secondaryContainer.find('[data-cid]').length;
742                        while (existingLength > maxListLength) {
743                            secondaryContainer.find('[data-cid]:last-child').remove();
744                            existingLength = secondaryContainer.find('[data-cid]').length;
745                        }
746                    }
747                }
748                var newItem = template(article);
749                mainContainer.append(newItem);
750                setupViewSectionsNewLabels(selector);
751                setupViewSectionsNewLabels(secondarySelector);
752            }
753            else {
754                addTemplatedItem(template, article, selector);
755            }
756        }
757        utilities.addMainArticleItem = addMainArticleItem;
758        function getLastViewDateToCheck(listSelector) {
759            var now = new Date();
760            var newMinutes = $(listSelector).data('new-min') || 60;
761            var section = $(listSelector).data('section');
762            var sectionViewData = store('svd');
763            var defaultDateToCheck = new Date(now.getTime() - (newMinutes * 60000));
764            if (sectionViewData != null) {
765                var lastViewDate = sectionViewData[section];
766                if (lastViewDate != null) {
767                    var lvd = new Date(lastViewDate);
768                    return lvd < defaultDateToCheck ? defaultDateToCheck : lvd;
769                }
770            }
771            return defaultDateToCheck;
772        }
773        utilities.getLastViewDateToCheck = getLastViewDateToCheck;
774        function toggleNewLabels(listSelector, itemSelector) {
775            var lvdToCheck = getLastViewDateToCheck(listSelector);
776            $(listSelector).find(itemSelector).each(function (i, el) {
777                var idt = $(el).data('idt');
778                if (idt.length > 0) {
779                    var dt = new Date(idt);
780                    $(el).find('.label-new').toggleClass('is-new', lvdToCheck < dt);
781                }
782            });
783            //if (sectionViewData != null) {
784            //    var lastViewDate = sectionViewData[section];
785            //    if (lastViewDate != null) {
786            //        $(listSelector).find(itemSelector).each((i, el) => {
787            //            var idt = $(el).data('idt');
788            //            if (idt.length > 0) {
789            //                var dt = new Date(idt);
790            //                var lvd = new Date(lastViewDate);                            
791            //                $(el).find('.label-new').toggleClass('is-new', lvd < dt);
792            //            }
793            //        });
794            //        return;
795            //    }
796            //}
797            //var threshold = newMinutes * 60 * 1000;
798            //$(listSelector).find(itemSelector).each((i, el) => {
799            //    var idt = $(el).data('idt');
800            //    if (idt.length > 0) {
801            //        var dt = new Date(idt);
802            //        var diff = now.getTime() - dt.getTime();                    
803            //        $(el).find('.label-new').toggleClass('is-new',diff < threshold);
804            //    }
805            //});
806        }
807        utilities.toggleNewLabels = toggleNewLabels;
808        function setupViewSectionsNewLabels(selector) {
809            $(selector).each(function (index, section) {
810                var selector = $(section).data('target');
811                toggleNewLabels(section, selector);
812                if ($(section).is(':appeared')) {
813                    setTimeout(function () {
814                        $(section).find('.is-new').removeClass('is-new');
815                    }, 15000);
816                }
817            });
818        }
819        utilities.setupViewSectionsNewLabels = setupViewSectionsNewLabels;
820        function setupTracking() {
821            $('body').on('click', 'a[data-trackurl]', function () {
822                var url = $(this).data('trackurl');
823                if (url != null && url.length > 0) {
824                    $.post(url, function () { return true; });
825                    var item = $(this).closest('[data-cid]');
826                    if (item.length > 0) {
827                        item.addClass('viewed');
828                        var id = item.data('cid');
829                        viewArticle(id);
830                    }
831                }
832            });
833        }
834        utilities.setupTracking = setupTracking;
835        function setupCobrand() {
836            $('body').on('click', 'a.remove-cobrand', function () {
837                $.post('/users/removecobrand', function (result) {
838                    $('.cobrand-section').remove();
839                    var redirectUrl = updateQueryString('cbu', null, null);
840                    window.location.replace(redirectUrl);
841                });
842                return false;
843            });
844        }
845        utilities.setupCobrand = setupCobrand;
846        function setupChangeState() {
847            $('body').on('click', 'a.change-state', function () {
848                return mnd.utilities.modalFormFromUrlTemplated('/changestate', 'Update Your Location', 'Update Location', null, function (returnData, form) {
849                    if (returnData.success === true) {
850                        $(form).modal('hide');
851                        window.location.reload();
852                    }
853                    else {
854                        form.find('.modal-body').empty().html(returnData);
855                    }
856                    return returnData.success;
857                }, 'change-state');
858            });
859        }
860        utilities.setupChangeState = setupChangeState;
861        function setupDirectoryCard() {
862            var setupEmailForm = function ($frm) {
863                $frm.on('submit', function () {
864                    //console.log('submitted', $frm);
865                    var url = $frm.prop('action');
866                    var data = $frm.serialize();
867                    $.post(url, data, function (res) {
868                        $frm.find('.error-message').html('').toggle(!res.success);
869                        $frm.find('.success-message').html('').toggle(res.success);
870                        if (res.success) {
871                            $frm.find('.success-message').html(res.message);
872                        }
873                        else {
874                            $frm.find('.error-message').html(res.message);
875                        }
876                    });
877                    return false;
878                });
879            };
880            $('body').on('click', '[data-directory]', function () {
881                var listingId = $(this).data('directory');
882                if (listingId && listingId.length) {
883                    mnd.utilities.showHtmlPopup("/directory/card/".concat(listingId), 'Business Card', function (modal) {
884                        var $frm = $(modal).find('.directory-email-form');
885                        //console.log('shown', $frm);
886                        if ($frm && $frm.length) {
887                            setupEmailForm($frm);
888                        }
889                    }, 'directory-modal');
890                    return false;
891                }
892            });
893        }
894        utilities.setupDirectoryCard = setupDirectoryCard;
895        function formatDate(date, format) {
896            return moment(date).format(format);
897        }
898        utilities.formatDate = formatDate;
899        function isToday(date) {
900            var format = 'MM/dd/yy';
901            return moment(date).format(format) ==
902                moment(today).format(format);
903        }
904        utilities.isToday = isToday;
905        function setupShare() {
906            var originalCobrandEnabled = false;
907            var crntCobrandEnabled = false;
908            var setupShareArea = function (container) {
909                var container$ = $(container);
910                var shareTypes = container$.find('.share-types');
911                shareTypes.on('click', '[data-toggle="tab"]', function () {
912                    $(this).tab('show');
913                });
914                var shareArea = $(container).find('.share-area');
915                shareArea.on('click', '[data-share-type]', function () {
916                    var shareType = $(this).data('share-type');
917                    var shareUrl = $(this).data('share-target');
918                    //console.log(shareType, shareUrl);
919                    if (shareType.length > 0 && shareUrl.length > 0) {
920                        if (shareType == 'email') {
921                            $('.modal.share-popup-modal').modal('hide');
922                        }
923                        showShare(shareType, mnd.share.shareContent, shareUrl);
924                    }
925                    return false;
926                });
927                shareArea.on('click', '.dropdown-menu', function (e) {
928                    if ($(e.target).hasClass('dropdown-toggle')) {
929                        shareArea.find('.dropdown').removeClass('open');
930                        $(e.target).closest('.dropdown').toggleClass('open'); // next('ul').toggle();
931                    }
932                    var sharePopupLink = $(e.target).closest('.share-popup');
933                    if (sharePopupLink.length) {
934                        return true;
935                    }
936                    e.stopPropagation();
937                });
938                shareArea.on('change', '.share-link-type', function (e) {
939                    var target = $(this).data('target');
940                    if (target && target.length) {
941                        var linkArea = $(this).closest('.share-links');
942                        linkArea.find('.embed-link').hide();
943                        linkArea.find(target).show();
944                    }
945                });
946                shareArea.on('click', '.embed-link', function (e) {
947                    $(this).select().focus();
948                });
949                container$.on('click', '.btn-copy-url', function (e) {
950                    copyToClipboardFromGroup($(this).closest('.copy-group'));
951                });
952                container$.on('click', '.btn-shorten-url', function (e) {
953                    var copyGroup = $(this).closest('.copy-group');
954                    var shortenUrl = $(this).closest('.shorten-group').find('.shorten-url');
955                    var url = shortenUrl.data('target');
956                    if (url && url.length) {
957                        $.post('/share/shorten', { url: url }, function (res) {
958                            if (res.success == true) {
959                                shortenUrl.val(res.shortUrl);
960                                return copyToClipboardFromGroup(copyGroup);
961                            }
962                        });
963                    }
964                });
965                container$.on('click', '.copy-group .copy-val', function () {
966                    $(this).focus().select();
967                });
968                container$.find('.copy-btn').tooltip({ container: 'body' });
969                container$.on('copied', '.copy-group .copy-btn', function (event, message) {
970                    return $(this).attr('title', message).tooltip('fixTitle').tooltip('show').attr('title', 'Copy Link to Clipboard').tooltip('fixTitle');
971                });
972                var toggleCobrandForm = container$.find('.toggle-cobrand-form');
973                if (toggleCobrandForm && toggleCobrandForm.length) {
974                    var toggle = toggleCobrandForm.find('.switch').bootstrapSwitch();
975                    originalCobrandEnabled = toggle.bootstrapSwitch('state');
976                    crntCobrandEnabled = originalCobrandEnabled;
977                    toggle.on('switchChange.bootstrapSwitch', function (evt, state) {
978                        var frm = $(this).closest('form');
979                        var action = frm.prop('action');
980                        var data = { enabled: state };
981                        $.post(action, data, function (res) {
982                            container$.find('.modal-content').toggleClass('cobrand-enabled', res.enableCobrand);
983                            container$.find('.modal-content').toggleClass('cobrand-disabled', !res.enableCobrand);
984                            crntCobrandEnabled = res.enableCobrand;
985                        });
986                    });
987                }
988            };
989            //var shareArea = $('body').find('.share-area');
990            //setupShareArea('body');
991            $('body').on('click', '.share-popup', function (e, stype) {
992                var _a, _b, _c;
993                var target = $(e.target).data('target');
994                var shareContent = (_a = mnd['share']) === null || _a === void 0 ? void 0 : _a['shareContent'];
995                if (!target || !target.length) {
996                    target = shareContent === null || shareContent === void 0 ? void 0 : shareContent['shareModalUrl'];
997                }
998                if (mnd.utilities.isMobile() && ((_b = shareContent === null || shareContent === void 0 ? void 0 : shareContent.url) === null || _b === void 0 ? void 0 : _b.length) && ((_c = shareContent === null || shareContent === void 0 ? void 0 : shareContent.title) === null || _c === void 0 ? void 0 : _c.length) && navigator.share) {
999                    var navOptions = {
1000                        text: shareContent.title,
1001                        url: shareContent.url
1002                    };
1003                    navigator.share(navOptions);
1004                    return;
1005                }
1006                if (target && target.length) {
1007                    $.post(target, shareContent, function (data) {
1008                        showSharePopup(data, 'Share This Page', 'share-popup-modal', function (modal) {
1009                            setupShareArea(modal);
1010                            setupEmailShare(modal.find('.tab-pane.share-email'));
1011                            if (stype) {
1012                                switch (stype.toLowerCase()) {
1013                                    case "email":
1014                                        setTimeout(function () {
1015                                            modal.find('.nav-item.email').first().find('a').trigger('click');
1016                                        });
1017                                        break;
1018                                }
1019                            }
1020                            $(modal).on('hidden.bs.modal', function () {
1021                                if (originalCobrandEnabled != crntCobrandEnabled) {
1022                                    window.location.reload();
1023                                }
1024                            });
1025                        });
1026                    });
1027                }
1028                else {
1029                    var modalContent = $('#share-modal-content');
1030                    if (modalContent.length) {
1031                        showSharePopup(modalContent.html(), 'Share This Page', 'share-popup-modal', function (modal) {
1032                            setupShareArea(modal);
1033                            $(modal).on('hidden.bs.modal', function () {
1034                                if (originalCobrandEnabled != crntCobrandEnabled) {
1035                                    window.location.reload();
1036                                }
1037                            });
1038                        });
1039                    }
1040                }
1041                return false;
1042            });
1043        }
1044        utilities.setupShare = setupShare;
1045        function setupShareList() {
1046            $('body').find('.share-list').on('click', '[data-share-type]', function () {
1047                var shareType = $(this).data('share-type');
1048                var shareUrl = $(this).data('share-target');
1049                //var shareContent = $(this).data('share-content');
1050                var shareContent = {
1051                    title: $(this).data('share-title'),
1052                    summary: $(this).data('share-summary'),
1053                    shareDownloadUrl: $(this).data('share-download-url'),
1054                    shareDownloadUrlNoRates: $(this).data('share-download-url-norates'),
1055                    imageUrl: $(this).data('share-image-url'),
1056                    canHideRates: $(this).data('share-download-hiderates') == true,
1057                    shareSource: $(this).data('share-source')
1058                };
1059                //console.log(shareType, shareUrl);
1060                if (shareType.length > 0 && shareUrl.length > 0) {
1061                    showShare(shareType, shareContent, shareUrl);
1062                }
1063                return false;
1064            });
1065        }
1066        utilities.setupShareList = setupShareList;
1067        function pad(val, length, padVal) {
1068            if (padVal === void 0) { padVal = '0'; }
1069            var str = '' + val;
1070            while (str.length < length) {
1071                str = padVal + str;
1072            }
1073            return str;
1074        }
1075        utilities.pad = pad;
1076        function formatPrice(val, pricingMode, decimals, showPlus, separator, highPrecision) {
1077            if (decimals === void 0) { decimals = 2; }
1078            if (showPlus === void 0) { showPlus = false; }
1079            if (separator === void 0) { separator = '-'; }
1080            if (highPrecision === void 0) { highPrecision = false; }
1081            if (pricingMode !== 2) {
1082                return (showPlus && val >= 0 ? "+" : "") + val.toFixed(decimals);
1083            }
1084            var retVal = '';
1085            var neg = val < 0;
1086            var absVal = Math.abs(val);
1087            var fraction = (absVal - Math.floor(absVal)) * 32.0;
1088            if (highPrecision) {
1089                var highFraction = (fraction - Math.floor(fraction)) * 8.0;
1090                var remainder = '';
1091                if (highFraction >= 1) {
1092                    var roundedFraction = Math.round(highFraction);
1093                    switch (roundedFraction) {
1094                        case 2:
1095                            remainder = '<span style="font-size:9px;"><sup>1</sup>&frasl;<sub>4</sub></span>';
1096                            break;
1097                        case 4:
1098                            remainder = '<span style="font-size:9px;"><sup>1</sup>&frasl;<sub>2</sub></span>';
1099                            break;
1100                        case 6:
1101                            remainder = '<span style="font-size:9px;"><sup>3</sup>&frasl;<sub>4</sub></span>';
1102                            break;
1103                        default:
1104                            remainder = '<span style="font-size:9px;"><sup>' +
1105                                highFraction +
1106                                '</sup>&frasl;<sub>8</sub></span>';
1107                            break;
1108                    }
1109                }
1110                retVal = Math.floor(absVal) + separator + pad(Math.floor(fraction).toString(), 2) + remainder;
1111            }
1112            else {
1113                retVal = Math.floor(absVal).toString() + separator + pad(Math.round(fraction).toString(), 2);
1114            }
1115            var prefix = neg ? '-' : (showPlus ? '+' : '');
1116            return prefix + retVal;
1117        }
1118        utilities.formatPrice = formatPrice;
1119        function showShare(shareType, shareContent, shareUrl) {
1120            if (shareContent.title == null || shareContent.title.length == 0) {
1121                shareContent.title = document.title;
1122            }
1123            if (shareContent.summary == null || shareContent.summary.length == 0) {
1124                shareContent.summary = $('meta[property=description]').attr("content");
1125            }
1126            if (shareContent.imageUrl == null || shareContent.imageUrl.length == 0) {
1127                shareContent.imageUrl = $('meta[property="og:image"]').attr("content");
1128            }
1129            switch (shareType) {
1130                case "email":
1131                    showEmailShare(shareContent, shareUrl);
1132                    break;
1133                case "social":
1134                    showSocialShare(shareContent, shareUrl);
1135                    break;
1136                case "download":
1137                    showPrintShare(shareContent, shareUrl);
1138                    break;
1139                case "external":
1140                    showLinkShare(shareContent, shareUrl);
1141                    break;
1142            }
1143        }
1144        utilities.showShare = showShare;
1145        function showEmailShare(shareContent, shareUrl) {
1146            $.post(shareUrl, shareContent, function (formContent) {
1147                var vm = {
1148                    title: '',
1149                    formContent: formContent,
1150                    saveButtonText: 'Send Email',
1151                    modalClass: 'share share-email',
1152                    cancelButtonText: 'Cancel'
1153                };
1154                showModal(vm, modalTemplate, function (modal) {
1155                    var form = modal.find('form');
1156                    var action = form.prop('action');
1157                    if (form.length > 0) {
1158                        modal.on('keypress', function (e) {
1159                            if (e.which === 13) {
1160                                modal.find('.btn.save').trigger('click');
1161                                return false;
1162                            }
1163                        });
1164                        $(modal).on('click', '.btn-choose', function (evt) {
1165                            var target = $(evt.currentTarget).data('target');
1166                            $(modal).find('.email-options').hide();
1167                            $(modal).find(target).show();
1168                            return false;
1169                        });
1170                        $(modal).on('click', '.choose-option', function (evt) {
1171                            $(modal).find('.option').hide();
1172                            $(modal).find('.email-options').show();
1173                            return false;
1174                        });
1175                        $(modal).on('click', '.btn.save', function (evt) {
1176                            var data = form.serialize();
1177                            var shareData = {
1178                                shareEmail: form.find('#ShareEmail').val(),
1179                                shareName: form.find('#ShareName').val()
1180                            };
1181                            store('shareData', shareData);
1182                            $.post(action, data, function (returnData) {
1183                                if (returnData.success === true) {
1184                                    modal.modal('hide');
1185                                    //showInfo('Email Sent', returnData.message, 'main>.body-content>.container', null, 'alert-fixed alert-share');
1186                                }
1187                                else {
1188                                    modal.find('.modal-body').html(returnData);
1189                                    form = modal.find('form');
1190                                    if (form.length == 0) {
1191                                        modal.find('.btn.save').hide();
1192                                        modal.find('.btn.btn-default').html('Close');
1193                                    }
1194                                }
1195                            });
1196                            return false;
1197                        }).on('hidden.bs.modal', function () {
1198                            modal.remove();
1199                        });
1200                        modal.find('input:visible:enabled').first().focus();
1201                        //Setup form - set content
1202                        //console.log(shareContent);
1203                        form.find('.share-title').html(shareContent.title);
1204                        form.find('.share-summary').html(shareContent.summary);
1205                        form.find('#ShareContentTitle').val(shareContent.title);
1206                        form.find('#ShareContentDescription').val(shareContent.summary);
1207                        form.find('#DisplayUrl').val(shareContent.url);
1208                        form.find('#DownloadUrl').val(shareContent.downloadUrl);
1209                        var shareData = store('shareData');
1210                        if (shareData != null) {
1211                            if (form.find('#ShareEmail').val().length == 0) {
1212                                form.find('#ShareEmail').val(shareData.shareEmail);
1213                            }
1214                            if (form.find('#ShareName').val().length == 0) {
1215                                form.find('#ShareName').val(shareData.shareName);
1216                            }
1217                        }
1218                    }
1219                    else {
1220                        modal.find('.modal-footer').hide();
1221                    }
1222                });
1223            });
1224        }
1225        function setupEmailShare(container) {
1226            $(container).on('click', '.btn.send-email', function (evt) {
1227                var form = $(evt.target).closest('form');
1228                var action = form.prop('action');
1229                var data = form.serialize();
1230                var shareData = {
1231                    shareEmail: form.find('#ShareEmail').val(),
1232                    shareName: form.find('#ShareName').val()
1233                };
1234                store('shareData', shareData);
1235                $.post(action, data, function (returnData) {
1236                    var emailForm = form.closest('.email-form');
1237                    emailForm.html(returnData);
1238                    var msg = emailForm.find('.success-message');
1239                    if (msg && msg.length) {
1240                        showSuccess(msg.html(), null, container, null, 'share-email-success');
1241                    }
1242                });
1243                return false;
1244            });
1245        }
1246        function showSocialShare(shareContent, shareUrl) {
1247            showShareModal(shareContent, shareUrl, 'Share this via Social Network');
1248        }
1249        function showPrintShare(shareContent, shareUrl) {
1250            showShareModal(shareContent, shareUrl, 'Download / Print this Page');
1251        }
1252        function showLinkShare(shareContent, shareUrl) {
1253            showShareModal(shareContent, shareUrl, 'Share this Page URL', function (modal) {
1254                $(modal).on('click', '.embed-link', function () {
1255                    $(this).select().focus();
1256                });
1257            });
1258        }
1259        function showShareModal(shareContent, shareUrl, title, onShown) {
1260            var _this = this;
1261            if (onShown === void 0) { onShown = null; }
1262            $.post(shareUrl, shareContent, function (body) {
1263                var vm = {
1264                    title: title,
1265                    body: body,
1266                    showSave: false,
1267                    modalClass: 'share'
1268                };
1269                showModal(vm, previewTemplate, function (modal) {
1270                    if (onShown != null) {
1271                        onShown.apply(_this, [modal]);
1272                    }
1273                });
1274            });
1275        }
1276        function setupVideoPopups(selector) {
1277            $(selector).on('click', '.video-item a', function () {
1278                var $row = $(this).closest('[data-cid]');
1279                if ($row != null && $row.length) {
1280                    var vid = $row.data('cid');
1281                    if (vid != null && vid.length) {
1282                        viewArticle(vid);
1283                        $row.addClass('viewed');
1284                        $.post('/video/embed', { id: vid }, function (vidData) {
1285                            if (vidData.success === true) {
1286                                if (vidData.video.embed.length > 0) {
1287                                    //console.log('showing embed', vidData.video.embed);
1288                                    mnd.utilities.showPopup(vidData.video.embed, vidData.video.title, 'video', function (modal) {
1289                                        $(modal).fitVids({
1290                                            customSelector: 'iframe'
1291                                        });
1292                                    });
1293                                }
1294                                else {
1295                                    window.open(vidData.videoUrl);
1296                                }
1297                            }
1298                        });
1299                        return false;
1300                    }
1301                }
1302            });
1303        }
1304        utilities.setupVideoPopups = setupVideoPopups;
1305        function viewSection(section) {
1306            var sectionViewData = store('svd') || {};
1307            sectionViewData[section] = new Date();
1308            store('svd', sectionViewData);
1309        }
1310        utilities.viewSection = viewSection;
1311        function fixItemHeightsSiblingLists(mainSelector, itemSelector) {
1312            var height = 0;
1313            $(mainSelector).find(itemSelector).each(function (i, item) {
1314                var itemHeight = $(item).outerHeight();
1315                if (itemHeight > height) {
1316                    height = itemHeight;
1317                }
1318            });
1319            $(mainSelector).find(itemSelector).css({ 'height': height + 'px' });
1320        }
1321        utilities.fixItemHeightsSiblingLists = fixItemHeightsSiblingLists;
1322        function viewArticle(articleId) {
1323            var articleViewData = store('avd') || [];
1324            if (articleViewData.indexOf(articleId) < 0) {
1325                articleViewData.push(articleId);
1326            }
1327            if (articleViewData.length > 100) {
1328                var reducedData = articleViewData.slice(5);
1329                store('avd', reducedData);
1330            }
1331            else {
1332                store('avd', articleViewData);
1333            }
1334        }
1335        utilities.viewArticle = viewArticle;
1336        function getViewedArticles(articleIds) {
1337            var viewedArticles = [];
1338            var articleViewData = store('avd') || [];
1339            if (articleViewData.length === 0) {
1340                return viewedArticles;
1341            }
1342            for (var _i = 0, articleIds_1 = articleIds; _i < articleIds_1.length; _i++) {
1343                var articleId = articleIds_1[_i];
1344                if (articleViewData.indexOf(articleId) >= 0) {
1345                    viewedArticles.push(articleId);
1346                }
1347            }
1348            return viewedArticles;
1349        }
1350        utilities.getViewedArticles = getViewedArticles;
1351        function editComment(editUrl, commentArea, editSuccessCallback) {
1352            var _this = this;
1353            $.get(editUrl, function (data) {
1354                if (data.success === true) {
1355                    var commentHeight = commentArea.find('.comment-text').outerHeight() + 25;
1356                    var vm = { content: data.content, height: commentHeight };
1357                    var editForm = editCommentTemplate(vm);
1358                    commentArea.find('.comment-text').hide().after(editForm);
1359                    commentArea.find('.comment-actions').hide();
1360                    commentArea.addClass('editing');
1361                    var $frm_1 = commentArea.find('.edit-comment-form');
1362                    var resetForm_1 = function () {
1363                        commentArea.find('.comment-text').show();
1364                        commentArea.find('.comment-actions').show();
1365                        commentArea.removeClass('editing');
1366                        $frm_1.remove();
1367                    };
1368                    $frm_1.on('click', '.btn.cancel', function () {
1369                        resetForm_1();
1370                        return false;
1371                    });
1372                    $frm_1.on('click', '.btn.save', function () {
1373                        $.post(editUrl, $frm_1.serialize(), function (res) {
1374                            if (res.success === true) {
1375                                if (editSuccessCallback != null) {
1376                                    editSuccessCallback.apply(_this, [res]);
1377                                }
1378                            }
1379                            else {
1380                                $frm_1.find('.field-validation-error').remove();
1381                                $('<span class="field-validation-error" />').html(res.message).appendTo($frm_1);
1382                            }
1383                        });
1384                        return false;
1385                    });
1386                }
1387            });
1388        }
1389        utilities.editComment = editComment;
1390        function editAnswer(editUrl, answerArea, formShowCallback, editSuccessCallback) {
1391            var _this = this;
1392            $.get(editUrl, function (data) {
1393                if (data.success === true) {
1394                    var answerHeight = answerArea.find('.answer-body').outerHeight() + 25;
1395                    var vm = { content: data.content, height: answerHeight };
1396                    var editForm = editAnswerTemplate(vm);
1397                    answerArea.find('.answer-body').hide().after(editForm);
1398                    answerArea.find('.mod-actions').hide();
1399                    answerArea.addClass('editing');
1400                    var $frm_2 = answerArea.find('.edit-answer-form');
1401                    var resetForm_2 = function () {
1402                        answerArea.find('.answer-body').show();
1403                        answerArea.find('.mod-actions').show();
1404                        answerArea.removeClass('editing');
1405                        $frm_2.remove();
1406                    };
1407                    if (formShowCallback != null) {
1408                        formShowCallback.apply(_this, [$frm_2]);
1409                    }
1410                    $frm_2.on('click', '.btn.cancel', function () {
1411                        resetForm_2();
1412                        return false;
1413                    });
1414                    $frm_2.on('click', '.btn.save', function () {
1415                        $.post(editUrl, $frm_2.serialize(), function (res) {
1416                            if (res.success === true) {
1417                                if (editSuccessCallback != null) {
1418                                    editSuccessCallback.apply(_this, [res]);
1419                                }
1420                            }
1421                            else {
1422                                $frm_2.find('.field-validation-error').remove();
1423                                $('<span class="field-validation-error" />').html(res.message).appendTo($frm_2);
1424                            }
1425                        });
1426                        return false;
1427                    });
1428                }
1429            });
1430        }
1431        utilities.editAnswer = editAnswer;
1432        function setupSavedItems() {
1433            $.post('/manage/saveditems', function (res) {
1434                if (res.success === true) {
1435                    //itemIds
1436                    $('[data-save-item-id]').removeClass('saved'); //.find('.save-text').html('Save Page (' + res.itemIds.length + ' Saved Pages)');
1437                    $.each(res.itemIds, function (index, item) {
1438                        $('[data-save-item-id="' + item + '"]').addClass('saved');
1439                        $('[data-display-save-item-id="' + item + '"]').addClass('saved');
1440                    });
1441                    $('.saved[data-save-item-type]').prop('title', 'Remove this Page from your saved pages.').find('.save-text').html('<span class="hidden-xs hidden-sm">Page </span>Saved');
1442                    updateSavedPageCount(res.itemIds.length);
1443                }
1444            });
1445            $('body').on('click', '[data-save-item-id]', function (evt) {
1446                var $lnk = $(evt.currentTarget);
1447                var itemId = $lnk.data('saveItemId');
1448                var itemType = $lnk.data('saveItemType');
1449                toggleSavedItem(itemId, itemType);
1450                return false;
1451            });
1452        }
1453        utilities.setupSavedItems = setupSavedItems;
1454        function setupAlertPreviews() {
1455            $('.sub-newsletter').on('click', '.preview', function (e) {
1456                var url = $(this).prop('href');
1457                showHtmlInIframePopup(url, 'email email-iframe', 'Preview');
1458                return false;
1459            });
1460        }
1461        utilities.setupAlertPreviews = setupAlertPreviews;
1462        function toggleSavedItem(itemId, itemType, callback) {
1463            if (callback === void 0) { callback = null; }
1464            $.post('/manage/togglesaveditem', { itemId: itemId, itemType: itemType, title: document.title }, function (res) {
1465                if (res.success === true) {
1466                    $('[data-display-save-item-id="' + res.itemId + '"]').toggleClass('saved', res.saved === true);
1467                    $('[data-save-item-id="' + res.itemId + '"]').toggleClass('saved', res.saved === true);
1468                    var title = res.saved === true
1469                        ? 'Remove this Page from your saved pages.'
1470                        : 'Save this Page';
1471                    var saveText = res.saved === true
1472                        ? '<span class="hidden-xs hidden-sm">Page </span>Saved'
1473                        : 'Save<span class="hidden-xs hidden-sm"> Page</span>';
1474                    $('[data-save-item-id="' + res.itemId + '"]').prop('title', title);
1475                    $('[data-save-item-id="' + res.itemId + '"]').find('.save-text').each(function (e, val) {
1476                        var item = $(val);
1477                        if (res.saved && item.data('saved-text')) {
1478                            $(val).html(item.data('saved-text'));
1479                        }
1480                        else if (!res.saved && item.data('save-text')) {
1481                            $(val).html(item.data('save-text'));
1482                        }
1483                        else {
1484                            $(val).html(saveText);
1485                        }
1486                    });
1487                    $('.saved-page-count').find('.save-text').html(res.savedItemCount);
1488                    if (callback != null) {
1489                        callback.apply(null, [res.itemId]);
1490                    }
1491                }
1492            });
1493        }
1494        utilities.toggleSavedItem = toggleSavedItem;
1495        function updateSavedPageCount(pageCount) {
1496            var title = 'View Your ' + pageCount + ' Saved Page';
1497            if (pageCount === 0) {
1498                title = 'You have 0 Saved Pages';
1499            }
1500            if (pageCount > 1) {
1501                title += 's';
1502            }
1503            $('.saved-page-count').prop('title', title);
1504            $('.saved-page-count').find('.save-text').html(pageCount);
1505        }
1506        function setupAdminMenu() {
1507            var _this = this;
1508            $('.admin-menu-toggle').on('click', function () {
1509                //console.log('opening toggle');
1510                var menuContent = $('.modal-admin-controls').html();
1511                _this.showPopup(menuContent, 'MND Admin Menu', 'admin-modal');
1512                return false;
1513            });
1514        }
1515        utilities.setupAdminMenu = setupAdminMenu;
1516        function s4() {
1517            return Math.floor((1 + Math.random()) * 0x10000)
1518                .toString(16)
1519                .substring(1);
1520        }
1521        function guid() {
1522            return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
1523                s4() + '-' + s4() + s4() + s4();
1524        }
1525        utilities.guid = guid;
1526        function setInputFilter(textbox, inputFilter) {
1527            ["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function (event) {
1528                textbox.addEventListener(event, function () {
1529                    if (inputFilter(this.value)) {
1530                        this.oldValue = this.value;
1531                        this.oldSelectionStart = this.selectionStart;
1532                        this.oldSelectionEnd = this.selectionEnd;
1533                    }
1534                    else if (this.hasOwnProperty("oldValue")) {
1535                        this.value = this.oldValue;
1536                        this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
1537                    }
1538                });
1539            });
1540        }
1541        utilities.setInputFilter = setInputFilter;
1542        //export function setInputFilterCallback(textbox, inputFilter) {
1543        //  ["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function(event) {
1544        //    textbox.addEventListener(event, function() {
1545        //      var that = this;
1546        //      inputFilter(this,
1547        //        function(result) {
1548        //          if (result.valid) {
1549        //            that.oldValue = result.value;
1550        //            that.oldSelectionStart = that.selectionStart;
1551        //            that.oldSelectionEnd = that.selectionEnd;
1552        //          } else if (that.hasOwnProperty("oldValue")) {
1553        //            that.value = that.oldValue;
1554        //            that.setSelectionRange(that.oldSelectionStart, that.oldSelectionEnd);
1555        //          }
1556        //        });
1557        //    });
1558        //  });
1559        //}
1560        function isNumeric(charCode) {
1561            if (charCode > 31 && (charCode < 48 || charCode > 57)) {
1562                return false;
1563            }
1564            return true;
1565        }
1566        utilities.isNumeric = isNumeric;
1567        function navigateToUrl(url) {
1568            window.location.href = url;
1569        }
1570        utilities.navigateToUrl = navigateToUrl;
1571        function setUserCobrandUrl(cobrandUrl) {
1572            if (cobrandUrl && cobrandUrl.length) {
1573                //var myFile = document.location.toString();
1574                window.history.pushState(null, null, "#@" + cobrandUrl);
1575                //if (myFile.match('#')) {
1576                //} else {
1577                //  window.history.pushState(null, null, "@" + cobrandUrl)
1578                //}
1579            }
1580        }
1581        utilities.setUserCobrandUrl = setUserCobrandUrl;
1582        function objectifyForm(formArray) {
1583            var returnArray = {};
1584            for (var i = 0; i < formArray.length; i++) {
1585                returnArray[formArray[i]['name']] = formArray[i]['value'];
1586            }
1587            return returnArray;
1588        }
1589        utilities.objectifyForm = objectifyForm;
1590        function copyToClipboardFromGroup(grp$) {
1591            var copyText, copyText$, err, success;
1592            copyText$ = grp$.find('.copy-val');
1593            if (copyText$.length > 0) {
1594                copyText = copyText$[0];
1595                try {
1596                    copyText.select();
1597                    success = document.execCommand('copy');
1598                    if (success === true) {
1599                        return grp$.find('.copy-btn').trigger('copied', ['Copied!']);
1600                    }
1601                    else {
1602                        return grp$.find('.copy-btn').trigger('copied', ['Copy with Ctrl-c']);
1603                    }
1604                }
1605                catch (_error) {
1606                    err = _error;
1607                    return grp$.find('.copy-btn').trigger('copied', ['Copy with Ctrl-c']);
1608                }
1609            }
1610        }
1611        utilities.copyToClipboardFromGroup = copyToClipboardFromGroup;
1612        ;
1613        function updateQueryString(key, value, url) {
1614            var hash, re, separator;
1615            if (!url) {
1616                url = window.location.href;
1617            }
1618            re = new RegExp('([?&])' + key + '=.*?(&|#|$)(.*)', 'g
1618i');
1619            hash = void 0;
1620            if (re.test(url)) {
1621                if (typeof value !== 'undefined' && value !== null) {
1622                    return url.replace(re, '$1' + key + '=' + value + '$2$3');
1623                }
1624                else {
1625                    hash = url.split('#');
1626                    url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
1627                    if (typeof hash[1] !== 'undefined' && hash[1] !== null) {
1628                        url += '#' + hash[1];
1629                    }
1630                    return url;
1631                }
1632            }
1633            else {
1634                if (typeof value !== 'undefined' && value !== null) {
1635                    separator = url.indexOf('?') !== -1 ? '&' : '?';
1636                    hash = url.split('#');
1637                    url = hash[0] + separator + key + '=' + value;
1638                    if (typeof hash[1] !== 'undefined' && hash[1] !== null) {
1639                        url += '#' + hash[1];
1640                    }
1641                    return url;
1642                }
1643                else {
1644                    return url;
1645                }
1646            }
1647        }
1648        utilities.updateQueryString = updateQueryString;
1649        function appendQueryString(value, url) {
1650            if (!url) {
1651                url = window.location.href;
1652            }
1653            if (url.indexOf('?') !== -1) {
1654                url += '&' + value;
1655            }
1656            else {
1657                url += '?' + value;
1658            }
1659            return url;
1660        }
1661        utilities.appendQueryString = appendQueryString;
1662        function isMobile() {
1663            return /Android|webOS|iPhone|iPad|iPod|Opera Mini/i.test(navigator.userAgent);
1664        }
1665        utilities.isMobile = isMobile;
1666    })(utilities = mnd.utilities || (mnd.utilities = {}));
1667})(mnd || (mnd = {}));
1668//# sourceMappingURL=utilities.js.map

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.