1$(function(){ 2 var $popups = $('*[data-popup]'); 3 $popups.each(function() { 4 var popup = $(this).popup(); 5 }); 6}); 7 8(function($) { 9 var plugname = 'popup'; 10 11 var $screen = null; 12 var opentime = 0; 13 14 /** 15 * ã³ã³ã¹ãã©ã¯ã¿ 16 */ 17 var Class = function(popupWindow, options) { 18 this.popupWindow = popupWindow; 19 this.options = $.extend({}, $.fn[plugname].defaults, options, this.popupWindow.data()); 20 this.popupWindow.data(plugname, this); 21 22 this.popupWindow.hide().css({ 23 'z-index': (this.options['zindex'] + 1), 24 }).addClass('popup-window'); 25 26 var object = this; 27 $('*[data-popup_id=' + this.popupWindow.attr('id') + ']').bind('click', function (event) { 28 event.preventDefault(); 29 object.open(); 30 return false; 31 }); 32 33 // ãã¼ãæã«ã¦ã£ã³ãã¦ããªã¼ãã³ããã 34 if (object.isOpenOnload()) { 35 $(window).bind('load', function() { 36 setTimeout(function() { 37 object.open(); 38 }, 50 + object.options['open_onload_delay']); 39 }); 40 } 41 42 // éãã 43 this.popupWindow.find(this.options['selector_close']).bind('click', function(event) { 44 event.preventDefault(); 45 object.close(); 46 return false; 47 }); 48 49 // 次åãã表示ããªã 50 this.popupWindow.find(this.options['selector_undisplay_checkbox']).bind('change', function(event) { 51 event.preventDefault(); 52 object.changeUndisplay($(this)); 53 return false; 54 }); 55 56 // ãªã³ã¯å ãç¡ãã¢ã³ã«ã¼ã¯ãªã³ã¯ãç¡å¹ã«ãã 57 if (object.options['remove_link_if_empty_href']) { 58 this.popupWindow.find('a[href=""]').each(function() { 59 var $target = $(this); 60 $target.replaceWith($target.html()); 61 }); 62 } 63 64 this.popupWindow.find('a[href!=""]').each(function() { 65 var $target = $(this); 66 if ($target.attr('href') != '#') { 67 $target.bind('click', function() { 68 object.sendGaEvent('click'); 69 }); 70 } 71 }); 72 } 73 74 Class.prototype.open = function() { 75 this.openScreen(); 76 77 this.setPopupPosition(); 78 79 var object = this; 80 this.popupWindow.fadeIn(this.options['speed'], function() { 81 object.setPopupPosition(); 82 }); 83 84 object.sendGaEvent('open'); 85 opentime = (new Date()).getTime(); 86 87 return this; 88 }; 89 90 Class.prototype.isOpenOnload = function() { 91 if (this.options['open_onload']) { 92 var cookieValue = this.getCookie(); 93 if (!('undisplay' in cookieValue) || !cookieValue['undisplay']) { 94 if (this.options['expires_type'] == 'daily') { 95 var now = getToday(); 96 if (!('last_display_date' in cookieValue) || cookieValue['last_display_date'] != now) { 97 this.saveCookie($.extend(this.getCookie(), {'last_display_date': now}), this.options['cookie_expires']); 98 return true; 99 } 100 } else { 101 //this.saveCookie($.extend(this.getCookie(), {'undisplay': true}), 0); 102 return true; 103 } 104 } 105 } 106 107 return false; 108 } 109 110 Class.prototype.setPopupPosition = function() { 111 // var windowWidth = $(window).width(), 112 // windowHeight = $(window).height(), 113 // scrollTop = $(window).scrollTop(), 114 // popupWindowWidth = this.popupWindow.outerWidth(), 115 // popupWindowHeight = this.popupWindow.outerHeight(), 116 // left = Math.max(((windowWidth - popupWindowWidth) / 2), 10), 117 // top = Math.max(((windowHeight - popupWindowHeight) / 2), 10); 118 // 119 // //this.popupWindow.css({}); 120 } 121 122 Class.prototype.openScreen = function() { 123 if (!this.options['screen']) { 124 return; 125 } 126 127 if ($screen == null) { 128 $screen = $('<div/>'); 129 //$screen.hide().css({ 130 // position: 'fixed', top: 0, left: 0, 131 // 'background-color': this.options['screen_bgcolor'], 132 // 'z-index': this.options['zindex'] 133 //}); 134 } 135 136 $(window).bind('resize', this.setScreenSize); 137 138 var object = this; 139 $screen.bind('click', function() { 140 if (object.options['close_onclick_screen']) { 141 object.close(); 142 } 143 }); 144 145 this.setScreenSize(); 146 147 $screen.fadeTo(this.options['screen_speed'], this.options['screen_opacity']); 148 149 return this; 150 }; 151 152 Class.prototype.setScreenSize = function() { 153 var windowWidth = $(window).width(), 154 windowHeight = $(window).height(); 155 156 $screen.css({ 157 width: windowWidth + 'px', 158 height: windowHeight + 'px' 159 }); 160 } 161 162 Class.prototype.close = function() { 163 this.popupWindow.fadeOut(this.options['speed']); 164 165 this.closeScreen(); 166 167 this.sendGaEvent('close'); 168 169 opentime = 0; 170 this.saveCookie($.extend(this.getCookie(), {'undisplay': true}), 0); 171 return this; 172 } 173 174 Class.prototype.closeScreen = function() { 175 $(window).unbind('resize', this.setScreenSize); 176 $screen.unbind('click'); 177 $screen.fadeOut(this.options['screen_speed'], function() { 178 $screen.hide(); 179 }); 180 } 181 182 Class.prototype.changeUndisplay = function($target) { 183 var isChecked = $target.is(':checked'); 184 if (isChecked) { 185 this.saveCookie($.extend(this.getCookie(), {'undisplay': true}), this.options['cookie_expires']); 186 } else { 187 this.saveCookie($.extend(this.getCookie(), {'undisplay': false}), this.options['cookie_expires']); 188 } 189 return this; 190 } 191 192 Class.prototype.getCookie = function() {
193 $.cookie.json = true; 194 195 var data = ''; 196 if (typeof $.cookie(this.options['cookie']) != 'undefined') { 197 data = $.cookie(this.options['cookie']); 198 } 199 200 if (data != '' && 'last_cookie_id' in data && data['last_cookie_id'] != this.getEachCookieId()) { 201 this.removeCookie(); 202 data = {}; 203 } 204 205 return data != '' ? data : {}; 206 } 207 208 Class.prototype.saveCookie = function(data, expires) { 209 data['last_cookie_id'] = this.getEachCookieId(); 210 211 $.cookie.json = true; 212 213 var params = {path: '/'}; 214 if (expires > 0) { 215 params['expires'] = expires; 216 } 217 218 $.cookie(this.options['cookie'], data, params); 219 } 220 221 Class.prototype.removeCookie = function() { 222 $.removeCookie(this.options['cookie']); 223 } 224 225 Class.prototype.getEachCookieId = function() { 226 var id = this.popupWindow.attr('id'); 227 if (typeof id == 'undefined' || id == '') { 228 id = 'default'; 229 } 230 return id; 231 } 232 233 Class.prototype.sendGaEvent = function(label) { 234 if (typeof ga != 'undefined' && this.options['send_ga']) { 235 var category = this.options['send_ga_category']; 236 var action = this.options['send_ga_action'] == '' ? this.getEachCookieId() : this.options['send_ga_action']; 237 var value = opentime > 0 ? (new Date()).getTime() - opentime : 0; 238 239 if (value > 0) { 240 ga('send', 'event', category, action, label, parseInt(value)); 241 } else { 242 ga('send', 'event', category, action, label); 243 } 244 } 245 } 246 247 /** 248 * å ¨ãã©ã°ã¤ã³å ±é 249 */ 250 $.fn[plugname] = function(options) { 251 return new Class(this, options); 252 } 253 254 /** 255 * ããã©ã«ããã©ã¡ã¼ã¿ 256 */ 257 $.fn[plugname].defaults = { 258 speed : 'normal', // ãããã¢ããã¦ã£ã³ãã¦ã®ééã¹ãã¼ã 259 zindex : 1000, // ã¹ã¯ãªã¼ã³ã®z-indexããããã¢ããã¦ã£ã³ãã¦ã¯ãã®å¤ï¼ï¼ 260 screen : true, // ã¹ã¯ãªã¼ã³ã表示ãããï¼ 261 screen_opacity : 0.5, // ã¹ã¯ãªã¼ã³ã®éé 262 screen_speed : 'normal', // ã¹ã¯ãªã¼ã³ã®ééã¹ãã¼ã 263 screen_bgcolor : '#000000', // ã¹ã¯ãªã¼ã³ã®èæ¯è² 264 close_onclick_screen : true, // ã¹ã¯ãªã¼ã³ã¯ãªãã¯ã§éãããï¼ 265 266 expires_type : '', // 次å表示ã¾ã§ã®æå¹æéãdailyï¼ï¼æ¥ï¼å 267 268 open_onload : false, // documentãã¼ãæã«ãããã¢ãããéããï¼ 269 open_onload_delay : 500, // documentãã¼ãæã«ãããã¢ãããéãã¨ãã®é å»¶æé 270 cookie : 'open_popup_item_list', // documentãã¼ãæã«ãããã¢ãããéãã¨ãã®è¡¨ç¤ºç¶æ ãä¿åããã¯ããã¼ 271 cookie_expires : 365, // documentãã¼ãæã«ãããã¢ãããéãã¨ãã®è¡¨ç¤ºç¶æ ãä¿åããã¯ããã¼ã®æå¹æé 272 273 selector_close : '.close', // éãããã¿ã³ã®selector 274 selector_undisplay : '.undisplay', // ãæ¬¡åãã表示ããªããboxã®selector 275 selector_undisplay_checkbox : '.undisplay input[type=checkbox]', // ãæ¬¡åãã表示ããªããcheckboxã®selector 276 277 remove_link_if_empty_href : false, // hrefã空ã®å ´åã«ã¢ã³ã«ã¼ãåé¤ãããï¼ 278 279 send_ga : true, // Google Analyticsã«ã¤ãã³ããéä¿¡ãããï¼ããå ´åã表示ã¨ã¯ãªãã¯ã®ã¤ãã³ããéç¥ããã¾ãã 280 send_ga_category : 'popup', // GAã«éä¿¡ããã¤ãã³ãã®ã«ãã´ãª 281 send_ga_action : '', // GAã«éä¿¡ããã¤ãã³ãã®ã¢ã¯ã·ã§ã³ï¼ç©ºã®å ´åã¯BOXã®IDã使ãããï¼IDã空ã®å ´åã¯defaultï¼ 282 }; 283 284 function getToday() { 285 var now = new Date(); 286 return now.getFullYear() + 287 ("0" + (now.getMonth() + 1)).slice(-2) + 288 ("0" + now.getDate()).slice(-2); 289 } 290})(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.