1/* ======================================================= 2 * 3 * Whatsapp Chat Support 4 * Version: 1.1 5 * By castlecode 6 * 7 * Contact: http://codecanyon.net/user/castlecode 8 * Created: December 10, 2018 9 * 10 * Copyright (c) 2018, castlecode. All rights reserved. 11 * Available only in http://codecanyon.net/ 12 * 13 * --------------------------------- 14 * CONTENTS 15 * --------------------------------- 16 * 17 * [A] WHATSAPP CHAT SUPPORT CLASS 18 * [B] DEFAULTS 19 * [C] INIT 20 * [1] SETUP 21 * [2] ON CLICK 22 * [3] OPEN / CLOSE 23 * [4] GO TO WHATSAPP 24 * [5] CHECK AVAILABILITY 25 * [D] WHATSAPP CHAT SUPPORT PLUGIN 26 * 27 * ======================================================= */ 28 29(function( window, $, undefined ){ 30 31 /* ====================================================================== * 32 [A] WHATSAPP CHAT SUPPORT CLASS 33 * ====================================================================== */ 34 35 var WhatsappChatSupport = function(container, options){ 36 this.init(container, options); 37 } 38 39 /* ====================================================================== * 40 [B] DEFAULTS 41 * ====================================================================== */ 42 43 WhatsappChatSupport.DEFAULTS = { 44 45 // Options 46 47 popupFx : '1', // The popup effect from 0 till 14 48 now : '', // When empty it will use the date and time from the user browser if not you can assign it with PHP maybe (which will be the date of the server) format: YYYY-MM-DD HH:mm:ss (2019-12-30 18:30:00) 49 timezone : 'America/Chicago', // When using the date and time from the user browser you can transform it to your current timezone (in case your user is in a different timezone) 50 notAvailableMsg : 'I am not available today', // message when its not an available day or once the available hours have passed 51 almostAvailableMsg : 'I will be available soon', // if today is an available day and before the time starts 52 defaultMsg : 'Hi, I have some questions about this page: {{url}}!', // default support msg 53 debug : false, // some messages for debug purposes 54 55 // Events 56 57 onPopupOpen : function(){}, 58 onPopupClose : function(){}, 59 beforeGoingSetText : function(text){ return text; }, // add by jjhiguera 3 abril 2020 12:27 horas 60 whenGoingToWhatsApp : function(number, text){}, 61 62 }; 63 64 /* ====================================================================== * 65 [C] INIT 66 * ====================================================================== */ 67 68 WhatsappChatSupport.prototype.init = function(container, options){ 69 70 /* ====================================================================== * 71 [1] SETUP 72 * ====================================================================== */ 73 74 /* SETTINGS */ 75 76 var settings = $.extend(true, {}, WhatsappChatSupport.DEFAULTS, options); 77 78 settings.defaultMsg = settings.defaultMsg.split('{{url}}').join(window.location.href); 79 80 /* VARS */ 81 82 var $container = $(container); 83 var $button = $container.find('.wcs_button'); 84 var $label = $container.find('.wcs_button_label'); 85 var $popup = $container.find('.wcs_popup'); 86 87 var popup_input = $container.find('.wcs_popup_input'); 88 var popup_persons = $container.find('.wcs_popup_person_container'); 89 90 /* INIT */ 91 92 $container.addClass('wcs-effect-'+settings.popupFx); 93 94 var debug = $('<div class="wcs_debug"></div>') 95 96 if(settings.debug){ 97 $('body').append(debug); 98 } 99 100 /* ====================================================================== * 101 [2] ON CLICK 102 * ====================================================================== */ 103 104 /* OPEN POPUP */ 105 106 $button.on('click', function(){ 107 108 if($popup[0] != undefined){ 109 if($container.hasClass('wcs-show')){ 110 close_popup(); 111 }else{ 112 open_popup() 113 } 114 } 115 116 }) 117 118 $label.on('click', function(){ 119 120 if($popup[0] != undefined){ 121 if($container.hasClass('wcs-show')){ 122 close_popup(); 123 }else{ 124 open_popup() 125 } 126 } 127 128 }) 129 130 /* CLOSE POPUP */ 131 132 $popup.find('.wcs_popup_close').on('click', function(){ 133 close_popup(); 134 }); 135 136 /* BUTTON CLICK WITHOUT POPUP */ 137 138 $button.on('click', function(){ 139 var $this = $(this) 140 141 if($this.attr('data-number') != undefined && !$this.hasClass('wcs_button_person_offline')){ 142 go_to_whatsapp($this.attr('data-number'), settings.defaultMsg); 143 } 144 }) 145
146 /* POPUP CHAT (SINGLE PERSON) */ 147 148 popup_input.on('click', '.fa', function(){ 149 var $this = $(this); 150 151 go_to_whatsapp(popup_input.attr('data-number'), popup_input.find('input[type="text"]').val()); 152 }); 153 154 popup_input.find('input[type="text"]').keypress(function (e) { 155 if (e.which == 13) { 156 var $this = $(this); 157 158 go_to_whatsapp(popup_input.attr('data-number'), popup_input.find('input[type="text"]').val()); 159 } 160 }); 161 162 /* CLICK ON A REPRESENTATIVE (MULTIPLE-PERSON) */ 163 164 popup_persons.on('click', '.wcs_popup_person', function(){ 165 var $this = $(this); 166 if(!$this.hasClass('wcs_popup_person_offline')){ 167 go_to_whatsapp($this.attr('data-number'), settings.defaultMsg); 168 } 169 }) 170 171 /* ====================================================================== * 172 [3] OPEN / CLOSE 173 * ====================================================================== */ 174 175 function open_popup(){ 176 settings.onPopupOpen(); 177 close_all_popup(); 178 $label.addClass('wcs_button_label_hide'); 179 180 $container.addClass('wcs-show'); 181 setTimeout(function(){ 182 $popup.find('input').val(settings.defaultMsg).focus(); 183 }, 50); 184 } 185 186 function close_popup(){ 187 settings.onPopupClose(); 188 $label.removeClass('wcs_button_label_hide'); 189 190 $container.removeClass('wcs-show'); 191 $container.find('.wcs_popup_input').find('input[type="text"]').val(''); 192 } 193 194 function close_all_popup(){ 195 var all_containers = $('.whatsapp_chat_support'); 196 197 all_containers.each(function(){ 198 var $this = $(this); 199 200 $this.removeClass('wcs-show'); 201 $this.find('.wcs_popup_input').find('input[type="text"]').val(''); 202 }); 203 } 204 205 /* ====================================================================== * 206 [4] GO TO WHATSAPP 207 * ====================================================================== */ 208 209 function go_to_whatsapp(number, text){ 210 text = settings.beforeGoingSetText(text); // add by jjhiguera 3 abril 2020 12:27 horas 211 settings.whenGoingToWhatsApp(number, text); 212 213 close_popup(); 214 var WhatsAppUrl = 'https://api.whatsapp.com/send'; 215 216 if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { 217 WhatsAppUrl = 'https://api.whatsapp.com/send'; 218 } 219 220 var url = WhatsAppUrl+'?phone='+number+'&text='+text; 221 var win = window.open(url, '_blank'); 222 win.focus(); 223 } 224 225 /* ====================================================================== * 226 [5] CHECK AVAILABILITY 227 * ====================================================================== */ 228 229 var now = moment(); 230 231 debug.append("<div><strong>Original Date</strong> "+now.format('YYYY-MM-DD HH:mm:ss')+" <br><strong>UTC Offsset</strong> "+(now.utcOffset()/60)+"</div>"); 232 233 if(settings.timezone != '' && settings.now == ''){ // set timezone 234 now.tz(settings.timezone); 235 236 debug.append("<div><strong>Setting Timezone</strong> "+now.format('YYYY-MM-DD HH:mm:ss')+" <br><strong>UTC Offsset</strong> "+(now.utcOffset()/60)+"</div>"); 237 } 238 239 if(settings.now != ''){ 240 now = moment(settings.now, 'YYYY-MM-DD HH:mm:ss'); 241 242 debug.append("<div><strong>Setting Manual Date</strong> "+now.format('YYYY-MM-DD HH:mm:ss')+" <br><strong>UTC Offsset</strong> "+(now.utcOffset()/60)+"</div>"); 243 } 244 245 /* BUTTON ONLY */ 246 247 if($button.attr('data-availability') != undefined){ 248 var available = is_available($.parseJSON($button.attr('data-availability'))); 249 250 if(available.is_available){ 251 // all good! 252 }else{ 253 $button.addClass('wcs_button_person_offline'); 254 $button.find('.wcs_button_person_status').html(available.almost_available ? settings.almostAvailableMsg : settings.notAvailableMsg); 255 } 256 } 257 258 /* SINGLE PERSON */ 259 260 if(popup_input.attr('data-availability') != undefined){ 261 var available = is_available($.parseJSON(popup_input.attr('data-availability'))); 262 263 if(available.is_available){ 264 // all good! 265 }else{ 266 popup_input.addClass('wcs_popup_input_offline'); 267 popup_input.html(available.almost_available ? settings.almostAvailableMsg : settings.notAvailableMsg); 268 } 269 } 270 271 /* MULTIPLE PERSON */ 272 273 popup_persons.find('.wcs_popup_person').each(function(){ 274 var $this = $(this); 275 276 if($this.attr('data-availability') != undefined){ 277 var available = is_available($.parseJSON($this.attr('data-availability'))); 278 279 if(available.is_available){ 280 // all good! 281 }else{ 282 $this.addClass('wcs_popup_person_offline'); 283 $this.find('.wcs_popup_person_status').html(available.almost_available ? settings.almostAvailableMsg : settings.notAvailableMsg); 284 } 285 286 } 287 }); 288 289 /* CHECK AVAILABILITY */ 290 291 function is_available(available){ 292 var is_available = false;
293 var almost_available = false; 294 295 for(var key in available) { 296 if(available.hasOwnProperty(key)){ 297 298 if(get_day_of_week(key) == now.day()){ 299 var start = moment($.trim(available[key].split('-')[0]), 'HH:mm'); // available[key] is in this format: 8:00-18:33 300 var end = moment($.trim(available[key].split('-')[1]), 'HH:mm'); // available[key] is in this format: 8:00-18:33 301 302 if (now.isAfter(start) && now.isBefore(end)) { 303 is_available = true; 304 }else if(now.isBefore(start)){ 305 almost_available = true; 306 } 307 308 } 309 } 310 } 311 312 return {'is_available' : is_available, 'almost_available' : almost_available}; 313 } 314 315 function get_day_of_week(name){ 316 name = name.toLowerCase(); 317 318 if(name == 'sunday'){ 319 return 0; 320 }else if(name == 'monday'){ 321 return 1; 322 }else if(name == 'tuesday'){ 323 return 2; 324 }else if(name == 'wednesday'){ 325 return 3; 326 }else if(name == 'thursday'){ 327 return 4; 328 }else if(name == 'friday'){ 329 return 5; 330 }else if(name == 'saturday'){ 331 return 6; 332 } 333 } 334 335 };//END OF INIT 336 337 /* ====================================================================== * 338 [D] WHATSAPP CHAT SUPPORT PLUGIN 339 * ====================================================================== */ 340 341 $.fn.whatsappChatSupport = function(options, content, callback) { 342 343 return this.each(function(key, value){ 344 var $this = $(this); 345 var data = $this.data('whatsappChatSupport') 346 347 // Initialize plugin 348 if (!data && typeof options != 'string'){ 349 $this.data('whatsappChatSupport', new WhatsappChatSupport(this, options)); 350 } 351 352 // Call method 353 if (data && typeof options == 'string'){ 354 data[options](content, callback); 355 } 356 }); 357 358 }; 359 360})( window, jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.