1/* 2*Author: Kaumudy 3*Date: 19-10-2017 4*Description: util.js serves common methods 5*/ 6var KAUMUDI = KAUMUDI || {}; 7$(document).ready(function () { 8 KAUMUDI.utils.init(); 9}); 10KAUMUDI.utils = (function () { 11 /*************** 12 *Private Region* 13 ****************/ 14 function spawnNotification(theBody, theIcon, theTitle, link) { 15 var options = { 16 body: theBody, 17 icon: theIcon 18 } 19 var n = new Notification(theTitle, options); 20 setTimeout(function () { n.close.bind(n) }, 100000); 21 n.onclick = function () { 22 if (link) window.location.href = link; else window.focus(); 23 }; 24 } 25 function notifyPermission() { 26 // Let's check if the browser supports notifications 27 if (!("Notification" in window)) { 28 console.log("This browser does not support desktop notification"); 29 return false; 30 }else if (Notification && Notification.permission !== 'granted') { 31 Notification.requestPermission(function (permission) {}); 32 } 33 } 34 /************** 35 *Public Region* 36 ***************/ 37 return { 38 init: function () { 39 String.prototype.fmt = function () { 40 var s = this, 41 i = arguments.length; 42 while (i--) { 43 s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]); 44 } 45 return s; 46 }; 47 //Go-to-top 48 $(window).scroll(function () { 49 if ($(this).scrollTop() > 500) { $('#gotop').show(); $(".header-strip").addClass('hs-fixed'); } else { $('#gotop').hide(); $(".header-strip").removeClass('hs-fixed'); } 50 }); 51 $('#gotop').click(function () { 52 $("html, body").animate({ scrollTop: 0 }, 600); 53 return false; 54 }); 55 //footer-link-popups 56 $("a[data-modal]").click(function () { 57 //$('#modal').modal('toggle'); 58 $('body').addClass('modal-open'); 59 $('#modal').addClass('in'); 60 $('body').append('<div class="modal-backdrop fade in"></div>'); 61 $('#modal').css({ "display": "block" }); 62 $("#info-body").hide(); 63 $("#ploader").html("<img src='/info/assets/imgs/loading.gif' width='100%'/>").show(); 64 $("#info-body").load('/info/' + $(this).attr('data-modal') + '.html?v=' + Math.random()); 65 setTimeout(function () { $("#ploader").hide(); $("#info-body").show(); }, 2000); 66 }); 67 $("#modal").on('click', '[data-dismiss="modal"]', function () { 68 $('body').removeClass('modal-open'); 69 $('#modal').removeClass('in'); 70 $('body').find('.modal-backdrop').remove(); 71 $('#modal').css({ "display": "none" }); 72 $("#info-body").html(''); 73 }); 74 //$("a[data-cusmodal]").click(function () { 75 // $('#modal').modal('toggle'); 76 // $('#modal').addClass('in'); 77 // $("#info-body").hide(); 78 // $("#ploader").html("<img src='/info/assets/imgs/loading.gif' width='100%'/>").show(); 79 // $("#info-body").load('/info/' + $(this).attr('data-modal') + '.html?v=' + Math.random()); 80 // setTimeout(function () { $("#ploader").hide(); $("#info-body").show(); }, 2000); 81 //}); 82 //init methods 83 //notifyPermission(); 84 }, 85 setCookie: function (cname, cvalue, exdays) { 86 87 var d = new Date(); 88 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); 89 var expires = "expires=" + d.toUTCString(); 90 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 91 }, 92 getCookie: function (cname) { 93 var name = cname + "="; 94 var decodedCookie = decodeURIComponent(document.cookie); 95 var ca = decodedCookie.split(';'); 96 for (var i = 0; i < ca.length; i++) { 97 var c = ca[i]; 98 while (c.charAt(0) == ' ') { 99 c = c.substring(1); 100 } 101 if (c.indexOf(name) == 0) { 102 return c.substring(name.length, c.length); 103 } 104 } 105 return ""; 106 }, 107 showLoader: function (a) { 108 $("#load-backdrop,#load-img").removeClass('hide'); 109 }, 110 hideLoader: function () { 111 $("#load-backdrop,#load-img").removeClass('hide'); 112 $("#load-backdrop,#load-img").addClass('hide'); 113 }, 114 printItem: function (divName) { 115 var printContents = document.getElementById(divName).innerHTML; 116 var originalContents = document.body.innerHTML; 117 document.body.innerHTML = printContents; 118 window.print(); 119 document.body.innerHTML = originalContents; 120 }, 121 preventRightClick: function(a) { 122 $(document).on("contextmenu dragstart", function(b) { 123 if ($(b.target).is(a)) { 124 return false 125 } 126 }) 127 }, 128 sendAjaxPost: function (url, formData, resType, successCallback, errorCallback) { 129 $.ajax({ 130 type: 'POST', 131 url: url.charAt(0)=='/'?url:baseUrlEP + url, 132 data: formData, 133 dataType: resType, 134 processData: false, // tell jQuery not to process the data 135 contentType: false, // tell jQuery not to set contentType 136 success: successCallback, 137 error: errorCallback 138 }); 139 }, 140 sendAjaxGet: function (url, formData, resType, successCallback, errorCallback) { 141 $.ajax({ 142 type: 'GET', 143 url: url.charAt(0) == '/' ? url : baseUrlEP + url, 144 data: formData, 145 cache: false, 146 dataType: resType, 147 processData: false, // tell jQuery not to process the data 148 contentType: false, // tell jQuery not to set contentType 149 success: successCallback, 150 error: errorCallback 151 }); 152 }, 153 triggerNotification: function (theBody, theIcon, theTitle, link) { 154 if (!("Notification" in window)) { 155 console.log("This browser does not support system notifications"); 156 return false;
157 } 158 if (Notification.permission === "granted") { 159 spawnNotification(theBody, theIcon, theTitle, link); 160 } 161 // Otherwise, we need to ask the user for permission 162 else if (Notification.permission !== 'granted') { 163 Notification.requestPermission(function (permission) { 164 // If the user accepts, let's create a notification 165 if (permission === "granted") { 166 spawnNotification(theBody, theIcon, theTitle, link); 167 } 168 }); 169 } 170 }, 171 notificationTypes: { 172 MINIMALIST: 'minimalist', 173 WARNING: 'pastel-warning', 174 INFO: 'pastel-info', 175 DANGER: 'pastel-danger' 176 }, 177 showInAppNotification: function(icon, title, msg, url, type) {//@types:minimalist,pastel-warning,pastel-info,pastel-danger 178 $.notify({ 179 icon: icon, 180 title: title, 181 message: msg, 182 url: url, 183 target: "_blank" 184 }, { 185 type: type, 186 delay: 36000, 187 placement: { 188 from: 'bottom', 189 align: 'right' 190 }, 191 icon_type: 'image', 192 template: '<div data-notify="container" class="col-xs-11 col-sm-3 alert alert-{0}" role="alert">' + 193 '<button type="button" aria-hidden="true" class="close" data-notify="dismiss"><i class="fa fa-window-close" aria-hidden="true"></i></button>' + 194 '<img data-notify="icon" class="img-circle pull-left">' + 195 '<span data-notify="title">{1}</span>' + 196 '<span data-notify="message">{2}</span>' + 197 '</div>' 198 }); 199 document.getElementById('notify_audio').play(); 200 } 201 } 202})();
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.