about.js
3 weeks ago
admin-notifications.js
3 weeks ago
builders-preview-handler.js
3 weeks ago
callout.js
3 weeks ago
cff-admin-scripts.js
3 weeks ago
divi-handler.min.js
3 weeks ago
extensions.js
3 weeks ago
oembeds.js
3 weeks ago
settings.js
3 weeks ago
smash-usage-session.js
3 weeks ago
support.js
3 weeks ago
vue.min.js
3 weeks ago
settings.js
931 lines
| 1 | var cffSettings; |
| 2 | |
| 3 | // Declaring as global variable for quick prototyping |
| 4 | var settings_data = { |
| 5 | adminUrl: cff_settings.admin_url, |
| 6 | nonce: cff_settings.nonce, |
| 7 | ajaxHandler: cff_settings.ajax_handler, |
| 8 | model: cff_settings.model, |
| 9 | feeds: cff_settings.feeds, |
| 10 | links: cff_settings.links, |
| 11 | tooltipName: null, |
| 12 | sourcesList : cff_settings.sources, |
| 13 | isDevSite: cff_settings.isDevSite, |
| 14 | dialogBoxPopupScreen : cff_settings.dialogBoxPopupScreen, |
| 15 | selectSourceScreen : cff_settings.selectSourceScreen, |
| 16 | |
| 17 | socialWallActivated: cff_settings.socialWallActivated, |
| 18 | socialWallLinks: cff_settings.socialWallLinks, |
| 19 | exportFeed: 'none', |
| 20 | locales: cff_settings.locales, |
| 21 | timezones: cff_settings.timezones, |
| 22 | genericText: cff_settings.genericText, |
| 23 | generalTab: cff_settings.generalTab, |
| 24 | feedsTab: cff_settings.feedsTab, |
| 25 | translationTab: cff_settings.translationTab, |
| 26 | advancedTab: cff_settings.advancedTab, |
| 27 | upgradeUrl: cff_settings.upgradeUrl, |
| 28 | footerUpgradeUrl: cff_settings.footerUpgradeUrl, |
| 29 | supportPageUrl: cff_settings.supportPageUrl, |
| 30 | licenseKey: cff_settings.licenseKey, |
| 31 | licenseType: cff_settings.licenseType, |
| 32 | licenseStatus: cff_settings.licenseStatus, |
| 33 | licenseErrorMsg: cff_settings.licenseErrorMsg, |
| 34 | extensionsLicense: cff_settings.extensionsLicense, |
| 35 | extensionsLicenseKey: cff_settings.extensionsLicenseKey, |
| 36 | extensionFieldHasError: false, |
| 37 | cronNextCheck: cff_settings.nextCheck, |
| 38 | currentView: null, |
| 39 | selected: null, |
| 40 | current: 0, |
| 41 | sections: ["General", "Feeds", "Translation", "Advanced"], |
| 42 | indicator_width: 0, |
| 43 | indicator_pos: 0, |
| 44 | forwards: true, |
| 45 | currentTab: null, |
| 46 | import_file: null, |
| 47 | gdprInfoTooltip: null, |
| 48 | loaderSVG: cff_settings.loaderSVG, |
| 49 | checkmarkSVG: cff_settings.checkmarkSVG, |
| 50 | uploadSVG: cff_settings.uploadSVG, |
| 51 | exportSVG: cff_settings.exportSVG, |
| 52 | reloadSVG: cff_settings.reloadSVG, |
| 53 | tooltipHelpSvg: cff_settings.tooltipHelpSvg, |
| 54 | tooltip : { |
| 55 | text : '', |
| 56 | hover : false |
| 57 | }, |
| 58 | |
| 59 | cogSVG: cff_settings.cogSVG, |
| 60 | deleteSVG: cff_settings.deleteSVG, |
| 61 | svgIcons : cff_settings.svgIcons, |
| 62 | |
| 63 | testConnectionStatus: null, |
| 64 | btnStatus: null, |
| 65 | uploadStatus: null, |
| 66 | clearCacheStatus: null, |
| 67 | optimizeCacheStatus: null, |
| 68 | dpaResetStatus: null, |
| 69 | pressedBtnName: null, |
| 70 | loading: false, |
| 71 | hasError: cff_settings.hasError, |
| 72 | dialogBox : { |
| 73 | active : false, |
| 74 | type : null, |
| 75 | heading : null, |
| 76 | description : null |
| 77 | }, |
| 78 | sourceToDelete : {}, |
| 79 | newManualSourcePopup : cff_settings.newManualSourcePopup, |
| 80 | viewsActive : { |
| 81 | sourcePopup : false, |
| 82 | sourcePopupScreen : 'redirect_1', |
| 83 | sourcePopupType : 'creation', |
| 84 | instanceSourceActive : null, |
| 85 | }, |
| 86 | //Add New Source |
| 87 | newSourceData : cff_settings.newSourceData ? cff_settings.newSourceData : null, |
| 88 | sourceConnectionURLs : cff_settings.sourceConnectionURLs, |
| 89 | returnedApiSourcesList : [], |
| 90 | addNewSource : { |
| 91 | typeSelected : 'page', |
| 92 | manualSourceID : null, |
| 93 | manualSourceToken : null |
| 94 | }, |
| 95 | selectedFeed : 'none', |
| 96 | expandedFeedID : null, |
| 97 | notificationElement : { |
| 98 | type : 'success', // success, error, warning, message |
| 99 | text : '', |
| 100 | shown : null |
| 101 | }, |
| 102 | selectedSourcesToConnect : [], |
| 103 | |
| 104 | //Loading Bar |
| 105 | fullScreenLoader : false, |
| 106 | appLoaded : false, |
| 107 | previewLoaded : false, |
| 108 | loadingBar : true, |
| 109 | isSetupPage : false |
| 110 | }; |
| 111 | |
| 112 | // The tab component |
| 113 | Vue.component("tab", { |
| 114 | props: ["section", "index"], |
| 115 | template: ` |
| 116 | <a class='tab' :id='section.toLowerCase().trim()' @click='emitWidth($el);changeComponent(index);activeTab(section)'>{{section}}</a> |
| 117 | `, |
| 118 | created: () => { |
| 119 | let urlParams = new URLSearchParams(window.location.search); |
| 120 | let view = urlParams.get('view'); |
| 121 | if ( view === null ) { |
| 122 | view = 'general'; |
| 123 | } |
| 124 | settings_data.currentView = view; |
| 125 | settings_data.currentTab = settings_data.sections[0]; |
| 126 | settings_data.selected = "app-1"; |
| 127 | }, |
| 128 | methods: { |
| 129 | emitWidth: function(el) { |
| 130 | settings_data.indicator_width = jQuery(el).outerWidth(); |
| 131 | settings_data.indicator_pos = jQuery(el).position().left; |
| 132 | }, |
| 133 | changeComponent: function(index) { |
| 134 | var prev = settings_data.current; |
| 135 | if (prev < index) { |
| 136 | settings_data.forwards = false; |
| 137 | } else if (prev > index) { |
| 138 | settings_data.forwards = true; |
| 139 | } |
| 140 | settings_data.selected = "app-" + (index + 1); |
| 141 | settings_data.current = index; |
| 142 | |
| 143 | // get the pro cta banner offset |
| 144 | let ctaOffset = jQuery('.cff-settings-cta').offset(); |
| 145 | // position them to bottom so during change component they don't appear at top |
| 146 | jQuery('.cff-settings-cta, .cff-save-button').css({"position": "absolute", "top": ctaOffset.top + 'px'}) |
| 147 | // remove the added styles shortly after to set it where it should be |
| 148 | setTimeout(function() { |
| 149 | jQuery('.cff-settings-cta, .cff-save-button').removeAttr('style') |
| 150 | }, 400); |
| 151 | }, |
| 152 | activeTab: function(section) { |
| 153 | this.setView(section.toLowerCase().trim()); |
| 154 | settings_data.currentTab = section; |
| 155 | }, |
| 156 | setView: function(section) { |
| 157 | history.replaceState({}, null, settings_data.adminUrl + 'admin.php?page=cff-settings&view=' + section); |
| 158 | } |
| 159 | } |
| 160 | }); |
| 161 | |
| 162 | var cffSettings = new Vue({ |
| 163 | el: "#cff-settings", |
| 164 | http: { |
| 165 | emulateJSON: true, |
| 166 | emulateHTTP: true |
| 167 | }, |
| 168 | data: settings_data, |
| 169 | created: function() { |
| 170 | this.$nextTick(function() { |
| 171 | let tabEl = document.querySelector('.tab'); |
| 172 | settings_data.indicator_width = tabEl.offsetWidth; |
| 173 | }); |
| 174 | setTimeout(function(){ |
| 175 | settings_data.appLoaded = true; |
| 176 | },350); |
| 177 | }, |
| 178 | mounted: function(){ |
| 179 | var self = this; |
| 180 | // set the current view page on page load |
| 181 | let activeEl = document.querySelector('a.tab#' + settings_data.currentView); |
| 182 | // we have to uppercase the first letter |
| 183 | let currentView = settings_data.currentView.charAt(0).toUpperCase() + settings_data.currentView.slice(1); |
| 184 | let viewIndex = settings_data.sections.indexOf(currentView) + 1; |
| 185 | settings_data.indicator_width = activeEl.offsetWidth; |
| 186 | settings_data.indicator_pos = activeEl.offsetLeft; |
| 187 | settings_data.selected = "app-" + viewIndex; |
| 188 | settings_data.current = viewIndex; |
| 189 | settings_data.currentTab = currentView; |
| 190 | |
| 191 | setTimeout(function(){ |
| 192 | settings_data.appLoaded = true; |
| 193 | },350); |
| 194 | |
| 195 | if(self.newManualSourcePopup != undefined && self.newManualSourcePopup == true){ |
| 196 | self.viewsActive.sourcePopupScreen = 'step_3'; |
| 197 | self.activateView('sourcePopup', 'creation'); |
| 198 | } |
| 199 | |
| 200 | }, |
| 201 | computed: { |
| 202 | getStyle: function() { |
| 203 | return { |
| 204 | position: "absolute", |
| 205 | bottom: "0px", |
| 206 | left: settings_data.indicator_pos + "px", |
| 207 | width: settings_data.indicator_width + "px", |
| 208 | height: "2px" |
| 209 | }; |
| 210 | }, |
| 211 | chooseDirection: function() { |
| 212 | return "slide-fade"; |
| 213 | } |
| 214 | }, |
| 215 | methods: { |
| 216 | activateLicense: function() { |
| 217 | if (this.licenseType === 'free') { |
| 218 | this.runOneClickUpgrade(); |
| 219 | } else { |
| 220 | this.activateProLicense(); |
| 221 | } |
| 222 | }, |
| 223 | activateProLicense: function() { |
| 224 | this.hasError = false; |
| 225 | this.loading = true; |
| 226 | this.pressedBtnName = 'cff'; |
| 227 | |
| 228 | let data = new FormData(); |
| 229 | data.append( 'action', 'cff_activate_license' ); |
| 230 | data.append( 'license_key', this.licenseKey ); |
| 231 | data.append( 'nonce', this.nonce ); |
| 232 | fetch(this.ajaxHandler, { |
| 233 | method: "POST", |
| 234 | credentials: 'same-origin', |
| 235 | body: data |
| 236 | }) |
| 237 | .then(response => response.json()) |
| 238 | .then(data => { |
| 239 | if ( data.success == false ) { |
| 240 | this.licenseStatus = 'inactive'; |
| 241 | this.hasError = true; |
| 242 | this.loading = false; |
| 243 | return; |
| 244 | } |
| 245 | if ( data.success == true ) { |
| 246 | let licenseData = data.data.licenseData; |
| 247 | this.licenseStatus = data.data.licenseStatus; |
| 248 | this.loading = false; |
| 249 | this.pressedBtnName = null; |
| 250 | |
| 251 | if ( |
| 252 | data.data.licenseStatus == 'inactive' || |
| 253 | data.data.licenseStatus == 'invalid' || |
| 254 | data.data.licenseStatus == 'expired' |
| 255 | ) { |
| 256 | this.hasError = true; |
| 257 | if( licenseData.error ) { |
| 258 | this.licenseErrorMsg = licenseData.errorMsg |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | return; |
| 263 | }); |
| 264 | }, |
| 265 | runOneClickUpgrade: function() { |
| 266 | this.hasError = false; |
| 267 | this.loading = true; |
| 268 | this.pressedBtnName = 'cff'; |
| 269 | |
| 270 | let data = new FormData(); |
| 271 | data.append( 'action', 'cff_maybe_upgrade_redirect' ); |
| 272 | data.append( 'license_key', this.licenseKey ); |
| 273 | data.append( 'nonce', this.nonce ); |
| 274 | fetch(this.ajaxHandler, { |
| 275 | method: "POST", |
| 276 | credentials: 'same-origin', |
| 277 | body: data |
| 278 | }) |
| 279 | .then(response => response.json()) |
| 280 | .then(data => { |
| 281 | if ( data.success === false ) { |
| 282 | this.licenseStatus = 'invalid'; |
| 283 | this.hasError = true; |
| 284 | this.loading = false; |
| 285 | if( typeof data.data !== 'undefined' ) { |
| 286 | this.licenseErrorMsg = data.data.message |
| 287 | } |
| 288 | return; |
| 289 | } |
| 290 | if ( data.success === true ) { |
| 291 | window.location.href = data.data.url |
| 292 | } |
| 293 | return; |
| 294 | }); |
| 295 | }, |
| 296 | deactivateLicense: function() { |
| 297 | this.loading = true; |
| 298 | this.pressedBtnName = 'cff'; |
| 299 | let data = new FormData(); |
| 300 | data.append( 'action', 'cff_deactivate_license' ); |
| 301 | data.append( 'nonce', this.nonce ); |
| 302 | fetch(this.ajaxHandler, { |
| 303 | method: "POST", |
| 304 | credentials: 'same-origin', |
| 305 | body: data |
| 306 | }) |
| 307 | .then(response => response.json()) |
| 308 | .then(data => { |
| 309 | if ( data.success == true ) { |
| 310 | this.licenseStatus = data.data.licenseStatus ; |
| 311 | this.loading = false; |
| 312 | this.pressedBtnName = null; |
| 313 | } |
| 314 | return; |
| 315 | }); |
| 316 | }, |
| 317 | |
| 318 | /** |
| 319 | * Activate Extensions License |
| 320 | * |
| 321 | * @since 4.0 |
| 322 | * |
| 323 | * @param {object} extension |
| 324 | */ |
| 325 | activateExtensionLicense: function( extension ) { |
| 326 | let licenseKey = this.extensionsLicenseKey[extension.name]; |
| 327 | this.extensionFieldHasError = false; |
| 328 | this.loading = true; |
| 329 | this.pressedBtnName = extension.name; |
| 330 | if ( ! licenseKey ) { |
| 331 | this.loading = false; |
| 332 | this.extensionFieldHasError = true; |
| 333 | return; |
| 334 | } |
| 335 | let data = new FormData(); |
| 336 | data.append( 'action', 'cff_activate_extension_license' ); |
| 337 | data.append( 'license_key', licenseKey ); |
| 338 | data.append( 'extension_name', extension.name ); |
| 339 | data.append( 'extension_item_name', extension.itemName ); |
| 340 | data.append( 'nonce', this.nonce ); |
| 341 | fetch(this.ajaxHandler, { |
| 342 | method: "POST", |
| 343 | credentials: 'same-origin', |
| 344 | body: data |
| 345 | }) |
| 346 | .then(response => response.json()) |
| 347 | .then(data => { |
| 348 | this.loading = false; |
| 349 | if ( data.success == true ) { |
| 350 | this.extensionFieldHasError = false; |
| 351 | this.pressedBtnName = null; |
| 352 | if ( data.data.licenseStatus == 'invalid' ) { |
| 353 | this.extensionFieldHasError = true; |
| 354 | this.notificationElement = { |
| 355 | type : 'error', |
| 356 | text : this.genericText.invalidLicenseKey, |
| 357 | shown : "shown" |
| 358 | }; |
| 359 | } |
| 360 | if ( data.data.licenseStatus == 'valid' ) { |
| 361 | this.notificationElement = { |
| 362 | type : 'success', |
| 363 | text : this.genericText.licenseActivated, |
| 364 | shown : "shown" |
| 365 | }; |
| 366 | } |
| 367 | extension.licenseStatus = data.data.licenseStatus; |
| 368 | extension.licenseKey = licenseKey; |
| 369 | |
| 370 | setTimeout(function(){ |
| 371 | this.notificationElement.shown = "hidden"; |
| 372 | }.bind(this), 3000); |
| 373 | } |
| 374 | return; |
| 375 | }); |
| 376 | }, |
| 377 | |
| 378 | licenseActiveAction: function(extension) { |
| 379 | extension = typeof extension !== 'undefined' ? extension : false; |
| 380 | if (this.licenseType === 'free') { |
| 381 | this.runOneClickUpgrade(); |
| 382 | } else { |
| 383 | if (typeof extension !== 'undefined') { |
| 384 | this.deactivateExtensionLicense(extension); |
| 385 | } else { |
| 386 | this.deactivateLicense(); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | }, |
| 391 | |
| 392 | /** |
| 393 | * Deactivate Extensions License |
| 394 | * |
| 395 | * @since 4.0 |
| 396 | * |
| 397 | * @param {object} extension |
| 398 | */ |
| 399 | deactivateExtensionLicense: function( extension ) { |
| 400 | let licenseKey = this.extensionsLicenseKey[extension.name]; |
| 401 | this.extensionFieldHasError = false; |
| 402 | this.loading = true; |
| 403 | this.pressedBtnName = extension.name; |
| 404 | let data = new FormData(); |
| 405 | data.append( 'action', 'cff_deactivate_extension_license' ); |
| 406 | data.append( 'extension_name', extension.name ); |
| 407 | data.append( 'extension_item_name', extension.itemName ); |
| 408 | data.append( 'nonce', this.nonce ); |
| 409 | fetch(this.ajaxHandler, { |
| 410 | method: "POST", |
| 411 | credentials: 'same-origin', |
| 412 | body: data |
| 413 | }) |
| 414 | .then(response => response.json()) |
| 415 | .then(data => { |
| 416 | this.loading = false; |
| 417 | if ( data.success == true ) { |
| 418 | this.extensionFieldHasError = false; |
| 419 | this.pressedBtnName = null; |
| 420 | if ( data.data.licenseStatus == 'deactivated' ) { |
| 421 | this.notificationElement = { |
| 422 | type : 'success', |
| 423 | text : this.genericText.licenseDeactivated, |
| 424 | shown : "shown" |
| 425 | }; |
| 426 | } |
| 427 | extension.licenseStatus = data.data.licenseStatus; |
| 428 | extension.licenseKey = licenseKey; |
| 429 | |
| 430 | setTimeout(function(){ |
| 431 | this.notificationElement.shown = "hidden"; |
| 432 | }.bind(this), 3000); |
| 433 | } |
| 434 | return; |
| 435 | }); |
| 436 | }, |
| 437 | testConnection: function() { |
| 438 | this.testConnectionStatus = 'loading'; |
| 439 | let data = new FormData(); |
| 440 | data.append( 'action', 'cff_test_connection' ); |
| 441 | data.append( 'nonce', this.nonce ); |
| 442 | fetch(this.ajaxHandler, { |
| 443 | method: "POST", |
| 444 | credentials: 'same-origin', |
| 445 | body: data |
| 446 | }) |
| 447 | .then(response => response.json()) |
| 448 | .then(data => { |
| 449 | if ( data.success == false ) { |
| 450 | this.testConnectionStatus = 'error'; |
| 451 | } |
| 452 | if ( data.success == true ) { |
| 453 | this.testConnectionStatus = 'success'; |
| 454 | |
| 455 | setTimeout(function() { |
| 456 | this.testConnectionStatus = null; |
| 457 | }.bind(this), 3000); |
| 458 | } |
| 459 | return; |
| 460 | }); |
| 461 | }, |
| 462 | testConnectionIcon: function() { |
| 463 | if ( this.testConnectionStatus == 'loading' ) { |
| 464 | return this.loaderSVG; |
| 465 | } else if ( this.testConnectionStatus == 'success' ) { |
| 466 | return '<i class="fa fa-check-circle"></i> ' + this.generalTab.licenseBox.connectionSuccessful; |
| 467 | } else if ( this.testConnectionStatus == 'error' ) { |
| 468 | return `<i class="fa fa-check-circle"></i> ${this.generalTab.licenseBox.connectionFailed} <a href="#">${this.generalTab.licenseBox.viewError}</a>`; |
| 469 | } |
| 470 | }, |
| 471 | importFile: function() { |
| 472 | document.getElementById("import_file").click(); |
| 473 | }, |
| 474 | uploadFile: function( event ) { |
| 475 | this.uploadStatus = 'loading'; |
| 476 | let file = this.$refs.file.files[0]; |
| 477 | let data = new FormData(); |
| 478 | data.append( 'action', 'cff_import_settings_json' ); |
| 479 | data.append( 'nonce', this.nonce ); |
| 480 | data.append( 'file', file ); |
| 481 | fetch(this.ajaxHandler, { |
| 482 | method: "POST", |
| 483 | credentials: 'same-origin', |
| 484 | body: data |
| 485 | }) |
| 486 | .then(response => response.json()) |
| 487 | .then(data => { |
| 488 | this.uploadStatus = null; |
| 489 | this.$refs.file.files[0] = null; |
| 490 | if ( data.success == false ) { |
| 491 | this.notificationElement = { |
| 492 | type : 'error', |
| 493 | text : this.genericText.failedToImportFeed, |
| 494 | shown : "shown" |
| 495 | }; |
| 496 | } |
| 497 | if ( data.success == true ) { |
| 498 | this.feeds = data.data.feeds; |
| 499 | this.notificationElement = { |
| 500 | type : 'success', |
| 501 | text : this.genericText.feedImported, |
| 502 | shown : "shown" |
| 503 | }; |
| 504 | } |
| 505 | setTimeout(function(){ |
| 506 | this.notificationElement.shown = "hidden"; |
| 507 | }.bind(this), 3000); |
| 508 | }); |
| 509 | }, |
| 510 | exportFeedSettings: function() { |
| 511 | // return if no feed is selected |
| 512 | if ( this.exportFeed === 'none' ) { |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | let url = this.ajaxHandler + '?action=cff_export_settings_json&feed_id=' + this.exportFeed + '&nonce=' + this.nonce; |
| 517 | window.location = url; |
| 518 | }, |
| 519 | saveSettings: function() { |
| 520 | this.btnStatus = 'loading'; |
| 521 | let data = new FormData(); |
| 522 | data.append( 'action', 'cff_save_settings' ); |
| 523 | data.append( 'nonce', this.nonce ); |
| 524 | data.append( 'model', JSON.stringify( this.model ) ); |
| 525 | data.append( 'cff_license_key', this.licenseKey ); |
| 526 | data.append( 'extensions_license_key', JSON.stringify( this.extensionsLicenseKey ) ); |
| 527 | fetch(this.ajaxHandler, { |
| 528 | method: "POST", |
| 529 | credentials: 'same-origin', |
| 530 | body: data |
| 531 | }) |
| 532 | .then(response => response.json()) |
| 533 | .then(data => { |
| 534 | if ( data.success == false ) { |
| 535 | this.btnStatus = 'error'; |
| 536 | return; |
| 537 | } |
| 538 | |
| 539 | this.cronNextCheck = data.data.cronNextCheck; |
| 540 | this.btnStatus = 'success'; |
| 541 | setTimeout(function() { |
| 542 | this.btnStatus = null; |
| 543 | }.bind(this), 3000); |
| 544 | }); |
| 545 | }, |
| 546 | clearCache: function() { |
| 547 | this.clearCacheStatus = 'loading'; |
| 548 | let data = new FormData(); |
| 549 | data.append( 'action', 'cff_clear_cache' ); |
| 550 | data.append( 'model', JSON.stringify( this.model ) ); |
| 551 | data.append( 'nonce', this.nonce ); |
| 552 | fetch(this.ajaxHandler, { |
| 553 | method: "POST", |
| 554 | credentials: 'same-origin', |
| 555 | body: data |
| 556 | }) |
| 557 | .then(response => response.json()) |
| 558 | .then(data => { |
| 559 | if ( data.success == false ) { |
| 560 | this.clearCacheStatus = 'error'; |
| 561 | return; |
| 562 | } |
| 563 | |
| 564 | this.cronNextCheck = data.data.cronNextCheck; |
| 565 | this.clearCacheStatus = 'success'; |
| 566 | setTimeout(function() { |
| 567 | this.clearCacheStatus = null; |
| 568 | }.bind(this), 3000); |
| 569 | }); |
| 570 | }, |
| 571 | showTooltip: function( tooltipName ) { |
| 572 | this.tooltipName = tooltipName; |
| 573 | }, |
| 574 | hideTooltip: function() { |
| 575 | this.tooltipName = null; |
| 576 | }, |
| 577 | gdprOptions: function() { |
| 578 | this.gdprInfoTooltip = null; |
| 579 | }, |
| 580 | gdprLimited: function() { |
| 581 | this.gdprInfoTooltip = this.gdprInfoTooltip == null ? true : null; |
| 582 | }, |
| 583 | clearImageResizeCache: function() { |
| 584 | this.optimizeCacheStatus = 'loading'; |
| 585 | let data = new FormData(); |
| 586 | data.append( 'action', 'cff_clear_image_resize_cache' ); |
| 587 | data.append( 'nonce', this.nonce ); |
| 588 | fetch(this.ajaxHandler, { |
| 589 | method: "POST", |
| 590 | credentials: 'same-origin', |
| 591 | body: data |
| 592 | }) |
| 593 | .then(response => response.json()) |
| 594 | .then(data => { |
| 595 | if ( data.success == false ) { |
| 596 | this.optimizeCacheStatus = 'error'; |
| 597 | return; |
| 598 | } |
| 599 | this.optimizeCacheStatus = 'success'; |
| 600 | setTimeout(function() { |
| 601 | this.optimizeCacheStatus = null; |
| 602 | }.bind(this), 3000); |
| 603 | }); |
| 604 | }, |
| 605 | dpaReset: function() { |
| 606 | this.dpaResetStatus = 'loading'; |
| 607 | let data = new FormData(); |
| 608 | data.append( 'action', 'cff_dpa_reset' ); |
| 609 | data.append( 'nonce', this.nonce ); |
| 610 | fetch(this.ajaxHandler, { |
| 611 | method: "POST", |
| 612 | credentials: 'same-origin', |
| 613 | body: data |
| 614 | }) |
| 615 | .then(response => response.json()) |
| 616 | .then(data => { |
| 617 | if ( data.success == false ) { |
| 618 | this.dpaResetStatus = 'error'; |
| 619 | return; |
| 620 | } |
| 621 | this.dpaResetStatus = 'success'; |
| 622 | setTimeout(function() { |
| 623 | this.dpaResetStatus = null; |
| 624 | }.bind(this), 3000); |
| 625 | }); |
| 626 | }, |
| 627 | dpaResetStatusIcon: function() { |
| 628 | if ( this.dpaResetStatus === null ) { |
| 629 | return; |
| 630 | } |
| 631 | if ( this.dpaResetStatus == 'loading' ) { |
| 632 | return this.loaderSVG; |
| 633 | } else if ( this.dpaResetStatus == 'success' ) { |
| 634 | return this.checkmarkSVG; |
| 635 | } else if ( this.dpaResetStatus == 'error' ) { |
| 636 | return `<i class="fa fa-times-circle"></i>`; |
| 637 | } |
| 638 | }, |
| 639 | saveChangesIcon: function() { |
| 640 | if ( this.btnStatus == 'loading' ) { |
| 641 | return this.loaderSVG; |
| 642 | } else if ( this.btnStatus == 'success' ) { |
| 643 | return this.checkmarkSVG; |
| 644 | } else if ( this.btnStatus == 'error' ) { |
| 645 | return `<i class="fa fa-times-circle"></i>`; |
| 646 | } |
| 647 | }, |
| 648 | importBtnIcon: function() { |
| 649 | if ( this.uploadStatus === null ) { |
| 650 | return this.uploadSVG; |
| 651 | } |
| 652 | if ( this.uploadStatus == 'loading' ) { |
| 653 | return this.loaderSVG; |
| 654 | } else if ( this.uploadStatus == 'success' ) { |
| 655 | return this.checkmarkSVG; |
| 656 | } else if ( this.uploadStatus == 'error' ) { |
| 657 | return `<i class="fa fa-times-circle"></i>`; |
| 658 | } |
| 659 | }, |
| 660 | clearCacheIcon: function() { |
| 661 | if ( this.clearCacheStatus === null ) { |
| 662 | return this.reloadSVG; |
| 663 | } |
| 664 | if ( this.clearCacheStatus == 'loading' ) { |
| 665 | return this.loaderSVG; |
| 666 | } else if ( this.clearCacheStatus == 'success' ) { |
| 667 | return this.checkmarkSVG; |
| 668 | } else if ( this.clearCacheStatus == 'error' ) { |
| 669 | return `<i class="fa fa-times-circle"></i>`; |
| 670 | } |
| 671 | }, |
| 672 | clearImageResizeCacheIcon: function() { |
| 673 | if ( this.optimizeCacheStatus === null ) { |
| 674 | return; |
| 675 | } |
| 676 | if ( this.optimizeCacheStatus == 'loading' ) { |
| 677 | return this.loaderSVG; |
| 678 | } else if ( this.optimizeCacheStatus == 'success' ) { |
| 679 | return this.checkmarkSVG; |
| 680 | } else if ( this.optimizeCacheStatus == 'error' ) { |
| 681 | return `<i class="fa fa-times-circle"></i>`; |
| 682 | } |
| 683 | }, |
| 684 | |
| 685 | printUsedInText: function( usedInNumber ){ |
| 686 | if(usedInNumber == 0){ |
| 687 | return this.genericText.sourceNotUsedYet; |
| 688 | } |
| 689 | return this.genericText.usedIn + ' ' + usedInNumber + ' ' +(usedInNumber == 1 ? this.genericText.feed : this.genericText.feeds); |
| 690 | }, |
| 691 | |
| 692 | /** |
| 693 | * Delete Source Ajax |
| 694 | * |
| 695 | * @since 4.0 |
| 696 | */ |
| 697 | deleteSource : function(sourceToDelete){ |
| 698 | var self = this; |
| 699 | let data = new FormData(); |
| 700 | data.append( 'action', 'cff_feed_saver_manager_delete_source' ); |
| 701 | data.append( 'nonce', this.nonce ); |
| 702 | data.append( 'source_id', sourceToDelete.id); |
| 703 | fetch(self.ajaxHandler, { |
| 704 | method: "POST", |
| 705 | credentials: 'same-origin', |
| 706 | body: data |
| 707 | }) |
| 708 | .then(response => response.json()) |
| 709 | .then(data => { |
| 710 | self.sourcesList = data; |
| 711 | }); |
| 712 | }, |
| 713 | |
| 714 | /** |
| 715 | * Check if Value is Empty |
| 716 | * |
| 717 | * @since 4.0 |
| 718 | * |
| 719 | * @return boolean |
| 720 | */ |
| 721 | checkNotEmpty : function(value){ |
| 722 | return value != null && value.replace(/ /gi,'') != ''; |
| 723 | }, |
| 724 | |
| 725 | /** |
| 726 | * Activate View |
| 727 | * |
| 728 | * @since 4.0 |
| 729 | */ |
| 730 | activateView : function(viewName, sourcePopupType = 'creation', ajaxAction = false){ |
| 731 | var self = this; |
| 732 | self.viewsActive[viewName] = (self.viewsActive[viewName] == false ) ? true : false; |
| 733 | if(viewName == 'sourcePopup' && sourcePopupType == 'creationRedirect'){ |
| 734 | setTimeout(function(){ |
| 735 | self.$refs.addSourceRef.processFBConnect() |
| 736 | },3500); |
| 737 | } |
| 738 | }, |
| 739 | |
| 740 | /** |
| 741 | * Switch & Change Feed Screens |
| 742 | * |
| 743 | * @since 4.0 |
| 744 | */ |
| 745 | switchScreen: function(screenType, screenName){ |
| 746 | this.viewsActive[screenType] = screenName; |
| 747 | }, |
| 748 | |
| 749 | /** |
| 750 | * Parse JSON |
| 751 | * |
| 752 | * @since 4.0 |
| 753 | * |
| 754 | * @return jsonObject / Boolean |
| 755 | */ |
| 756 | jsonParse : function(jsonString){ |
| 757 | try { |
| 758 | return JSON.parse(jsonString); |
| 759 | } catch(e) { |
| 760 | return false; |
| 761 | } |
| 762 | }, |
| 763 | |
| 764 | |
| 765 | /** |
| 766 | * Ajax Post Action |
| 767 | * |
| 768 | * @since 4.0 |
| 769 | */ |
| 770 | ajaxPost : function(data, callback){ |
| 771 | var self = this; |
| 772 | data['nonce'] = self.nonce; |
| 773 | data['settings_page'] = true; |
| 774 | |
| 775 | self.$http.post(self.ajaxHandler,data).then(callback); |
| 776 | }, |
| 777 | |
| 778 | /** |
| 779 | * Check if Object has Nested Property |
| 780 | * |
| 781 | * @since 4.0 |
| 782 | * |
| 783 | * @return boolean |
| 784 | */ |
| 785 | hasOwnNestedProperty : function(obj,propertyPath) { |
| 786 | if (!propertyPath){return false;}var properties = propertyPath.split('.'); |
| 787 | for (var i = 0; i < properties.length; i++) { |
| 788 | var prop = properties[i]; |
| 789 | if (!obj || !obj.hasOwnProperty(prop)) { |
| 790 | return false; |
| 791 | } else { |
| 792 | obj = obj[prop]; |
| 793 | } |
| 794 | } |
| 795 | return true; |
| 796 | }, |
| 797 | |
| 798 | /** |
| 799 | * Show Tooltip on Hover |
| 800 | * |
| 801 | * @since 4.0 |
| 802 | */ |
| 803 | toggleElementTooltip : function(tooltipText, type, align = 'center'){ |
| 804 | var self = this, |
| 805 | target = window.event.currentTarget, |
| 806 | tooltip = (target != undefined && target != null) ? document.querySelector('.sb-control-elem-tltp-content') : null; |
| 807 | if(tooltip != null && type == 'show'){ |
| 808 | self.tooltip.text = tooltipText; |
| 809 | var position = target.getBoundingClientRect(), |
| 810 | left = position.left + 7, |
| 811 | top = position.top - 15; |
| 812 | tooltip.style.left = left + 'px'; |
| 813 | tooltip.style.top = top + 'px'; |
| 814 | tooltip.style.textAlign = align; |
| 815 | self.tooltip.hover = true; |
| 816 | } |
| 817 | if(type == 'hide'){ |
| 818 | self.tooltip.hover = false; |
| 819 | } |
| 820 | }, |
| 821 | |
| 822 | /** |
| 823 | * Hover Tooltip |
| 824 | * |
| 825 | * @since 4.0 |
| 826 | */ |
| 827 | hoverTooltip : function(type){ |
| 828 | this.tooltip.hover = type; |
| 829 | }, |
| 830 | |
| 831 | /** |
| 832 | * Open Dialog Box |
| 833 | * |
| 834 | * @since 4.0 |
| 835 | */ |
| 836 | openDialogBox : function(type, args = []){ |
| 837 | var self = this, |
| 838 | heading = self.dialogBoxPopupScreen[type].heading, |
| 839 | description = self.dialogBoxPopupScreen[type].description; |
| 840 | |
| 841 | switch (type) { |
| 842 | case "deleteSource": |
| 843 | self.sourceToDelete = args; |
| 844 | heading = heading.replace("#", self.sourceToDelete.username); |
| 845 | break; |
| 846 | } |
| 847 | self.dialogBox = { |
| 848 | active : true, |
| 849 | type : type, |
| 850 | heading : heading, |
| 851 | description : description |
| 852 | }; |
| 853 | }, |
| 854 | |
| 855 | |
| 856 | /** |
| 857 | * Confirm Dialog Box Actions |
| 858 | * |
| 859 | * @since 4.0 |
| 860 | */ |
| 861 | confirmDialogAction : function(){ |
| 862 | var self = this; |
| 863 | switch (self.dialogBox.type) { |
| 864 | case 'deleteSource': |
| 865 | self.deleteSource(self.sourceToDelete); |
| 866 | break; |
| 867 | } |
| 868 | }, |
| 869 | |
| 870 | /** |
| 871 | * Display Feed Sources Settings |
| 872 | * |
| 873 | * @since 4.0 |
| 874 | * |
| 875 | * @param {object} source |
| 876 | * @param {int} sourceIndex |
| 877 | */ |
| 878 | displayFeedSettings: function(source, sourceIndex) { |
| 879 | this.expandedFeedID = sourceIndex + 1; |
| 880 | }, |
| 881 | |
| 882 | /** |
| 883 | * Hide Feed Sources Settings |
| 884 | * |
| 885 | * @since 4.0 |
| 886 | * |
| 887 | * @param {object} source |
| 888 | * @param {int} sourceIndex |
| 889 | */ |
| 890 | hideFeedSettings: function() { |
| 891 | this.expandedFeedID = null; |
| 892 | }, |
| 893 | |
| 894 | /** |
| 895 | * Copy text to clipboard |
| 896 | * |
| 897 | * @since 4.0 |
| 898 | */ |
| 899 | copyToClipBoard : function(value){ |
| 900 | var self = this; |
| 901 | const el = document.createElement('textarea'); |
| 902 | el.className = 'cff-fb-cp-clpboard'; |
| 903 | el.value = value; |
| 904 | document.body.appendChild(el); |
| 905 | el.select(); |
| 906 | document.execCommand('copy'); |
| 907 | document.body.removeChild(el); |
| 908 | self.notificationElement = { |
| 909 | type : 'success', |
| 910 | text : this.genericText.copiedClipboard, |
| 911 | shown : "shown" |
| 912 | }; |
| 913 | setTimeout(function(){ |
| 914 | self.notificationElement.shown = "hidden"; |
| 915 | }, 3000); |
| 916 | }, |
| 917 | |
| 918 | |
| 919 | /** |
| 920 | * View Source Instances |
| 921 | * |
| 922 | * @since 4.0 |
| 923 | */ |
| 924 | viewSourceInstances : function(source){ |
| 925 | var self = this; |
| 926 | self.viewsActive.instanceSourceActive = source; |
| 927 | }, |
| 928 | } |
| 929 | }); |
| 930 | |
| 931 |