1/** FOXIZ_PERSONALIZE */ 2var FOXIZ_PERSONALIZE = (function (Module, $) { 3 'use strict'; 4 5 Module.initParams = function () { 6 this.ajaxURL = foxizCoreParams.ajaxurl || ''; 7 this.personailizeUID = FOXIZ_CORE_SCRIPT.personailizeUID; 8 this._body = $('body'); 9 this.isProgress = false; 10 this.checkPersonalize(); 11 12 this.personalizePopup = $('#bookmark-notification'); 13 this.yesPopup = this.personalizePopup.length || false; 14 15 this.followPopupTemplate = $('#follow-notification-template').html(); 16 this.savedPopupTemplate = $('#bookmark-notification-template').html(); 17 18 if ('ask_login' === this.pesonalizeMode) { 19 this.bookmarkToggleTemplate = $('#bookmark-ask-login-template').html(); 20 this.followToggleTemplate = $('#follow-ask-login-template').html(); 21 } else { 22 this.bookmarkToggleTemplate = $('#bookmark-toggle-template').html(); 23 this.followToggleTemplate = $('#follow-toggle-template').html(); 24 } 25 } 26 27 Module.init = function () { 28 this.initParams(); 29 30 if (!FOXIZ_CORE_SCRIPT.getCookie('personalize_sync')) { 31 this.syncPersonalizeLayout(); 32 } else { 33 this.syncPersonalizeData(); 34 } 35 this.keepPersonalizePopup(); 36 this.readingListTemplate(); 37 this.bookmarkToggle(); 38 this.followCategoryToggle(); 39 this.followWriterToggle(); 40 } 41 42 Module.getSavedKey = function (id) { 43 return this.personailizeUID + '-saved-' + id; 44 } 45 46 Module.getCategoryFollowKey = function (id) { 47 return this.personailizeUID + '-cat-' + id; 48 } 49 50 Module.getWriterFollowKey = function (id) { 51 return this.personailizeUID + '-writer-' + id; 52 } 53 54 Module.setStorage = function (key, data) { 55 return FOXIZ_CORE_SCRIPT.setStorage(key, data); 56 } 57 58 Module.getStorage = function (key, defaultValue) { 59 return FOXIZ_CORE_SCRIPT.getStorage(key, defaultValue); 60 } 61 62 Module.deleteStorage = function (key) { 63 localStorage.removeItem(key); 64 } 65 66 /** 67 * check checkPersonalize 68 */ 69 Module.checkPersonalize = function () { 70 this.pesonalizeMode = 'yes'; 71 let setting = 'all'; 72 const isLogged = FOXIZ_CORE_SCRIPT.getCookie('u_logged'); 73 if (this._body.hasClass('personalized-logged-only')) { 74 setting = 'logged'; 75 } else if (this._body.hasClass('personalized-ask-login')) { 76 setting = 'login'; 77 } 78 if (!isLogged) { 79 if ('login' === setting) { 80 this.pesonalizeMode = 'ask_login'; 81 } else if ('logged' === setting) { 82 this.pesonalizeMode = 'no'; 83 } 84 } 85 }; 86 87 /** saved a post */ 88 Module.bookmarkToggle = function () { 89 90 var self = this; 91 self._body.on('click', '.bookmark-trigger', function (e) { 92 93 e.preventDefault(); 94 e.stopPropagation(); 95 96 const target = $(this); 97 const pid = target.data('pid'); 98 99 if (!pid || self.isProgress) { 100 return false; 101 } 102 103 self.isProgress = true; 104 clearTimeout(self.personalizeTimeout); 105 target.addClass('in-progress'); 106 107 const storageKey = self.getSavedKey(pid); 108 let savedPopupTemplate = self.savedPopupTemplate; 109 110 let type = 'save'; 111 if (target.hasClass('bookmarked')) { 112 type = 'remove'; 113 } 114 115 $.ajax({
116 type: 'POST', 117 url: self.ajaxURL, 118 data: { 119 action: 'rbbookmark', 120 pid: pid, 121 type: type, 122 uuid: self.personailizeUID 123 }, 124 125 success: function (response) { 126 127 response = JSON.parse(JSON.stringify(response)); 128 129 if ('save' === type) { 130 $('.bookmark-trigger[data-pid=' + pid + ']').css('opacity', 0).addClass('bookmarked').animate({opacity: 1}, 250); 131 self.setStorage(storageKey, 1); 132 if (self.yesPopup) { 133 savedPopupTemplate = savedPopupTemplate.replace('{{classes}}', 'added'); 134 } 135 } else { 136 $('.bookmark-trigger[data-pid=' + pid + ']').css('opacity', 0).removeClass('bookmarked').animate({opacity: 1}, 250); 137 self.deleteStorage(storageKey); 138 if (self.yesPopup) { 139 savedPopupTemplate = savedPopupTemplate.replace('{{classes}}', 'removed'); 140 } 141 } 142 143 target.removeClass('in-progress'); 144 self.isProgress = false; 145 146 if (self.yesPopup) { 147 savedPopupTemplate = savedPopupTemplate 148 .replace('{{image}}', response.image) 149 .replace('{{title}}', response.title) 150 .replace('{{description}}', response.description); 151 152 clearTimeout(self.personalizeTimeout); 153 self.personalizePopup.empty(); 154 self.personalizePopup.append(savedPopupTemplate); 155 self.personalizePopup.fadeIn(300); 156 157 self.personalizeTimeout = setTimeout(function () { 158 self.personalizePopup.fadeOut(600); 159 }, 2000); 160 } 161 } 162 }); 163 }); 164 } 165 166 /** follow category */ 167 Module.followCategoryToggle = function () { 168 169 if ('no' === this.pesonalizeMode) { 170 return; 171 } 172 173 var self = this; 174 self._body.on('click', '.follow-trigger[data-cid]', function (e) { 175 176 e.preventDefault(); 177 e.stopPropagation(); 178 179 var target = $(this); 180 var cid = target.data('cid'); 181 182 if (!cid || self.isProgress) { 183 return false; 184 } 185 186 self.isProgress = true; 187 clearTimeout(self.personalizeTimeout); 188 target.addClass('in-progress'); 189 190 const storageKey = self.getCategoryFollowKey(cid); 191 let followPopupTemplate = self.followPopupTemplate; 192 const catName = target.data('name'); 193 194 let type = 'follow'; 195 if (target.hasClass('followed')) { 196 type = 'unfollow'; 197 } 198 199 $.ajax({
200 type: 'POST', 201 url: self.ajaxURL, 202 data: { 203 uuid: self.personailizeUID, 204 action: 'rb_follow_category', 205 cid: cid, 206 type: type, 207 }, 208 success: function (response) { 209 response = JSON.parse(JSON.stringify(response)); 210 if ('follow' === type) { 211 $('.follow-trigger[data-cid=' + cid + ']').css('opacity', 0).addClass('followed').animate({opacity: 1}, 150); 212 self.setStorage(storageKey, 1); 213 if (self.yesPopup) { 214 followPopupTemplate = followPopupTemplate.replace('{{classes}}', 'added'); 215 } 216 } else { 217 $('.follow-trigger[data-cid=' + cid + ']').css('opacity', 0).removeClass('followed').animate({opacity: 1}, 150); 218 self.deleteStorage(storageKey); 219 if (self.yesPopup) { 220 followPopupTemplate = followPopupTemplate.replace('{{classes}}', 'removed'); 221 } 222 } 223 224 target.removeClass('in-progress'); 225 self.isProgress = false; 226 227 if (self.yesPopup) { 228 followPopupTemplate = followPopupTemplate 229 .replace('{{description}}', response.description) 230 .replace('{{name}}', catName); 231 232 clearTimeout(self.personalizeTimeout); 233 self.personalizePopup.empty(); 234 self.personalizePopup.append(followPopupTemplate); 235 self.personalizePopup.fadeIn(300); 236 self.personalizeTimeout = setTimeout(function () { 237 self.personalizePopup.fadeOut(600); 238 }, 2000); 239 } 240 } 241 }); 242 }); 243 } 244 245 /** follow writer */ 246 Module.followWriterToggle = function () { 247 248 if ('no' === this.pesonalizeMode) { 249 return; 250 } 251 252 var self = this; 253 self._body.on('click', '.follow-trigger[data-uid]', function (e) { 254 255 e.preventDefault(); 256 e.stopPropagation(); 257 258 var target = $(this); 259 var uid = target.data('uid'); 260 261 if (!uid || self.isProgress) { 262 return false; 263 } 264 265 self.isProgress = true; 266 clearTimeout(self.personalizeTimeout); 267 target.addClass('in-progress'); 268 269 const storageKey = self.getWriterFollowKey(uid); 270 let followPopupTemplate = self.followPopupTemplate; 271 const authName = target.data('name'); 272 273 let type = 'follow'; 274 if (target.hasClass('followed')) { 275 type = 'unfollow'; 276 } 277 278 $.ajax({
279 type: 'POST', 280 url: self.ajaxURL, 281 data: { 282 uuid: self.personailizeUID, 283 action: 'rb_follow_writer', 284 uid: uid, 285 type: type, 286 }, 287 success: function (response) { 288 289 response = JSON.parse(JSON.stringify(response)); 290 291 if ('follow' === type) { 292 $('.follow-trigger[data-uid=' + uid + ']').css('opacity', 0).addClass('followed').animate({opacity: 1}, 150); 293 self.setStorage(storageKey, 1); 294 if (self.yesPopup) { 295 followPopupTemplate = followPopupTemplate.replace('{{classes}}', 'added'); 296 } 297 } else { 298 $('.follow-trigger[data-uid=' + uid + ']').css('opacity', 0).removeClass('followed').animate({opacity: 1}, 150); 299 self.deleteStorage(storageKey); 300 if (self.yesPopup) { 301 followPopupTemplate = followPopupTemplate.replace('{{classes}}', 'removed'); 302 } 303 } 304 305 target.removeClass('in-progress'); 306 self.isProgress = false; 307 308 if (self.yesPopup) { 309 followPopupTemplate = followPopupTemplate 310 .replace('{{description}}', response.description) 311 .replace('{{name}}', authName); 312 313 clearTimeout(self.personalizeTimeout); 314 self.personalizePopup.empty(); 315 self.personalizePopup.append(followPopupTemplate); 316 self.personalizePopup.fadeIn(300); 317 self.personalizeTimeout = setTimeout(function () { 318 self.personalizePopup.fadeOut(600); 319 }, 2000); 320 } 321 } 322 }); 323 }); 324 } 325 326 /** keep notification */ 327 Module.keepPersonalizePopup = function () { 328 329 var self = this; 330 if (self.personalizePopup.length > 0) { 331 self.personalizePopup.on({ 332 mouseenter: function () { 333 clearTimeout(self.personalizeTimeout); 334 }, 335 mouseleave: function () { 336 self.personalizeTimeout = setTimeout(function () { 337 self.personalizePopup.fadeOut(600); 338 }, 1200); 339 } 340 }); 341 } 342 } 343 344 /** sync layouts */ 345 Module.syncPersonalizeLayout = function () { 346 347 if ('no' === this.pesonalizeMode) { 348 return; 349 } 350 351 this.isProgress = true; 352 this.syncLayoutBookmarks(); 353 this.syncLayoutCategories(); 354 this.syncLayoutWitters(); 355 this.isProgress = false; 356 } 357 358 Module.syncLayoutBookmarks = function () { 359 360 var self = this; 361 const bookmarks = document.querySelectorAll('.rb-bookmark[data-pid]'); 362 363 bookmarks.forEach((bookmark) => { 364 if (bookmark.classList.contains('loaded')) { 365 return; 366 } 367 bookmark.insertAdjacentHTML('beforeend', self.bookmarkToggleTemplate); 368 if ('yes' === self.pesonalizeMode) { 369 const storageKey = self.getSavedKey(bookmark.getAttribute('data-pid')); 370 const bookmarked = self.getStorage(storageKey) === 1; 371 if (bookmarked) { 372 bookmark.classList.add('bookmarked'); 373 } else { 374 bookmark.classList.remove('bookmarked'); 375 } 376 } else { 377 bookmark.classList.remove('bookmark-trigger'); 378 } 379 bookmark.classList.add('loaded'); 380 }); 381 } 382 383 Module.syncLayoutCategories = function () { 384 385 var self = this; 386 const catFollows = document.querySelectorAll('.rb-follow[data-cid]'); 387 388 catFollows.forEach((cat) => { 389 if (cat.classList.contains('loaded')) { 390 return; 391 } 392 cat.insertAdjacentHTML('beforeend', self.followToggleTemplate); 393 if ('yes' === self.pesonalizeMode) { 394 const storageKey = self.getCategoryFollowKey(cat.getAttribute('data-cid')); 395 const bookmarked = self.getStorage(storageKey) === 1; 396 if (bookmarked) { 397 cat.classList.add('followed'); 398 } else { 399 cat.classList.remove('followed'); 400 } 401 } else { 402 cat.classList.remove('follow-trigger'); 403 } 404 cat.classList.add('loaded'); 405 }); 406 } 407 408 Module.syncLayoutWitters = function () { 409 410 var self = this; 411 const writerFollows = document.querySelectorAll('.rb-follow[data-uid]'); 412
413 writerFollows.forEach((writer) => { 414 if (writer.classList.contains('loaded')) { 415 return; 416 } 417 writer.insertAdjacentHTML('beforeend', self.followToggleTemplate); 418 if ('yes' === self.pesonalizeMode) { 419 const storageKey = self.getWriterFollowKey(writer.getAttribute('data-uid')); 420 const bookmarked = self.getStorage(storageKey) === 1; 421 if (bookmarked) { 422 writer.classList.add('followed'); 423 } else { 424 writer.classList.remove('followed'); 425 } 426 } else { 427 writer.classList.remove('follow-trigger'); 428 } 429 writer.classList.add('loaded'); 430 }); 431 } 432 433 Module.syncPersonalizeData = function () { 434 435 var self = this; 436 const blankSavedKey = self.getSavedKey(''); 437 const blankCatKey = self.getCategoryFollowKey(''); 438 const blankWriterKey = self.getWriterFollowKey(''); 439 let i, id; 440 441 FOXIZ_CORE_SCRIPT.setCookie('personalize_sync', '', -1); 442 $.ajax({
443 type: 'POST', 444 url: self.ajaxURL, 445 data: { 446 action: 'rbpersonalizedata', 447 }, 448 success: function (response) { 449 response = JSON.parse(JSON.stringify(response)); 450 451 for (i = 0; i < localStorage.length; i++) { 452 var key = localStorage.key(i); 453 if (key.includes(blankSavedKey) || key.includes(blankCatKey) || key.includes(blankWriterKey)) { 454 localStorage.removeItem(key); 455 } 456 } 457 458 if (response.bookmarks && response.bookmarks.length > 0) { 459 for (i = 0; i < response.bookmarks.length; i++) { 460 id = response.bookmarks[i]; 461 localStorage.setItem(self.getSavedKey(id), '1'); 462 } 463 } 464 465 if (response.categories && response.categories.length > 0) { 466 for (i = 0; i < response.categories.length; i++) { 467 id = response.categories[i]; 468 localStorage.setItem(self.getCategoryFollowKey(id), '1'); 469 } 470 } 471 472 if (response.writers && response.writers.length > 0) { 473 for (i = 0; i < response.writers.length; i++) { 474 id = response.writers[i]; 475 localStorage.setItem(self.getWriterFollowKey(id), '1'); 476 } 477 } 478 479 self.isProgress = false; 480 self.syncPersonalizeLayout(); 481 } 482 }); 483 } 484 485 /** for reading list template */ 486 Module.readingListTemplate = function () { 487 488 var self = this; 489 const mySaved = $('#my-saved'); 490 const myCategories = $('#my-categories'); 491 const myWriters = $('#my-writers'); 492 const myRecommended = $('#my-recommended'); 493 494 if (mySaved.length < 1) { 495 return false; 496 } 497 self.isProgress = true; 498 $.ajax({
499 type: 'POST', 500 url: self.ajaxURL, 501 data: { 502 action: 'rbreadinglist' 503 }, 504 success: function (response) { 505 506 response = JSON.parse(JSON.stringify(response)); 507 508 if ('no' === self.pesonalizeMode) { 509 mySaved.hide().html(response.saved).fadeIn(250); 510 $(".interest-section").remove(); 511 $("#my-recommended").remove(); 512 return false; 513 } else { 514 mySaved.hide().html(response.saved).fadeIn(250); 515 } 516 517 if (myCategories.length > 0) { 518 myCategories.hide().html(response.categories).fadeIn(250); 519 } 520 if (myWriters.length > 0) { 521 myWriters.html(response.writers).fadeIn(250); 522 } 523 524 if (myRecommended.length > 0) { 525 myRecommended.hide().html(response.recommended).fadeIn(250); 526 } 527 528 self.isProgress = false; 529 Waypoint.refreshAll(); 530 531 setTimeout(function () { 532 self.syncPersonalizeLayout(); 533 }, 10) 534 } 535 }); 536 } 537 538 return Module; 539 540 }(FOXIZ_PERSONALIZE || {}, jQuery) 541) 542 543/** init */ 544jQuery(document).ready(function ($) { 545 FOXIZ_PERSONALIZE.init(); 546});
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.