1// Popup messages 2//----------------------------------------------------------------- 3jQuery(document).ready(function(){ 4 "use strict"; 5 6 LOVESTORY_STORAGE['message_callback'] = null; 7 LOVESTORY_STORAGE['message_timeout'] = 5000; 8 9 jQuery('body').on('click', '#lovestory_modal_bg,.lovestory_message .lovestory_message_close', function (e) { 10 "use strict"; 11 lovestory_message_destroy(); 12 if (LOVESTORY_STORAGE['message_callback']) { 13 LOVESTORY_STORAGE['message_callback'](0); 14 LOVESTORY_STORAGE['message_callback'] = null; 15 } 16 e.preventDefault(); 17 return false; 18 }); 19}); 20 21 22// Warning 23function lovestory_message_warning(msg) { 24 "use strict"; 25 var hdr = arguments[1] ? arguments[1] : ''; 26 var icon = arguments[2] ? arguments[2] : 'cancel'; 27 var delay = arguments[3] ? arguments[3] : LOVESTORY_STORAGE['message_timeout']; 28 return lovestory_message({ 29 msg: msg, 30 hdr: hdr, 31 icon: icon, 32 type: 'warning', 33 delay: delay, 34 buttons: [], 35 callback: null 36 }); 37} 38 39// Success 40function lovestory_message_success(msg) { 41 "use strict"; 42 var hdr = arguments[1] ? arguments[1] : ''; 43 var icon = arguments[2] ? arguments[2] : 'check'; 44 var delay = arguments[3] ? arguments[3] : LOVESTORY_STORAGE['message_timeout']; 45 return lovestory_message({ 46 msg: msg, 47 hdr: hdr, 48 icon: icon, 49 type: 'success', 50 delay: delay, 51 buttons: [], 52 callback: null 53 }); 54} 55 56// Info 57function lovestory_message_info(msg) { 58 "use strict"; 59 var hdr = arguments[1] ? arguments[1] : ''; 60 var icon = arguments[2] ? arguments[2] : 'info'; 61 var delay = arguments[3] ? arguments[3] : LOVESTORY_STORAGE['message_timeout']; 62 return lovestory_message({ 63 msg: msg, 64 hdr: hdr, 65 icon: icon, 66 type: 'info', 67 delay: delay, 68 buttons: [], 69 callback: null 70 }); 71} 72 73// Regular 74function lovestory_message_regular(msg) { 75 "use strict"; 76 var hdr = arguments[1] ? arguments[1] : ''; 77 var icon = arguments[2] ? arguments[2] : 'quote'; 78 var delay = arguments[3] ? arguments[3] : LOVESTORY_STORAGE['message_timeout']; 79 return lovestory_message({ 80 msg: msg, 81 hdr: hdr, 82 icon: icon, 83 type: 'regular', 84 delay: delay, 85 buttons: [], 86 callback: null 87 }); 88} 89 90// Confirm dialog 91function lovestory_message_confirm(msg) { 92 "use strict"; 93 var hdr = arguments[1] ? arguments[1] : ''; 94 var callback = arguments[2] ? arguments[2] : null; 95 return lovestory_message({ 96 msg: msg, 97 hdr: hdr, 98 icon: 'help', 99 type: 'regular', 100 delay: 0, 101 buttons: ['Yes', 'No'], 102 callback: callback 103 }); 104} 105 106// Modal dialog 107function lovestory_message_dialog(content) { 108 "use strict"; 109 var hdr = arguments[1] ? arguments[1] : ''; 110 var init = arguments[2] ? arguments[2] : null; 111 var callback = arguments[3] ? arguments[3] : null; 112 return lovestory_message({ 113 msg: content, 114 hdr: hdr, 115 icon: '', 116 type: 'regular', 117 delay: 0, 118 buttons: ['Apply', 'Cancel'], 119 init: init, 120 callback: callback 121 }); 122} 123 124// General message window 125function lovestory_message(opt) { 126 "use strict"; 127 var msg = opt.msg != undefined ? opt.msg : ''; 128 var hdr = opt.hdr != undefined ? opt.hdr : ''; 129 var icon = opt.icon != undefined ? opt.icon : ''; 130 var type = opt.type != undefined ? opt.type : 'regular'; 131 var delay = opt.delay != undefined ? opt.delay : LOVESTORY_STORAGE['message_timeout']; 132 var buttons = opt.buttons != undefined ? opt.buttons : []; 133 var init = opt.init != undefined ? opt.init : null; 134 var callback = opt.callback != undefined ? opt.callback : null; 135 // Modal bg 136 jQuery('#lovestory_modal_bg').remove(); 137 jQuery('body').append('<div id="lovestory_modal_bg"></div>'); 138 jQuery('#lovestory_modal_bg').fadeIn(); 139 // Popup window 140 jQuery('.lovestory_message').remove(); 141 var html = '<div class="lovestory_message lovestory_message_' + type + (buttons.length > 0 ? ' lovestory_message_dialog' : '') + '">' 142 + '<span class="lovestory_message_close iconadmin-cancel icon-cancel"></span>' 143 + (icon ? '<span class="lovestory_message_icon iconadmin-'+icon+' icon-'+icon+'"></span>' : '') 144 + (hdr ? '<h2 class="lovestory_message_header">'+hdr+'</h2>' : ''); 145 html += '<div class="lovestory_message_body">' + msg + '</div>'; 146 if (buttons.length > 0) { 147 html += '<div class="lovestory_message_buttons">'; 148 for (var i=0; i<buttons.length; i++) { 149 html += '<span class="lovestory_message_button">'+buttons[i]+'</span>'; 150 } 151 html += '</div>'; 152 } 153 html += '</div>'; 154 // Add popup to body 155 jQuery('body').append(html); 156 var popup = jQuery('body .lovestory_message').eq(0); 157 // Prepare callback on buttons click
158 if (callback != null) { 159 LOVESTORY_STORAGE['message_callback'] = callback; 160 jQuery('.lovestory_message_button').on('click', function(e) { 161 "use strict"; 162 var btn = jQuery(this).index(); 163 callback(btn+1, popup); 164 LOVESTORY_STORAGE['message_callback'] = null; 165 lovestory_message_destroy(); 166 }); 167 } 168 // Call init function 169 if (init != null) init(popup); 170 // Show (animate) popup 171 var top = jQuery(window).scrollTop(); 172 jQuery('body .lovestory_message').animate({top: top+Math.round((jQuery(window).height()-jQuery('.lovestory_message').height())/2), opacity: 1}, {complete: function () { 173 // Call init function 174 //if (init != null) init(popup); 175 }}); 176 // Delayed destroy (if need) 177 if (delay > 0) { 178 setTimeout(function() { lovestory_message_destroy(); }, delay); 179 } 180 return popup; 181} 182 183// Destroy message window 184function lovestory_message_destroy() { 185 "use strict"; 186 var top = jQuery(window).scrollTop(); 187 jQuery('#lovestory_modal_bg').fadeOut(); 188 jQuery('.lovestory_message').animate({top: top-jQuery('.lovestory_message').height(), opacity: 0}); 189 setTimeout(function() { jQuery('#lovestory_modal_bg').remove(); jQuery('.lovestory_message').remove(); }, 500); 190}
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.