1/** PIXWELL_CORE_SCRIPT */ 2var PIXWELL_CORE_SCRIPT = (function (Module, $) { 3 "use strict"; 4 5 Module.init = function () { 6 let self = this; 7 this._body = $('body'); 8 $(window).trigger('RB:CountBookmark'); 9 this.darkModeID = pixwellCoreParams.darkModeID || 'RubyDarkMode'; 10 this.isCMode = document.body.classList.contains("is-cmode"); 11 12 self.newsLetterSubmit(); 13 self.initDarkModeCookie(); 14 self.rbCookie(); 15 self.headerStrip(); 16 self.bookMarkCounter(); 17 self.bookmarkList(); 18 self.removeBookmarkList(); 19 self.removeBookMark(); 20 self.newsLetterPopup(); 21 self.switchDarkMode(); 22 self.noteToggle(); 23 self.accordion(); 24 }; 25 26 Module.initReaction = function () { 27 this.clickReaction(); 28 this.loadReactions(); 29 } 30 31 Module.rbBookMarks = function () { 32 this.loadBookMarks(); 33 this.addBookMark(); 34 }; 35 36 /** module newsletter */ 37 Module.newsLetterSubmit = function () { 38 $('.rb-newsletter-form').submit(function (e) { 39 e.preventDefault(); 40 e.stopPropagation(); 41 let target = $(this); 42 let responseWrap = target.closest('.rb-newsletter').find('.newsletter-response'); 43 responseWrap.find('.is-show').removeClass('is-show'); 44 let subscribeEmail = target.find('input[name="rb_email_subscribe"]').val(); 45 if (!subscribeEmail) { 46 responseWrap.find('.email-error').addClass('is-show'); 47 responseWrap.find('.email-error').addClass('showing'); 48 return false; 49 } 50 51 let postData = { 52 action: 'rb_submit_newsletter', 53 email: subscribeEmail 54 }; 55 56 let privacy = target.find(':checkbox[name="rb_privacy"]'); 57 if (privacy != null && privacy.length > 0) { 58 let privacyVal = privacy.prop('checked'); 59 if (!privacyVal) { 60 responseWrap.find('.privacy-error').addClass('is-show showing'); 61 return false; 62 } else { 63 postData.privacy = privacyVal; 64 } 65 } 66 67 $.ajax({
68 type: 'POST', 69 url: pixwellParams.ajaxurl, 70 data: postData, 71 success: function (response) { 72 responseWrap.find('.' + response.notice).addClass('is-show'); 73 responseWrap.find('.' + response.notice).addClass('showing'); 74 } 75 }); 76 77 return false; 78 }); 79 }; 80 81 /** Newsletter popup */ 82 Module.newsLetterPopup = function () { 83 84 if ($(window).width() < 768) { 85 return; 86 } 87 88 let targetID = '#rb-newsletter-popup'; 89 if ($(targetID).length > 0 && '1' !== $.cookie('ruby_newsletter_popup')) { 90 let delay = $(targetID).data('delay'); 91 if (!delay) { 92 delay = 2000; 93 } 94 setTimeout(function () { 95 if (PIXWELL_MAIN_SCRIPTS && true === PIXWELL_MAIN_SCRIPTS.siteAccessFlag) { 96 return; 97 } 98 $.magnificPopup.open({ 99 type: 'inline', 100 preloader: false, 101 closeBtnInside: true, 102 removalDelay: 300, 103 showCloseBtn: true, 104 closeOnBgClick: false, 105 disableOn: 992, 106 items: { 107 src: targetID, 108 type: 'inline' 109 }, 110 mainClass: 'rb-popup-effect', 111 fixedBgPos: true, 112 fixedContentPos: true, 113 closeMarkup: '<button id="rb-close-newsletter" title="%title%" aria-label="%title%" class="mfp-close"><i class="rbi rbi-move"></i></button>', 114 callbacks: { 115 close: function () { 116 let expiresTime = $(targetID).data('expired'); 117 $.cookie('ruby_newsletter_popup', '1', {expires: parseInt(expiresTime), path: '/'}); 118 } 119 } 120 }); 121 122 }, delay); 123 } 124 }; 125 126 Module.noteToggle = function () { 127 $('.yes-toggle > .note-header').on('click', function () { 128 let wrapper = $(this).parent(); 129 let timing = wrapper.hasClass('is-inline') ? 0 : 300; 130 131 wrapper.toggleClass('explain'); 132 wrapper.find('.note-content').slideToggle(timing); 133 }); 134 } 135 136 //share action 137 Module.sharesAction = function () { 138 $('a.share-action').off('click').on('click', function (e) { 139 e.preventDefault(); 140 e.stopPropagation(); 141 window.open($(this).attr('href'), '_blank', 'width=600, height=350'); 142 return false; 143 }) 144 }; 145 146 /** rb cookie */ 147 Module.rbCookie = function () { 148 let rbCookie = $('#rb-cookie'); 149 if (rbCookie.length > 0) { 150 if ($.cookie('ruby_cookie_popup') !== '1') { 151 rbCookie.css('display', 'block'); 152 setTimeout(function () { 153 rbCookie.addClass('is-show'); 154 }, 10) 155 } 156 157 $('#cookie-accept').off('click').on('click', function (e) { 158 e.preventDefault(); 159 e.stopPropagation(); 160 $.cookie('ruby_cookie_popup', '1', {expires: 30, path: '/'}); 161 rbCookie.removeClass('is-show'); 162 setTimeout(function () { 163 rbCookie.css('display', 'none'); 164 }, 500) 165 }) 166 } 167 }; 168 169 /** header strip */ 170 Module.headerStrip = function () { 171 let headerStrips = $('.rb-headerstrip'); 172 if (headerStrips.length > 0) { 173 headerStrips.each(function () { 174 let headerStrip = $(this); 175 let id = headerStrip.attr('id'); 176 if ($.cookie(id) !== '1') { 177 headerStrip.css('display', 'block'); 178 } 179 }); 180 } 181 182 $('.headerstrip-submit').off('click').on('click', function (e) { 183 e.preventDefault(); 184 e.stopPropagation(); 185 let wrap = $(this).parents('.rb-headerstrip'); 186 let expired = wrap.data('headerstrip'); 187 if (!expired) { 188 expired = 30; 189 } 190 let id = wrap.attr('id'); 191 $.cookie(id, '1', {expires: expired, path: '/'}); 192 wrap.slideUp(300, function () { 193 wrap.remove(); 194 }); 195 }); 196 }; 197 198 /** add bookmark */ 199 Module.addBookMark = function () { 200 let self = this; 201 $('.read-it-later').off('click').on('click', function (e) { 202 e.preventDefault(); 203 e.stopPropagation(); 204 205 let target = $(this); 206 let postID = target.data('bookmarkid'); 207 if (!postID) { 208 return; 209 } 210 let dataBookMark = $.cookie('RBBookmarkData'); 211 if (dataBookMark) { 212 dataBookMark = JSON.parse(dataBookMark); 213 } 214 215 if (typeof dataBookMark != 'object' || null == dataBookMark || !dataBookMark) { 216 dataBookMark = []; 217 } 218 219 dataBookMark = self.toggleArrayItem(target, dataBookMark, postID); 220 $.cookie('RBBookmarkData', JSON.stringify(dataBookMark), {expires: 30, path: '/'}); 221 $(window).trigger('RB:CountBookmark'); 222 }); 223 }; 224 225 /** toggle data */ 226 Module.toggleArrayItem = function (target, data, value) { 227 let i = $.inArray(value, data); 228 if (i === -1) { 229 $('[data-bookmarkid= ' + value + ']').addClass('added'); 230 data.push(value); 231 } else { 232 $('[data-bookmarkid= ' + value + ']').removeClass('added'); 233 data.splice(i, 1); 234 } 235 return data; 236 }; 237 238 /** remove bookmarks */ 239 Module.removeBookmarkList = function () { 240 $('#remove-bookmark-list').on('click', function (e) { 241 e.preventDefault(); 242 e.stopPropagation(); 243 $.removeCookie('RBBookmarkData', {path: '/'}); 244 window.location.reload(); 245 }) 246 }; 247 248 Module.loadBookMarks = function () { 249 let dataBookMark = $.cookie('RBBookmarkData'); 250 if (dataBookMark) { 251 dataBookMark = JSON.parse(dataBookMark); 252 } 253 $('.read-it-later:not(.loaded)').each(function () { 254 let target = $(this); 255 target.addClass('loaded'); 256 257 let postID = target.data('bookmarkid'); 258 if (!postID) { 259 return; 260 } 261 let i = $.inArray(postID, dataBookMark); 262 if (i !== -1) { 263 target.addClass('added'); 264 } 265 }); 266 $(window).trigger('RB:CountBookmark'); 267 }; 268 269 /** remove single bookmark */ 270 Module.removeBookMark = function () { 271 let removeID = $('.rb-remove-bookmark').data('bookmarkid'); 272 if (removeID) { 273 let dataBookMark = $.cookie('RBBookmarkData'); 274 if (dataBookMark) { 275 dataBookMark = JSON.parse(dataBookMark); 276 } 277 if (typeof dataBookMark != 'object') { 278 return; 279 } 280 let i = $.inArray(removeID, dataBookMark); 281 if (i != -1) { 282 dataBookMark.splice(i, 1); 283 } 284 $.cookie('RBBookmarkData', JSON.stringify(dataBookMark), {expires: 30, path: '/'}); 285 } 286 }; 287 288 /** total bookmarks */ 289 Module.bookMarkCounter = function () { 290 $(window).on('RB:CountBookmark', function () { 291 let dataBookMark = $.cookie('RBBookmarkData'); 292 if (dataBookMark) { 293 dataBookMark = JSON.parse(dataBookMark); 294 if (dataBookMark != null && dataBookMark.length > 0) { 295 $('.bookmark-counter').fadeOut(0).html(dataBookMark.length).fadeIn(200); 296 } 297 } 298 }); 299 }; 300 301 /** ajax get bookmark list */ 302 Module.bookmarkList = function () { 303 304 let bookmarkList = $('#bookmarks-list'); 305 if (null == bookmarkList || bookmarkList.length < 1) { 306 return; 307 } 308 let dataBookMark = $.cookie('RBBookmarkData'); 309 if (dataBookMark) { 310 dataBookMark = JSON.parse(dataBookMark); 311 } 312 313 $.ajax({
314 type: 'POST', 315 url: pixwellParams.ajaxurl, 316 data: { 317 action: 'rb_bookmark', 318 ids: dataBookMark 319 }, 320 success: function (data) { 321 data = $.parseJSON(JSON.stringify(data)); 322 $('#bookmarks-list').html(data); 323 $(window).trigger('load'); 324 } 325 }); 326 }; 327 328 Module.setDarkModeCookie = function (id, value) { 329 if (this.isCMode) { 330 var date = new Date() 331 date.setTime(date.getTime() + 5184000000); 332 document.cookie = id + '= ' + value + '; path=/; expires=' + date.toGMTString() + ';'; 333 } 334 } 335 336 Module.initDarkModeCookie = function () { 337 if (this.isCMode && !$.cookie(this.darkModeID)) { 338 $.cookie(this.darkModeID, document.body.getAttribute('data-theme'), {expires: 60, path: '/'}); 339 } 340 } 341 342 Module.switchDarkMode = function () { 343 let self = this; 344 let darkModeID = pixwellCoreParams.darkModeID; 345 346 $('.dark-mode-toggle').off('click').on('click', function (e) { 347 e.preventDefault(); 348 e.stopPropagation(); 349 350 if (!$(this).hasClass('trigged')) { 351 $(this).addClass('trigged') 352 } 353 354 let iconDefault = $('.mode-icon-default'); 355 let iconDark = $('.mode-icon-dark'); 356 357 let currentMode = localStorage.getItem(darkModeID); 358 if (null === currentMode) { 359 currentMode = self._body.data('theme'); 360 } 361 362 self._body.addClass('switch-smooth'); 363 364 if (null === currentMode || 'default' === currentMode) { 365 localStorage.setItem(darkModeID, 'dark'); 366 self._body.attr('data-theme', 'dark'); 367 iconDefault.removeClass('activated'); 368 iconDark.addClass('activated'); 369 self.setDarkModeCookie(darkModeID, 'dark'); 370 } else { 371 localStorage.setItem(darkModeID, 'default'); 372 self._body.attr('data-theme', 'default'); 373 iconDefault.addClass('activated'); 374 iconDark.removeClass('activated'); 375 self.setDarkModeCookie(darkModeID, 'default'); 376 } 377 }) 378 }; 379 380 /** reaction */ 381 Module.loadReactions = function () { 382 let self = this; 383 384 self.reaction = $('.rb-reaction'); 385 if (self.reaction.length < 1) { 386 return; 387 } 388 self.reactionProcessing = false; 389 self.reaction.each(function () { 390 let currentReaction = $(this); 391 let uid = currentReaction.data('reaction_uid'); 392 if (!currentReaction.hasClass('data-loaded')) { 393 self.loadCurrentReaction(currentReaction, uid); 394 } 395 }); 396 }; 397 398 Module.loadCurrentReaction = function (currentReaction, uid) { 399 let self = this; 400 self.reactionProcessing = true; 401 $.ajax({
402 type: 'POST', 403 url: pixwellParams.ajaxurl, 404 data: { 405 action: 'rb_load_reaction', 406 uid: uid 407 }, 408 success: function (data) { 409 data = $.parseJSON(JSON.stringify(data)); 410 $.each(data, function (index, val) { 411 currentReaction.find('[data-reaction=' + val + ']').addClass('active'); 412 }); 413 currentReaction.addClass('data-loaded'); 414 self.reactionProcessing = false; 415 } 416 }); 417 }; 418 419 Module.clickReaction = function () { 420 421 let self = this; 422 $('.reaction').off('click').on('click', function (e) { 423 e.preventDefault(); 424 e.stopPropagation(); 425 426 let target = $(this); 427 let reaction = target.data('reaction'); 428 let uid = target.data('reaction_uid'); 429 let push = 1; 430 431 if (self.reactionProcessing) { 432 return; 433 } 434 target.addClass('loading'); 435 self.reactionProcessing = true; 436 let reactionCount = target.find('.reaction-count'); 437 let total = parseInt(reactionCount.html()); 438 if (target.hasClass('active')) { 439 total--; 440 push = '-1'; 441 } else { 442 total++; 443 } 444 $.ajax({
445 type: 'POST', 446 url: pixwellParams.ajaxurl, 447 data: { 448 action: 'rb_add_reaction', 449 uid: uid, 450 reaction: reaction, 451 push: push 452 }, 453 454 success: function (data) { 455 if (true !== data) { 456 let oldReactions = target.siblings('.active'); 457 if (oldReactions.length > 0) { 458 $.each(oldReactions, function () { 459 $(this).removeClass('active'); 460 let oldReactionCount = $(this).find('.reaction-count'); 461 let oldTotal = parseInt(oldReactionCount.html()) - 1; 462 oldReactionCount.hide().html(oldTotal).fadeIn(300); 463 }); 464 } 465 } 466 reactionCount.hide().html(total).fadeIn(300); 467 target.toggleClass('active'); 468 target.removeClass('loading'); 469 self.reactionProcessing = false; 470 } 471 }); 472 473 return false; 474 }); 475 }; 476 477 Module.accordion = function () { 478 $('.gb-accordion').each(function () { 479 const accordion = $(this); 480 const accordionItems = accordion.find('.gb-accordion-item'); 481 482 if (accordion.hasClass('yes-open')) { 483 accordionItems.first().addClass('active'); 484 } 485 486 accordionItems.on('click', function () { 487 const item = $(this); 488 const isActive = item.hasClass('active'); 489 490 if (!isActive) { 491 const activeItem = accordionItems.filter('.active'); 492 activeItem.removeClass('active').find('.accordion-item-content').slideUp(250, function () { 493 $(this).css('display', 'none'); 494 }); 495 496 item.addClass('active').find('.accordion-item-content').slideDown(250, function () { 497 $(this).css('display', 'block'); 498 }); 499 } else { 500 item.removeClass('active').find('.accordion-item-content').slideUp(250, function () { 501 $(this).css('display', 'none'); 502 }); 503 } 504 }); 505 }); 506 }; 507 508 return Module; 509 510}(PIXWELL_CORE_SCRIPT || {}, jQuery)); 511 512jQuery(document).ready(function () { 513 PIXWELL_CORE_SCRIPT.init(); 514}); 515 516jQuery(window).on('load', function () { 517 PIXWELL_CORE_SCRIPT.sharesAction(); 518 PIXWELL_CORE_SCRIPT.rbBookMarks(); 519 PIXWELL_CORE_SCRIPT.initReaction(); 520});
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.