add-source.js
1 month ago
builder.js
1 month ago
confirm-dialog.js
1 month ago
date_i18n.js
1 month ago
install-plugin-popup.js
1 month ago
jquery.tooltipster.min.js
1 month ago
oembed.js
1 month ago
owl.autoheight.js
1 month ago
ressources.js
1 month ago
tooltip-wizard.js
1 month ago
vue-color.min.js
1 month ago
builder.js
3311 lines
| 1 | var cffBuilder, |
| 2 | cffStorage = window.localStorage, |
| 3 | sketch = VueColor.Sketch; |
| 4 | |
| 5 | /** |
| 6 | * VueJS Dummy Lightbox |
| 7 | * |
| 8 | * @since 4.0 |
| 9 | */ |
| 10 | Vue.component('cff-dummy-lightbox', { |
| 11 | name: 'cff-dummy-lightbox', |
| 12 | template: '#cff-dummy-lightbox', |
| 13 | props: ['customizerScreens','customizerFeedData'], |
| 14 | methods : { |
| 15 | |
| 16 | } |
| 17 | }); |
| 18 | |
| 19 | /** |
| 20 | * VueJS Iframe, Link, Video Component |
| 21 | * |
| 22 | * @since 4.0 |
| 23 | */ |
| 24 | Vue.component('cff-iframe-media-component', { |
| 25 | name: 'cff-iframe-media-component', |
| 26 | template: '#cff-iframe-media-component', |
| 27 | props: ['postmedia','customizerFeedData','singlePost','pluginType'], |
| 28 | methods : { |
| 29 | /** |
| 30 | * Check Whether to display the Iframe (video + sound) |
| 31 | * Depending on the feed settings |
| 32 | * |
| 33 | * @since 4.0 |
| 34 | * |
| 35 | * @return bool |
| 36 | */ |
| 37 | checkIframePostDisplay : function( postMedia ){ |
| 38 | var self = this; |
| 39 | return postMedia.type == 'embed' && |
| 40 | ( |
| 41 | ( self.customizerFeedData.settings.include.includes('media') && postMedia.site == 'video' ) |
| 42 | || |
| 43 | ( self.customizerFeedData.settings.include.includes('sharedlinks') && postMedia.site != 'video' ) |
| 44 | ); |
| 45 | }, |
| 46 | } |
| 47 | }); |
| 48 | /** |
| 49 | * VueJS Iframe, Link, Video Component |
| 50 | * |
| 51 | * @since 4.0 |
| 52 | */ |
| 53 | Vue.component('cff-free-linkbox-component', { |
| 54 | name: 'cff-free-linkbox-component', |
| 55 | template: '#cff-free-linkbox-component', |
| 56 | props: ['postmedia','customizerFeedData','singlePost','pluginType'], |
| 57 | methods : { |
| 58 | /** |
| 59 | * Check Whether to display the Iframe (video + sound) |
| 60 | * Depending on the feed settings |
| 61 | * |
| 62 | * @since 4.0 |
| 63 | * |
| 64 | * @return bool |
| 65 | */ |
| 66 | checkIframePostDisplay : function( postMedia ){ |
| 67 | var self = this; |
| 68 | return postMedia.type == 'embed' && |
| 69 | ( |
| 70 | ( self.customizerFeedData.settings.include.includes('media') && postMedia.site == 'video' ) |
| 71 | || |
| 72 | ( self.customizerFeedData.settings.include.includes('sharedlinks') && postMedia.site != 'video' ) |
| 73 | ); |
| 74 | }, |
| 75 | } |
| 76 | }); |
| 77 | |
| 78 | /** |
| 79 | * VueJS Post Preview Components |
| 80 | * |
| 81 | * @since 4.0 |
| 82 | */ |
| 83 | var postPreviewComponents = [ |
| 84 | 'author', |
| 85 | 'text', |
| 86 | 'event-detail', |
| 87 | 'media', |
| 88 | 'meta', |
| 89 | 'overlay', |
| 90 | 'lightbox', |
| 91 | 'full-layout', |
| 92 | 'half-layout', |
| 93 | 'thumb-layout', |
| 94 | 'videosposts', |
| 95 | 'reviewsposts', |
| 96 | 'dummy-lightbox', |
| 97 | 'free-icon', |
| 98 | 'likebox' |
| 99 | |
| 100 | ]; |
| 101 | |
| 102 | postPreviewComponents.forEach( function( component ) { |
| 103 | var nameComponent = 'cff-post-'+component+'-component'; |
| 104 | Vue.component( nameComponent , { |
| 105 | template: '#' + nameComponent, |
| 106 | props: ['singlePost','customizerFeedData','translatedText','parent','lightBox','dummyLightBoxData','pluginType'] |
| 107 | }); |
| 108 | }); |
| 109 | |
| 110 | |
| 111 | |
| 112 | /** |
| 113 | * VueJS Global App Builder |
| 114 | * |
| 115 | * @since 4.0 |
| 116 | */ |
| 117 | cffBuilder = new Vue({ |
| 118 | el: '#cff-builder-app', |
| 119 | http: { |
| 120 | emulateJSON: true, |
| 121 | emulateHTTP: true |
| 122 | }, |
| 123 | components: { |
| 124 | 'sketch-picker': sketch |
| 125 | }, |
| 126 | mixins: [VueClickaway.mixin], |
| 127 | data: { |
| 128 | nonce : cff_builder.nonce, |
| 129 | admin_nonce: cff_builder.admin_nonce, |
| 130 | plugins: cff_builder.installPluginsPopup, |
| 131 | dismissLite : cff_builder.facebook_feed_dismiss_lite, |
| 132 | supportPageUrl: cff_builder.supportPageUrl, |
| 133 | builderUrl : cff_builder.builderUrl, |
| 134 | pluginType : cff_builder.pluginType, |
| 135 | genericText : cff_builder.genericText, |
| 136 | ajaxHandler : cff_builder.ajax_handler, |
| 137 | adminPostURL : cff_builder.adminPostURL, |
| 138 | widgetsPageURL : cff_builder.widgetsPageURL, |
| 139 | translatedText : cff_builder.translatedText, |
| 140 | socialShareLink : cff_builder.socialShareLink, |
| 141 | licenseType: cff_builder.licenseType, |
| 142 | freeCtaShowFeatures: false, |
| 143 | upgradeUrl: cff_builder.upgradeUrl, |
| 144 | |
| 145 | welcomeScreen : cff_builder.welcomeScreen, |
| 146 | allFeedsScreen : cff_builder.allFeedsScreen, |
| 147 | extensionsPopup : cff_builder.extensionsPopup, |
| 148 | mainFooterScreen : cff_builder.mainFooterScreen, |
| 149 | embedPopupScreen : cff_builder.embedPopupScreen, |
| 150 | |
| 151 | newManualSourcePopup : cff_builder.newManualSourcePopup, |
| 152 | |
| 153 | selectSourceScreen : cff_builder.selectSourceScreen, |
| 154 | customizeScreensText : cff_builder.customizeScreens, |
| 155 | dialogBoxPopupScreen : cff_builder.dialogBoxPopupScreen, |
| 156 | selectFeedTypeScreen : cff_builder.selectFeedTypeScreen, |
| 157 | selectFeedTemplateScreen : cff_builder.selectFeedTemplateScreen, |
| 158 | addFeaturedPostScreen : cff_builder.addFeaturedPostScreen, |
| 159 | addFeaturedAlbumScreen : cff_builder.addFeaturedAlbumScreen, |
| 160 | addVideosPostScreen : cff_builder.addVideosPostScreen, |
| 161 | dummyLightBoxData : cff_builder.dummyLightBoxData, |
| 162 | |
| 163 | svgIcons : cff_builder.svgIcons, |
| 164 | feedsList : cff_builder.feeds, |
| 165 | feedTypes : cff_builder.feedTypes, |
| 166 | socialInfo : cff_builder.socialInfo, |
| 167 | sourcesList : cff_builder.sources, |
| 168 | links : cff_builder.links, |
| 169 | legacyFeedsList : cff_builder.legacyFeeds, |
| 170 | activeExtensions : cff_builder.activeExtensions, |
| 171 | advancedFeedTypes : cff_builder.advancedFeedTypes, |
| 172 | groupSourcesNumber : cff_builder.groupSourcesNumber, |
| 173 | //Selected Feed type => TimeLine / Photos ... or Advanced ones! |
| 174 | selectedFeed : 'timeline', |
| 175 | |
| 176 | // Will be changed depending on the feed type Selected () |
| 177 | type : [ |
| 178 | 'links', |
| 179 | 'events', |
| 180 | 'videos', |
| 181 | 'photos', |
| 182 | 'albums', |
| 183 | 'statuses' |
| 184 | ], |
| 185 | |
| 186 | selectedSources : [], |
| 187 | viewsActive : { |
| 188 | //Screens where the footer widget is disabled |
| 189 | footerDiabledScreens : [ |
| 190 | 'welcome', |
| 191 | 'selectFeed' |
| 192 | ], |
| 193 | |
| 194 | // welcome, selectFeed |
| 195 | pageScreen : 'welcome', |
| 196 | |
| 197 | // feedsType, selectSource, feedsTypeGetProcess |
| 198 | selectedFeedSection : 'feedsType', |
| 199 | |
| 200 | sourcePopup : false, |
| 201 | feedtypesPopup : false, |
| 202 | feedtemplatesPopup : false, |
| 203 | // step_1 [Add New Source] , step_2 [Connect to a user pages/groups], step_3 [Add Manually] |
| 204 | sourcePopupScreen : 'redirect_1', |
| 205 | |
| 206 | // creation or customizer |
| 207 | sourcePopupType : 'creation', |
| 208 | extensionsPopupElement : false, |
| 209 | feedTypeElement : null, |
| 210 | instanceFeedActive : null, |
| 211 | clipboardCopiedNotif : false, |
| 212 | legacyFeedsShown : false, |
| 213 | editName : false, |
| 214 | embedPopup : false, |
| 215 | embedPopupScreen : 'step_1', |
| 216 | embedPopupSelectedPage : null, |
| 217 | |
| 218 | // onboarding |
| 219 | onboardingPopup : cff_builder.allFeedsScreen.onboarding.active, |
| 220 | onboardingStep : 1, |
| 221 | |
| 222 | // customizer onboarding |
| 223 | onboardingCustomizerPopup : cff_builder.customizeScreens.onboarding.active, |
| 224 | |
| 225 | // plugin install popup |
| 226 | installPluginPopup : false, |
| 227 | installPluginModal: 'instagram' |
| 228 | }, |
| 229 | |
| 230 | //Feeds Pagination |
| 231 | feedPagination : { |
| 232 | feedsCount : cff_builder.feedsCount != undefined ? cff_builder.feedsCount : null, |
| 233 | pagesNumber : 1, |
| 234 | currentPage : 1, |
| 235 | itemsPerPage : cff_builder.itemsPerPage != undefined ? cff_builder.itemsPerPage : null, |
| 236 | }, |
| 237 | |
| 238 | //Add New Source |
| 239 | newSourceData : cff_builder.newSourceData ? cff_builder.newSourceData : null, |
| 240 | sourceConnectionURLs : cff_builder.sourceConnectionURLs, |
| 241 | returnedApiSourcesList : [], |
| 242 | addNewSource : { |
| 243 | typeSelected : 'page', |
| 244 | manualSourceID : null, |
| 245 | manualSourceToken : null |
| 246 | }, |
| 247 | selectedSourcesToConnect : [], |
| 248 | |
| 249 | //Feeds Types Get Info |
| 250 | extraProcessFeedsTypes : [ |
| 251 | //'events', |
| 252 | 'singlealbum', |
| 253 | 'featuredpost', |
| 254 | 'videos' |
| 255 | ], |
| 256 | isCreateProcessGood : false, |
| 257 | feedCreationInfoUrl : null, |
| 258 | feedsSelected : [], |
| 259 | selectedBulkAction : false, |
| 260 | singleAlbumFeedInfo : { |
| 261 | url : '', |
| 262 | info : {}, |
| 263 | success: false, |
| 264 | isError : false |
| 265 | }, |
| 266 | featuredPostFeedInfo : { |
| 267 | url : '', |
| 268 | info : {}, |
| 269 | success: false, |
| 270 | isError : false |
| 271 | }, |
| 272 | videosTypeInfo : { |
| 273 | type : 'all', |
| 274 | info : {}, |
| 275 | playListUrl : null, |
| 276 | success: false, |
| 277 | playListUrlError : false |
| 278 | }, |
| 279 | |
| 280 | customizerFeedDataInitial : null, |
| 281 | customizerFeedData : cff_builder.customizerFeedData, |
| 282 | wordpressPageLists : cff_builder.wordpressPageLists, |
| 283 | iscustomizerScreen : (cff_builder.customizerFeedData != undefined && cff_builder.customizerFeedData != false), |
| 284 | |
| 285 | customizerSidebarBuilder : cff_builder.customizerSidebarBuilder, |
| 286 | feedTemplates : cff_builder.feedTemplates, |
| 287 | customizerScreens : { |
| 288 | activeTab : 'customize', |
| 289 | printedType : {}, |
| 290 | activeSection : null, |
| 291 | printedTemplate : {}, |
| 292 | |
| 293 | previewScreen : 'desktop', |
| 294 | sourceExpanded : null, |
| 295 | sourcesChoosed : [], |
| 296 | inputNameWidth : '0px', |
| 297 | activeSectionData : null, |
| 298 | parentActiveSection : null, //For nested Setions |
| 299 | parentActiveSectionData : null, //For nested Setions |
| 300 | activeColorPicker : null, |
| 301 | popupBackButton : ['photos','videos','albums','events','reviews','featuredpost','singlealbum','socialwall', 'feedTemplates'] |
| 302 | }, |
| 303 | previewScreens: [ |
| 304 | 'desktop', |
| 305 | 'tablet', |
| 306 | 'mobile' |
| 307 | ], |
| 308 | |
| 309 | nestedStylingSection : [ |
| 310 | 'post_styling_author', |
| 311 | 'post_styling_text', |
| 312 | 'post_styling_date', |
| 313 | 'post_styling_media', |
| 314 | 'post_styling_social', |
| 315 | 'post_styling_eventtitle', |
| 316 | 'post_styling_eventdetails', |
| 317 | 'post_styling_link', |
| 318 | 'post_styling_desc', |
| 319 | 'post_styling_sharedlinks' |
| 320 | ], |
| 321 | |
| 322 | sourceToDelete : {}, |
| 323 | feedToDelete : {}, |
| 324 | dialogBox : { |
| 325 | active : false, |
| 326 | type : null, //deleteSourceCustomizer |
| 327 | heading : null, |
| 328 | description : null |
| 329 | }, |
| 330 | |
| 331 | feedStyle : '', |
| 332 | expandedPostText : [], |
| 333 | showedSocialShareTooltip : null, |
| 334 | showedCommentSection : [], |
| 335 | |
| 336 | //LightBox Object |
| 337 | lightBox : { |
| 338 | visibility : 'hidden', |
| 339 | type : null, |
| 340 | post : null, |
| 341 | activeImage : null, |
| 342 | albumIndex : 0, |
| 343 | videoSource : null |
| 344 | }, |
| 345 | highLightedSection : 'all', |
| 346 | |
| 347 | tooltip : { |
| 348 | text : '', |
| 349 | hover : false, |
| 350 | hoverType : 'outside' |
| 351 | }, |
| 352 | //Loading Bar |
| 353 | fullScreenLoader : false, |
| 354 | appLoaded : false, |
| 355 | previewLoaded : false, |
| 356 | loadingBar : true, |
| 357 | notificationElement : { |
| 358 | type : 'success', // success, error, warning, message |
| 359 | text : '', |
| 360 | shown : null |
| 361 | }, |
| 362 | |
| 363 | //Onboarding Wizard |
| 364 | onboardingWizardContent : cff_builder.onboardingWizardContent, |
| 365 | currentOnboardingWizardStep : 0, |
| 366 | onboardingWizardStepContent : {}, |
| 367 | currentOnboardingWizardActiveSettings : {}, |
| 368 | onboardingSuccessMessages : cff_builder.onboardingWizardContent.successMessages, |
| 369 | onboardingSuccessMessagesDisplay : [], |
| 370 | onboardingWizardDone : 'false', |
| 371 | isSetupPage : cff_builder.isSetupPage, |
| 372 | setupLicencekey : '', |
| 373 | setupLicencekeyError : null, |
| 374 | licenseLoading : false |
| 375 | }, |
| 376 | computed : { |
| 377 | feedStyleOutput : function(){ |
| 378 | return this.customizerStyleMaker(); |
| 379 | }, |
| 380 | singleHolderData : function(){ |
| 381 | return this.singleHolderParams(); |
| 382 | } |
| 383 | |
| 384 | }, |
| 385 | created: function(){ |
| 386 | var self = this; |
| 387 | if( self.customizerFeedData ){ |
| 388 | setTimeout(function(){ |
| 389 | self.generateMasonryGridHeight('update'); |
| 390 | self.generateCarouselSettings(); |
| 391 | }, 2000); |
| 392 | self.customizerFeedDataInitial = JSON.parse(JSON.stringify(self.customizerFeedData)) |
| 393 | if(self.customizerFeedData.feed_info.id == 'legacy'){ |
| 394 | self.customizerFeedData.settings.layout = 'full'; |
| 395 | } |
| 396 | self.customizerScreens.printedTemplate = self.feedTemplates[0]; |
| 397 | } |
| 398 | |
| 399 | if(self.customizerFeedData == undefined){ |
| 400 | if(self.sourcesList.length == 1){ |
| 401 | self.selectedSources.push(self.sourcesList[0].account_id); |
| 402 | } |
| 403 | self.feedPagination.pagesNumber = self.feedPagination.feedsCount != null ? Math.ceil(self.feedPagination.feedsCount / self.feedPagination.itemsPerPage) : 1 |
| 404 | } |
| 405 | |
| 406 | if(self.newManualSourcePopup != undefined && self.newManualSourcePopup == true){ |
| 407 | self.viewsActive.sourcePopupScreen = 'step_3'; |
| 408 | self.activateView('sourcePopup', 'creation'); |
| 409 | } |
| 410 | |
| 411 | if(self?.onboardingWizardContent !== undefined){ |
| 412 | self?.onboardingWizardContent.steps.forEach( step => { |
| 413 | self.onboardingWizardStepContent[step.id] = step; |
| 414 | } ); |
| 415 | self.checkActiveOnboardingWizardSettings() |
| 416 | } |
| 417 | |
| 418 | self.loadingBar = false; |
| 419 | /* Onboarding - move elements so the position is in context */ |
| 420 | self.positionOnboarding(); |
| 421 | setTimeout(function(){ |
| 422 | self.positionOnboarding(); |
| 423 | }, 500); |
| 424 | |
| 425 | if(self?.onboardingWizardContent !== undefined){ |
| 426 | self?.onboardingWizardContent.steps.forEach( step => { |
| 427 | self.onboardingWizardStepContent[step.id] = step; |
| 428 | } ); |
| 429 | self.checkActiveOnboardingWizardSettings() |
| 430 | } |
| 431 | |
| 432 | if( cffStorage?.isSetupPage !== 'true' && cffStorage?.isSetupPage !== true ){ |
| 433 | self.appLoaded = true; |
| 434 | } |
| 435 | |
| 436 | if(cffStorage?.setCurrentStep !== undefined){ |
| 437 | self.currentOnboardingWizardStep = 1; |
| 438 | self.recordUsageEvent( 'setup_wizard_started' ); |
| 439 | cffStorage.removeItem("setCurrentStep"); |
| 440 | } |
| 441 | |
| 442 | }, |
| 443 | methods: { |
| 444 | updateColorValue : function(id){ |
| 445 | var self = this; |
| 446 | self.customizerFeedData.settings[id] = (self.customizerFeedData.settings[id].a == 1) ? self.customizerFeedData.settings[id].hex : self.customizerFeedData.settings[id].hex8; |
| 447 | }, |
| 448 | /** |
| 449 | * Show & Hide View |
| 450 | * |
| 451 | * @since 4.0 |
| 452 | */ |
| 453 | activateView : function(viewName, sourcePopupType = 'creation', ajaxAction = false){ |
| 454 | var self = this; |
| 455 | if(viewName === 'feedtemplatesPopupCustomizer'){ |
| 456 | self.activateView('feedtemplatesPopup'); |
| 457 | self.activateView('extensionsPopupElement'); |
| 458 | }else{ |
| 459 | self.viewsActive[viewName] = (self.viewsActive[viewName] == false ) ? true : false; |
| 460 | if(viewName === 'sourcePopup'){ |
| 461 | self.viewsActive.sourcePopupType = sourcePopupType; |
| 462 | if(self.customizerFeedData != undefined && sourcePopupType != 'updateCustomizer'){ |
| 463 | Object.assign(self.customizerScreens.sourcesChoosed,self.customizerFeedData.settings.sources); |
| 464 | } |
| 465 | if(self.customizerFeedData != undefined && sourcePopupType == 'updateCustomizer'){ |
| 466 | self.viewsActive.sourcePopupType = 'customizer'; |
| 467 | //self.viewsActive.sourcePopup = true; |
| 468 | self.customizerFeedData.settings.sources = self.customizerScreens.sourcesChoosed; |
| 469 | } |
| 470 | |
| 471 | if( ajaxAction !== false ){ |
| 472 | self.customizerControlAjaxAction( ajaxAction ); |
| 473 | } |
| 474 | } |
| 475 | if(viewName === 'feedtypesPopup'){ |
| 476 | self.viewsActive.feedTypeElement = null; |
| 477 | if(self.viewsActive['feedtypesPopup'] == true){ |
| 478 | self.viewsActive.extensionsPopupElement = null; |
| 479 | } |
| 480 | } |
| 481 | if(viewName === 'extensionsPopupElement' && self.customizerFeedData !== undefined){ |
| 482 | //self.activateView('feedtypesPopup'); |
| 483 | } |
| 484 | if(viewName == 'editName'){ |
| 485 | document.getElementById("cff-csz-hd-input").focus(); |
| 486 | } |
| 487 | if(viewName == 'embedPopup' && ajaxAction == true){ |
| 488 | self.saveFeedSettings(); |
| 489 | } |
| 490 | if((viewName == 'sourcePopup' || viewName == 'sourcePopupType') && sourcePopupType == 'creationRedirect'){ |
| 491 | setTimeout(function(){ |
| 492 | self.$refs.addSourceRef.processFBConnect() |
| 493 | },3500); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | |
| 498 | self.$forceUpdate(); |
| 499 | self.movePopUp(); |
| 500 | }, |
| 501 | |
| 502 | /** |
| 503 | * Show/Hide View or Redirect to plugin dashboard page |
| 504 | * |
| 505 | * @since 4.0 |
| 506 | */ |
| 507 | activateViewOrRedirect: function(viewName, pluginName, plugin) { |
| 508 | var self = this; |
| 509 | |
| 510 | if ( plugin.installed && plugin.activated ) { |
| 511 | window.location = plugin.dashboard_permalink; |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | self.viewsActive[viewName] = (self.viewsActive[viewName] == false ) ? true : false; |
| 516 | |
| 517 | if(viewName == 'installPluginPopup'){ |
| 518 | self.viewsActive.installPluginModal = pluginName; |
| 519 | } |
| 520 | |
| 521 | self.movePopUp(); |
| 522 | cffBuilder.$forceUpdate(); |
| 523 | }, |
| 524 | |
| 525 | movePopUp : function(){ |
| 526 | var overlay = document.querySelectorAll("sb-fs-boss"); |
| 527 | if (overlay.length > 0) { |
| 528 | document.getElementById("wpbody-content").prepend(overlay[0]); |
| 529 | } |
| 530 | }, |
| 531 | |
| 532 | /** |
| 533 | * Check if View is Active |
| 534 | * |
| 535 | * @since 4.0 |
| 536 | * |
| 537 | * @return boolean |
| 538 | */ |
| 539 | checkActiveView : function(viewName){ |
| 540 | return this.viewsActive[viewName]; |
| 541 | }, |
| 542 | |
| 543 | /** |
| 544 | * Switch & Change Feed Screens |
| 545 | * |
| 546 | * @since 4.0 |
| 547 | */ |
| 548 | switchScreen: function(screenType, screenName){ |
| 549 | this.viewsActive[screenType] = screenName; |
| 550 | cffBuilder.$forceUpdate(); |
| 551 | }, |
| 552 | |
| 553 | /** |
| 554 | * Check if Value is Empty |
| 555 | * |
| 556 | * @since 4.0 |
| 557 | * |
| 558 | * @return boolean |
| 559 | */ |
| 560 | checkNotEmpty : function(value){ |
| 561 | return value != null && value.replace(/ /gi,'') != ''; |
| 562 | }, |
| 563 | |
| 564 | /** |
| 565 | * Check if Value exists in Array Object |
| 566 | * |
| 567 | * @since 4.0 |
| 568 | * |
| 569 | * @return boolean |
| 570 | */ |
| 571 | checkObjectArrayElement : function(objectArray, object, byWhat){ |
| 572 | var objectResult = objectArray.filter(function(elem){ |
| 573 | return elem[byWhat] == object[byWhat]; |
| 574 | }); |
| 575 | return (objectResult.length > 0) ? true : false; |
| 576 | }, |
| 577 | |
| 578 | /** |
| 579 | * Check if Data Setting is Enabled |
| 580 | * |
| 581 | * @since 4.0 |
| 582 | * |
| 583 | * @return boolean |
| 584 | */ |
| 585 | valueIsEnabled : function(value){ |
| 586 | return value == 1 || value == true || value == 'true' || value == 'on'; |
| 587 | }, |
| 588 | |
| 589 | |
| 590 | /** |
| 591 | * Parse JSON |
| 592 | * |
| 593 | * @since 4.0 |
| 594 | * |
| 595 | * @return jsonObject / Boolean |
| 596 | */ |
| 597 | jsonParse : function(jsonString){ |
| 598 | try { |
| 599 | return JSON.parse(jsonString); |
| 600 | } catch(e) { |
| 601 | return false; |
| 602 | } |
| 603 | }, |
| 604 | |
| 605 | |
| 606 | /** |
| 607 | * Ajax Post Action |
| 608 | * |
| 609 | * @since 4.0 |
| 610 | */ |
| 611 | ajaxPost : function(data, callback){ |
| 612 | var self = this; |
| 613 | data['nonce'] = data.nonce ? data.nonce : this.nonce; |
| 614 | self.$http.post(self.ajaxHandler,data).then(callback); |
| 615 | }, |
| 616 | |
| 617 | /** |
| 618 | * Check if Object has Nested Property |
| 619 | * |
| 620 | * @since 4.0 |
| 621 | * |
| 622 | * @return boolean |
| 623 | */ |
| 624 | hasOwnNestedProperty : function(obj,propertyPath) { |
| 625 | if (!propertyPath){return false;}var properties = propertyPath.split('.'); |
| 626 | for (var i = 0; i < properties.length; i++) { |
| 627 | var prop = properties[i]; |
| 628 | if (!obj || !obj.hasOwnProperty(prop)) { |
| 629 | return false; |
| 630 | } else { |
| 631 | obj = obj[prop]; |
| 632 | } |
| 633 | } |
| 634 | return true; |
| 635 | }, |
| 636 | |
| 637 | |
| 638 | /** |
| 639 | * Feed List Pagination |
| 640 | * |
| 641 | * @since 4.0 |
| 642 | */ |
| 643 | feedListPagination : function(type){ |
| 644 | var self = this, |
| 645 | currentPage = self.feedPagination.currentPage, |
| 646 | pagesNumber = self.feedPagination.pagesNumber; |
| 647 | self.loadingBar = true; |
| 648 | if((currentPage != 1 && type == 'prev') || (currentPage < pagesNumber && type == 'next')){ |
| 649 | self.feedPagination.currentPage = (type == 'next') ? |
| 650 | (currentPage < pagesNumber ? (parseInt(currentPage) + 1) : pagesNumber) : |
| 651 | (currentPage > 1 ? (parseInt(currentPage) - 1) : 1); |
| 652 | |
| 653 | |
| 654 | var postData = { |
| 655 | action : 'cff_feed_saver_manager_get_feed_list_page', |
| 656 | page : self.feedPagination.currentPage |
| 657 | }; |
| 658 | self.ajaxPost(postData, function(_ref){ |
| 659 | var data = _ref.data; |
| 660 | if(data){ |
| 661 | self.feedsList = data; |
| 662 | } |
| 663 | self.loadingBar = false; |
| 664 | }); |
| 665 | cffBuilder.$forceUpdate(); |
| 666 | } |
| 667 | }, |
| 668 | |
| 669 | /** |
| 670 | * Choose Feed Type |
| 671 | * |
| 672 | * @since 4.0 |
| 673 | */ |
| 674 | chooseFeedType : function(feedTypeGroup, feedElement, iscustomizerPopup = false){ |
| 675 | var self = this; |
| 676 | if(feedTypeGroup == 'advanced' && feedElement.extensionActive !== true){ |
| 677 | self.viewsActive.extensionsPopupElement = feedElement.type; |
| 678 | if(self.customizerFeedData !== undefined){ |
| 679 | self.activateView('feedtypesPopup'); |
| 680 | } |
| 681 | self.selectedFeed = 'timeline'; |
| 682 | } else { |
| 683 | self.selectedFeed = feedElement.type; |
| 684 | } |
| 685 | if(iscustomizerPopup){ |
| 686 | self.viewsActive.feedTypeElement = self.selectedFeed; |
| 687 | }else{ |
| 688 | self.setType( self.selectedFeed ); |
| 689 | } |
| 690 | |
| 691 | if (self.selectedFeed === null) { |
| 692 | self.selectedFeed = 'timeline'; |
| 693 | } |
| 694 | cffBuilder.$forceUpdate(); |
| 695 | }, |
| 696 | |
| 697 | /** |
| 698 | * Set Feed Type |
| 699 | * |
| 700 | * @since 4.0 |
| 701 | */ |
| 702 | setType : function(feedType){ |
| 703 | var typesArray = [], self = this; |
| 704 | switch (feedType) { |
| 705 | case 'photos': |
| 706 | typesArray = ['photos']; |
| 707 | break; |
| 708 | case 'videos': |
| 709 | typesArray = ['videos']; |
| 710 | break; |
| 711 | case 'events': |
| 712 | typesArray = ['events']; |
| 713 | break; |
| 714 | case 'albums': |
| 715 | typesArray = ['albums']; |
| 716 | break; |
| 717 | default: |
| 718 | typesArray = ['links','events','videos','photos','albums','statuses']; |
| 719 | break; |
| 720 | } |
| 721 | self.type = typesArray; |
| 722 | if(self.customizerFeedData !== undefined){ |
| 723 | self.customizerFeedData.settings.type = typesArray; |
| 724 | self.customizerFeedData.settings.feedtype = (typesArray.length == 1) ? typesArray[0] : 'timeline'; |
| 725 | self.processFeedTypesSources( typesArray ); |
| 726 | } |
| 727 | }, |
| 728 | |
| 729 | /** |
| 730 | * Feed Types Sources |
| 731 | * |
| 732 | * @since 4.0 |
| 733 | */ |
| 734 | processFeedTypesSources : function( typesArray ){ |
| 735 | var self = this; |
| 736 | if( self.customizerFeedData.settings.feedtype == 'timeline'){ |
| 737 | if( typesArray.includes('photos') ){ |
| 738 | self.customizerFeedData.settings.photosource = 'timeline'; |
| 739 | } |
| 740 | if( typesArray.includes('videos') ){ |
| 741 | self.customizerFeedData.settings.videosource = 'timeline'; |
| 742 | } |
| 743 | if( typesArray.includes('albums') ){ |
| 744 | self.customizerFeedData.settings.albumsource = 'timeline'; |
| 745 | } |
| 746 | if( typesArray.includes('events') ){ |
| 747 | self.customizerFeedData.settings.eventsource = 'timeline'; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | if( self.customizerFeedData.settings.feedtype == 'photos' ){ |
| 752 | self.customizerFeedData.settings.photosource = 'photospage'; |
| 753 | } |
| 754 | if( self.customizerFeedData.settings.feedtype == 'videos' ){ |
| 755 | self.customizerFeedData.settings.videosource = 'videospage'; |
| 756 | } |
| 757 | if( self.customizerFeedData.settings.feedtype == 'albums' ){ |
| 758 | self.customizerFeedData.settings.albumsource = 'photospage'; |
| 759 | } |
| 760 | if( self.customizerFeedData.settings.feedtype == 'events' ){ |
| 761 | self.customizerFeedData.settings.eventsource = 'eventspage'; |
| 762 | } |
| 763 | }, |
| 764 | |
| 765 | /* |
| 766 | Feed Creation Process |
| 767 | */ |
| 768 | creationProcessCheckAction : function(){ |
| 769 | var self = this, checkBtnNext = false; |
| 770 | switch (self.viewsActive.selectedFeedSection) { |
| 771 | case 'feedsType': |
| 772 | checkBtnNext = self.selectedFeed != null ? true : false; |
| 773 | window.cffSelectedFeed = self.selectedFeed; |
| 774 | break; |
| 775 | case 'selectSource': |
| 776 | checkBtnNext = self.selectedSources.length > 0 ? true : false; |
| 777 | break; |
| 778 | case 'feedsTypeGetProcess': |
| 779 | if(self.selectedFeed == 'singlealbum' && self.checkNotEmpty(self.singleAlbumFeedInfo.url)){ |
| 780 | checkBtnNext = true; |
| 781 | if(self.singleAlbumFeedInfo.url === self.feedCreationInfoUrl && self.singleAlbumFeedInfo.isError) |
| 782 | checkBtnNext = false; |
| 783 | else |
| 784 | self.singleAlbumFeedInfo.isError = false; |
| 785 | |
| 786 | } |
| 787 | if(self.selectedFeed == 'featuredpost' && self.checkNotEmpty(self.featuredPostFeedInfo.url)){ |
| 788 | checkBtnNext = true; |
| 789 | if(self.featuredPostFeedInfo.url === self.feedCreationInfoUrl && self.featuredPostFeedInfo.isError) |
| 790 | checkBtnNext = false; |
| 791 | else |
| 792 | self.featuredPostFeedInfo.isError = false; |
| 793 | } |
| 794 | |
| 795 | if(self.selectedFeed == 'videos' && ( self.videosTypeInfo.type == 'all' || ( self.videosTypeInfo.type == 'playlist' && self.checkNotEmpty(self.videosTypeInfo.playListUrl) ) ) ) { |
| 796 | checkBtnNext = true; |
| 797 | if(self.videosTypeInfo.playListUrl === self.feedCreationInfoUrl && self.videosTypeInfo.playListUrlError) |
| 798 | checkBtnNext = false; |
| 799 | else |
| 800 | self.videosTypeInfo.playListUrlError = false; |
| 801 | } |
| 802 | break; |
| 803 | } |
| 804 | return checkBtnNext; |
| 805 | }, |
| 806 | //Next Click in the Creation Process |
| 807 | creationProcessNext : function(){ |
| 808 | var self = this; |
| 809 | switch (self.viewsActive.selectedFeedSection) { |
| 810 | case 'feedsType': |
| 811 | if(self.selectedFeed !== null){ |
| 812 | if (self.selectedFeed === 'socialwall') { |
| 813 | window.location.href = cff_builder.pluginsInfo.social_wall.settingsPage; |
| 814 | return; |
| 815 | } |
| 816 | self.switchScreen('selectedFeedSection', 'selectSource'); |
| 817 | } |
| 818 | break; |
| 819 | case 'selectSource': |
| 820 | if(self.selectedSources.length == 0){ |
| 821 | self.processNotification("selectSourceError"); |
| 822 | } |
| 823 | if(self.selectedSources.length > 0){ |
| 824 | self.switchScreen('selectedFeedSection', 'feedsTypeGetProcess'); |
| 825 | if(!self.extraProcessFeedsTypes.includes(self.selectedFeed)) |
| 826 | self.isCreateProcessGood = true; |
| 827 | } |
| 828 | break; |
| 829 | case 'feedsTypeGetProcess': |
| 830 | //Getting Single Album Info |
| 831 | if(self.selectedFeed == 'singlealbum' && self.checkNotEmpty(self.singleAlbumFeedInfo.url)){ |
| 832 | self.feedCreationInfoUrl = self.singleAlbumFeedInfo.url; |
| 833 | self.getSingleAlbumCreationProcessInfo(); |
| 834 | } |
| 835 | //Getting Featured Post info |
| 836 | if(self.selectedFeed == 'featuredpost' && self.checkNotEmpty(self.featuredPostFeedInfo.url)){ |
| 837 | self.feedCreationInfoUrl = self.featuredPostFeedInfo.url; |
| 838 | self.getFeaturedPostCreationProcessInfo(); |
| 839 | } |
| 840 | //Getting PlayList Info |
| 841 | if(self.selectedFeed == 'videos' && ( self.videosTypeInfo.type == 'all' || ( self.videosTypeInfo.type == 'playlist' && self.checkNotEmpty(self.videosTypeInfo.playListUrl) ) ) ){ |
| 842 | self.feedCreationInfoUrl = self.videosTypeInfo.playListUrl; |
| 843 | if(self.videosTypeInfo.type == 'all'){ |
| 844 | self.submitNewFeed(); |
| 845 | }else{ |
| 846 | self.getVideosPlaylistCreationProcessInfo(); |
| 847 | } |
| 848 | } |
| 849 | break; |
| 850 | } |
| 851 | if(self.isCreateProcessGood) |
| 852 | self.submitNewFeed(); |
| 853 | |
| 854 | cffBuilder.$forceUpdate(); |
| 855 | }, |
| 856 | changeVideoSource : function( videoSource ){ |
| 857 | this.videosTypeInfo.type = videoSource; |
| 858 | cffBuilder.$forceUpdate(); |
| 859 | }, |
| 860 | |
| 861 | //Next Click in the Onboarding Process |
| 862 | onboardingNext : function(){ |
| 863 | this.viewsActive.onboardingStep ++; |
| 864 | this.onboardingHideShow(); |
| 865 | cffBuilder.$forceUpdate(); |
| 866 | }, |
| 867 | //Previous Click in the Onboarding Process |
| 868 | onboardingPrev : function(){ |
| 869 | this.viewsActive.onboardingStep --; |
| 870 | this.onboardingHideShow(); |
| 871 | cffBuilder.$forceUpdate(); |
| 872 | }, |
| 873 | onboardingHideShow : function() { |
| 874 | var tooltips = document.querySelectorAll(".sb-onboarding-tooltip"); |
| 875 | for (var i = 0; i < tooltips.length; i++){ |
| 876 | tooltips[i].style.display = "none"; |
| 877 | } |
| 878 | document.querySelectorAll(".sb-onboarding-tooltip-"+this.viewsActive.onboardingStep)[0].style.display = "block"; |
| 879 | |
| 880 | if (this.viewsActive.onboardingCustomizerPopup) { |
| 881 | if (this.viewsActive.onboardingStep === 2) { |
| 882 | this.switchCustomizerTab('customize'); |
| 883 | } else if (this.viewsActive.onboardingStep === 3) { |
| 884 | this.switchCustomizerTab('settings'); |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | }, |
| 889 | //Close Click in the Onboarding Process |
| 890 | onboardingClose : function(){ |
| 891 | var self = this, |
| 892 | wasActive = self.viewsActive.onboardingPopup ? 'newuser' : 'customizer'; |
| 893 | |
| 894 | document.getElementById("cff-builder-app").classList.remove('sb-onboarding-active'); |
| 895 | |
| 896 | self.viewsActive.onboardingPopup = false; |
| 897 | self.viewsActive.onboardingCustomizerPopup = false; |
| 898 | |
| 899 | this.switchCustomizerTab('customize'); |
| 900 | self.viewsActive.onboardingStep = 0; |
| 901 | var postData = { |
| 902 | action : 'cff_dismiss_onboarding', |
| 903 | was_active : wasActive, |
| 904 | }; |
| 905 | self.ajaxPost(postData, function(_ref){ |
| 906 | var data = _ref.data; |
| 907 | }); |
| 908 | cffBuilder.$forceUpdate(); |
| 909 | }, |
| 910 | positionOnboarding : function(){ |
| 911 | var self = this, |
| 912 | onboardingElem = document.querySelectorAll(".sb-onboarding-overlay")[0], |
| 913 | wrapElem = document.getElementById("cff-builder-app"); |
| 914 | |
| 915 | if (onboardingElem === null || typeof onboardingElem === 'undefined') { |
| 916 | return; |
| 917 | } |
| 918 | |
| 919 | if (self.viewsActive.onboardingCustomizerPopup && self.iscustomizerScreen) { |
| 920 | if (document.getElementById("sb-onboarding-tooltip-customizer-1") !== null) { |
| 921 | wrapElem.classList.add('sb-onboarding-active'); |
| 922 | |
| 923 | var step1El = document.querySelectorAll(".cff-csz-header")[0]; |
| 924 | step1El.appendChild(document.getElementById("sb-onboarding-tooltip-customizer-1")); |
| 925 | |
| 926 | var step2El = document.querySelectorAll(".sb-customizer-sidebar-sec1")[0]; |
| 927 | step2El.appendChild(document.getElementById("sb-onboarding-tooltip-customizer-2")); |
| 928 | |
| 929 | var step3El = document.querySelectorAll(".sb-customizer-sidebar-sec1")[0]; |
| 930 | step3El.appendChild(document.getElementById("sb-onboarding-tooltip-customizer-3")); |
| 931 | |
| 932 | self.onboardingHideShow(); |
| 933 | } |
| 934 | } else if (self.viewsActive.onboardingPopup && !self.iscustomizerScreen) { |
| 935 | if (cff_builder.allFeedsScreen.onboarding.type === 'single') { |
| 936 | if (document.getElementById("sb-onboarding-tooltip-single-1") !== null) { |
| 937 | wrapElem.classList.add('sb-onboarding-active'); |
| 938 | |
| 939 | var step1El = document.querySelectorAll(".cff-fb-wlcm-header .sb-positioning-wrap")[0]; |
| 940 | step1El.appendChild(document.getElementById("sb-onboarding-tooltip-single-1")); |
| 941 | |
| 942 | var step2El = document.querySelectorAll(".cff-table-wrap")[0]; |
| 943 | if(step2El != undefined){ |
| 944 | step2El.appendChild(document.getElementById("sb-onboarding-tooltip-single-2")); |
| 945 | } |
| 946 | self.onboardingHideShow(); |
| 947 | } |
| 948 | } else { |
| 949 | if (document.getElementById("sb-onboarding-tooltip-multiple-1") !== null) { |
| 950 | wrapElem.classList.add('sb-onboarding-active'); |
| 951 | |
| 952 | var step1El = document.querySelectorAll(".cff-fb-wlcm-header .sb-positioning-wrap")[0]; |
| 953 | step1El.appendChild(document.getElementById("sb-onboarding-tooltip-multiple-1")); |
| 954 | |
| 955 | var step2El = document.querySelectorAll(".cff-fb-lgc-ctn")[0]; |
| 956 | step2El.appendChild(document.getElementById("sb-onboarding-tooltip-multiple-2")); |
| 957 | |
| 958 | var step3El = document.querySelectorAll(".cff-legacy-table-wrap")[0]; |
| 959 | step3El.appendChild(document.getElementById("sb-onboarding-tooltip-multiple-3")); |
| 960 | |
| 961 | self.activateView('legacyFeedsShown'); |
| 962 | self.onboardingHideShow(); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | } |
| 967 | }, |
| 968 | //Back Click in the Creation Process |
| 969 | creationProcessBack : function(){ |
| 970 | var self = this; |
| 971 | switch (self.viewsActive.selectedFeedSection) { |
| 972 | case 'feedsType': |
| 973 | self.switchScreen('pageScreen', 'welcome'); |
| 974 | break; |
| 975 | case 'selectSource': |
| 976 | self.switchScreen('selectedFeedSection', 'feedsType'); |
| 977 | break; |
| 978 | case 'feedsTypeGetProcess': |
| 979 | self.switchScreen('selectedFeedSection', 'selectSource'); |
| 980 | break; |
| 981 | } |
| 982 | cffBuilder.$forceUpdate(); |
| 983 | }, |
| 984 | checkCreationFeedTypeChosen : function(feedTypeChosen){ |
| 985 | var self = this, isShown = false; |
| 986 | switch (feedTypeChosen) { |
| 987 | case "singlealbum": |
| 988 | isShown = self.activeExtensions.album && (self.viewsActive.selectedFeedSection == 'feedsTypeGetProcess' && self.selectedFeed == 'singlealbum'); |
| 989 | break; |
| 990 | case "featuredpost": |
| 991 | isShown = self.activeExtensions.featured_post && (self.viewsActive.selectedFeedSection == 'feedsTypeGetProcess' && self.selectedFeed == 'featuredpost'); |
| 992 | break; |
| 993 | case "videos": |
| 994 | isShown = (self.viewsActive.selectedFeedSection == 'feedsTypeGetProcess' && self.selectedFeed == 'videos'); |
| 995 | break; |
| 996 | } |
| 997 | return isShown; |
| 998 | }, |
| 999 | //Get Single Album info in the creation Process |
| 1000 | getSingleAlbumCreationProcessInfo : function(){ |
| 1001 | var self = this; |
| 1002 | var singleAlbumData = { |
| 1003 | action : 'cff_source_get_featured_post_preview', |
| 1004 | url_or_id : self.singleAlbumFeedInfo.url, |
| 1005 | source_id : self.selectedSources[0] |
| 1006 | }; |
| 1007 | self.ajaxPost(singleAlbumData, function(_ref){ |
| 1008 | var data = _ref.data; |
| 1009 | if(self.hasOwnNestedProperty(data,'error')){ |
| 1010 | self.singleAlbumFeedInfo.isError = true, self.singleAlbumFeedInfo.success = false, self.singleAlbumFeedInfo.info = {}; |
| 1011 | }else { |
| 1012 | self.singleAlbumFeedInfo.isError = false,self.singleAlbumFeedInfo.success = true; |
| 1013 | var albumID = data.id.split("_"); |
| 1014 | albumID = albumID[1] != undefined ? albumID[1] : data.id; |
| 1015 | |
| 1016 | self.singleAlbumFeedInfo.info = { |
| 1017 | title : data.attachments.data[0].title ? data.attachments.data[0].title : '', |
| 1018 | description : data.story ? data.story : '', |
| 1019 | thumbnail : self.hasOwnNestedProperty(data,'full_picture') ? data.full_picture : '', |
| 1020 | album : albumID |
| 1021 | }; |
| 1022 | self.isCreateProcessGood = true; |
| 1023 | } |
| 1024 | }); |
| 1025 | }, |
| 1026 | |
| 1027 | //Get Videos Play List Info |
| 1028 | getVideosPlaylistCreationProcessInfo : function(){ |
| 1029 | var self = this, |
| 1030 | videosPlaylistData = { |
| 1031 | action : 'cff_source_get_playlist_post_preview', |
| 1032 | url_or_id : self.videosTypeInfo.playListUrl, |
| 1033 | source_id : self.selectedSources[0] |
| 1034 | }; |
| 1035 | self.ajaxPost(videosPlaylistData, function(_ref){ |
| 1036 | var data = _ref.data; |
| 1037 | if(self.hasOwnNestedProperty(data,'error')){ |
| 1038 | self.videosTypeInfo.playListUrlError = true, self.videosTypeInfo.success = false; |
| 1039 | }else { |
| 1040 | self.videosTypeInfo.info = { |
| 1041 | playlistID : data.playlistID |
| 1042 | } |
| 1043 | self.videosTypeInfo.playListUrlError = false, self.videosTypeInfo.success = true; |
| 1044 | self.isCreateProcessGood = true; |
| 1045 | self.submitNewFeed(); |
| 1046 | } |
| 1047 | }); |
| 1048 | |
| 1049 | }, |
| 1050 | |
| 1051 | //Get Featured Post info in the creation Process |
| 1052 | getFeaturedPostCreationProcessInfo : function(){ |
| 1053 | var self = this; |
| 1054 | var featuredPostData = { |
| 1055 | action : 'cff_source_get_featured_post_preview', |
| 1056 | url_or_id : self.featuredPostFeedInfo.url, |
| 1057 | source_id : self.selectedSources[0] |
| 1058 | }; |
| 1059 | self.ajaxPost(featuredPostData, function(_ref){ |
| 1060 | var data = _ref.data; |
| 1061 | if(self.hasOwnNestedProperty(data,'error')){ |
| 1062 | self.featuredPostFeedInfo.isError = true, self.featuredPostFeedInfo.success = false, self.featuredPostFeedInfo.info = {}; |
| 1063 | }else { |
| 1064 | self.featuredPostFeedInfo.isError = false,self.featuredPostFeedInfo.success = true; |
| 1065 | self.featuredPostFeedInfo.info = { |
| 1066 | description : data.message ? data.message.substr(0, 60) + '...' : '', |
| 1067 | thumbnail : self.hasOwnNestedProperty(data,'full_picture') ? data.full_picture : '', |
| 1068 | featuredpost : data.id |
| 1069 | }; |
| 1070 | self.isCreateProcessGood = true; |
| 1071 | } |
| 1072 | }); |
| 1073 | }, |
| 1074 | getSelectedSourceName : function(sourceID){ |
| 1075 | var self = this; |
| 1076 | var sourceInfo = self.sourcesList.filter(function(source){ |
| 1077 | return source.account_id == sourceID; |
| 1078 | }); |
| 1079 | return (sourceInfo.length > 0) ? sourceInfo[0].username : ''; |
| 1080 | }, |
| 1081 | //Create & Submit New Feed |
| 1082 | submitNewFeed : function(){ |
| 1083 | var self = this, |
| 1084 | newFeedData = { |
| 1085 | action : 'cff_feed_saver_manager_builder_update', |
| 1086 | sources : self.selectedSources, |
| 1087 | new_insert : 'true', |
| 1088 | sourcename : self.getSelectedSourceName(self.selectedSources[0]), |
| 1089 | feedtype : self.selectedFeed, |
| 1090 | type : self.type |
| 1091 | }; |
| 1092 | if(self.selectedFeed == 'featuredpost'){ |
| 1093 | newFeedData.featuredpost = self.featuredPostFeedInfo.info.featuredpost; |
| 1094 | } |
| 1095 | if(self.selectedFeed == 'singlealbum'){ |
| 1096 | newFeedData.album = self.singleAlbumFeedInfo.info.album; |
| 1097 | } |
| 1098 | if(self.selectedFeed == 'videos'){ |
| 1099 | newFeedData.playlist = (self.videosTypeInfo.info.playlistID != undefined && self.videosTypeInfo.type == 'playlist') ? self.videosTypeInfo.info.playlistID : ''; |
| 1100 | } |
| 1101 | self.fullScreenLoader = true; |
| 1102 | self.ajaxPost(newFeedData, function(_ref){ |
| 1103 | var data = _ref.data; |
| 1104 | if(data.feed_id && data.success){ |
| 1105 | window.location = self.builderUrl + '&feed_id=' + data.feed_id; |
| 1106 | } |
| 1107 | }); |
| 1108 | }, |
| 1109 | |
| 1110 | //Select & Choose the Feed Source |
| 1111 | checkSourceForEvents : function(source){ |
| 1112 | return this.selectedFeed == 'events' && source.account_type == 'page' && source.privilege != 'events'; |
| 1113 | }, |
| 1114 | checkTypeForGroup : function(source){ |
| 1115 | return source.account_type === 'group' && this.selectedFeed === 'photos'; |
| 1116 | }, |
| 1117 | selectSource : function(source){ |
| 1118 | var self = this; |
| 1119 | isMultifeed = (self.activeExtensions['multifeed'] !== undefined && self.activeExtensions['multifeed'] == true); |
| 1120 | if(!self.checkSourceForEvents(source) && !self.checkTypeForGroup(source)){ |
| 1121 | if(isMultifeed){ |
| 1122 | if(self.selectedSources.includes(source.account_id)){ |
| 1123 | self.selectedSources.splice(self.selectedSources.indexOf(source.account_id), 1); |
| 1124 | }else{ |
| 1125 | self.selectedSources.push(source.account_id); |
| 1126 | } |
| 1127 | }else{ |
| 1128 | self.selectedSources = (self.selectedSources.includes(source.account_id)) ? [] : [source.account_id]; |
| 1129 | } |
| 1130 | } |
| 1131 | }, |
| 1132 | processDomList : function(selector, attributes){ |
| 1133 | document.querySelectorAll(selector).forEach( function(element) { |
| 1134 | attributes.map( function(attrName) { |
| 1135 | element.setAttribute(attrName[0], attrName[1]); |
| 1136 | }); |
| 1137 | }); |
| 1138 | }, |
| 1139 | openTooltipBig : function(){ |
| 1140 | var self = this, elem = window.event.currentTarget; |
| 1141 | self.processDomList('.cff-fb-onbrd-tltp-elem', [['data-active', 'false']]); |
| 1142 | elem.querySelector('.cff-fb-onbrd-tltp-elem').setAttribute('data-active', 'true'); |
| 1143 | cffBuilder.$forceUpdate(); |
| 1144 | }, |
| 1145 | closeTooltipBig : function(){ |
| 1146 | var self = this; |
| 1147 | self.processDomList('.cff-fb-onbrd-tltp-elem', [['data-active', 'false']]); |
| 1148 | window.event.stopPropagation(); |
| 1149 | cffBuilder.$forceUpdate(); |
| 1150 | }, |
| 1151 | |
| 1152 | /* |
| 1153 | FEEDS List Actions |
| 1154 | */ |
| 1155 | |
| 1156 | /** |
| 1157 | * Switch Bulk Action |
| 1158 | * |
| 1159 | * @since 4.0 |
| 1160 | */ |
| 1161 | bulkActionClick : function(){ |
| 1162 | var self = this; |
| 1163 | switch (self.selectedBulkAction) { |
| 1164 | case 'delete': |
| 1165 | if(self.feedsSelected.length > 0){ |
| 1166 | self.openDialogBox('deleteMultipleFeeds') |
| 1167 | } |
| 1168 | break; |
| 1169 | } |
| 1170 | cffBuilder.$forceUpdate(); |
| 1171 | }, |
| 1172 | |
| 1173 | /** |
| 1174 | * Duplicate Feed |
| 1175 | * |
| 1176 | * @since 4.0 |
| 1177 | */ |
| 1178 | feedActionDuplicate : function(feed){ |
| 1179 | var self = this, |
| 1180 | feedsDuplicateData = { |
| 1181 | action : 'cff_feed_saver_manager_duplicate_feed', |
| 1182 | feed_id : feed.id |
| 1183 | }; |
| 1184 | self.ajaxPost(feedsDuplicateData, function(_ref){ |
| 1185 | var data = _ref.data; |
| 1186 | self.feedsList = Object.values(Object.assign({}, data)); |
| 1187 | //self.feedsList = data; |
| 1188 | }); |
| 1189 | cffBuilder.$forceUpdate(); |
| 1190 | }, |
| 1191 | |
| 1192 | /** |
| 1193 | * Delete Feed |
| 1194 | * |
| 1195 | * @since 4.0 |
| 1196 | */ |
| 1197 | feedActionDelete : function(feeds_ids){ |
| 1198 | var self = this, |
| 1199 | feedsDeleteData = { |
| 1200 | action : 'cff_feed_saver_manager_delete_feeds', |
| 1201 | feeds_ids : feeds_ids |
| 1202 | }; |
| 1203 | self.ajaxPost(feedsDeleteData, function(_ref){ |
| 1204 | var data = _ref.data; |
| 1205 | self.feedsList = Object.values(Object.assign({}, data)); |
| 1206 | self.feedsSelected = []; |
| 1207 | }); |
| 1208 | }, |
| 1209 | |
| 1210 | /** |
| 1211 | * View Feed Instances |
| 1212 | * |
| 1213 | * @since 4.0 |
| 1214 | */ |
| 1215 | viewFeedInstances : function(feed){ |
| 1216 | var self = this; |
| 1217 | self.viewsActive.instanceFeedActive = feed; |
| 1218 | self.movePopUp(); |
| 1219 | cffBuilder.$forceUpdate(); |
| 1220 | }, |
| 1221 | |
| 1222 | /** |
| 1223 | * Select All Feeds in List |
| 1224 | * |
| 1225 | * @since 4.0 |
| 1226 | */ |
| 1227 | selectAllFeedCheckBox : function(){ |
| 1228 | var self = this; |
| 1229 | if( !self.checkAllFeedsActive() ){ |
| 1230 | self.feedsSelected = []; |
| 1231 | self.feedsList.forEach( function(feed) { |
| 1232 | self.feedsSelected.push(feed.id); |
| 1233 | }); |
| 1234 | }else{ |
| 1235 | self.feedsSelected = []; |
| 1236 | } |
| 1237 | |
| 1238 | }, |
| 1239 | |
| 1240 | /** |
| 1241 | * Select Single Feed in List |
| 1242 | * |
| 1243 | * @since 4.0 |
| 1244 | */ |
| 1245 | selectFeedCheckBox : function(feedID){ |
| 1246 | if(this.feedsSelected.includes(feedID)){ |
| 1247 | this.feedsSelected.splice(this.feedsSelected.indexOf(feedID),1); |
| 1248 | }else{ |
| 1249 | this.feedsSelected.push(feedID); |
| 1250 | } |
| 1251 | cffBuilder.$forceUpdate(); |
| 1252 | }, |
| 1253 | |
| 1254 | /** |
| 1255 | * Check if All Feeds are Selected |
| 1256 | * |
| 1257 | * @since 4.0 |
| 1258 | */ |
| 1259 | checkAllFeedsActive : function(){ |
| 1260 | var self = this, |
| 1261 | result = true; |
| 1262 | self.feedsList.forEach( function(feed) { |
| 1263 | if(!self.feedsSelected.includes(feed.id)){ |
| 1264 | result = false; |
| 1265 | } |
| 1266 | }); |
| 1267 | |
| 1268 | return result; |
| 1269 | }, |
| 1270 | |
| 1271 | |
| 1272 | /** |
| 1273 | * Copy text to clipboard |
| 1274 | * |
| 1275 | * @since 4.0 |
| 1276 | */ |
| 1277 | copyToClipBoard : function(value){ |
| 1278 | var self = this; |
| 1279 | const el = document.createElement('textarea'); |
| 1280 | el.className = 'cff-fb-cp-clpboard'; |
| 1281 | el.value = value; |
| 1282 | document.body.appendChild(el); |
| 1283 | el.select(); |
| 1284 | document.execCommand('copy'); |
| 1285 | document.body.removeChild(el); |
| 1286 | self.notificationElement = { |
| 1287 | type : 'success', |
| 1288 | text : this.genericText.copiedClipboard, |
| 1289 | shown : "shown" |
| 1290 | }; |
| 1291 | setTimeout(function(){ |
| 1292 | self.notificationElement.shown = "hidden"; |
| 1293 | }, 3000); |
| 1294 | cffBuilder.$forceUpdate(); |
| 1295 | }, |
| 1296 | |
| 1297 | |
| 1298 | /** |
| 1299 | * Check Post Show |
| 1300 | * |
| 1301 | * @since 4.0 |
| 1302 | */ |
| 1303 | shouldShowPostList : function(layout, singlePost){ |
| 1304 | var self = this; |
| 1305 | return self.customizerFeedData.settings.layout == layout && |
| 1306 | ( |
| 1307 | ( |
| 1308 | self.customizerFeedData.settings.feedtype == 'reviews' && |
| 1309 | ((self.valueIsEnabled(self.customizerFeedData.settings.hidenegative) && singlePost.recommendation_type == 'positive') || !self.valueIsEnabled(self.customizerFeedData.settings.hidenegative) ) |
| 1310 | ) |
| 1311 | || self.customizerFeedData.settings.feedtype != 'reviews' |
| 1312 | ) |
| 1313 | }, |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | /*------------------------------------------- |
| 1318 | CUSTOMIZER FUNCTIONS |
| 1319 | -------------------------------------------*/ |
| 1320 | /** |
| 1321 | * HighLight Section |
| 1322 | * |
| 1323 | * @since 4.0 |
| 1324 | */ |
| 1325 | isSectionHighLighted : function(sectionName){ |
| 1326 | var self = this; |
| 1327 | return (self.highLightedSection === sectionName || self.highLightedSection === 'all') |
| 1328 | }, |
| 1329 | |
| 1330 | /** |
| 1331 | * Enable HightLight Section |
| 1332 | * |
| 1333 | * @since 4.0 |
| 1334 | */ |
| 1335 | enableHighLightSection : function(sectionId){ |
| 1336 | var self = this, |
| 1337 | listPostSection = ['customize_feedlayout', 'customize_colorscheme', 'customize_posts','post_style','individual_elements'], |
| 1338 | headerSection = ['customize_header'], |
| 1339 | likeBoxSection = ['customize_likebox'], |
| 1340 | loadeMoreSection = ['customize_loadmorebutton'], |
| 1341 | lightBoxSection = ['customize_lightbox'], |
| 1342 | domBody = document.getElementsByTagName("body")[0]; |
| 1343 | |
| 1344 | self.dummyLightBoxData.visibility = 'hidden'; |
| 1345 | domBody.classList.remove("no-overflow"); |
| 1346 | |
| 1347 | if( listPostSection.includes(sectionId) ){ |
| 1348 | self.highLightedSection = 'postList'; |
| 1349 | self.scrollToHighLightedSection("cff-post-list-section"); |
| 1350 | }else if( headerSection.includes(sectionId) ){ |
| 1351 | self.highLightedSection = 'header'; |
| 1352 | self.scrollToHighLightedSection("cff-header-section"); |
| 1353 | }else if( likeBoxSection.includes(sectionId) ){ |
| 1354 | self.highLightedSection = 'likeBox'; |
| 1355 | self.scrollToHighLightedSection("cff-like-box-section"); |
| 1356 | }else if( loadeMoreSection.includes(sectionId) ){ |
| 1357 | self.highLightedSection = 'loadMore'; |
| 1358 | self.scrollToHighLightedSection("cff-load-more-section"); |
| 1359 | }else if( lightBoxSection.includes(sectionId) ){ |
| 1360 | self.highLightedSection = 'lightBox'; |
| 1361 | self.dummyLightBoxData.visibility = 'shown'; |
| 1362 | document.body.scrollTop = 0; |
| 1363 | document.documentElement.scrollTop = 0; |
| 1364 | domBody.classList.add("no-overflow"); |
| 1365 | }else{ |
| 1366 | self.highLightedSection = 'all'; |
| 1367 | self.dummyLightBoxData.visibility = 'hidden'; |
| 1368 | domBody.classList.remove("no-overflow"); |
| 1369 | } |
| 1370 | }, |
| 1371 | |
| 1372 | |
| 1373 | /** |
| 1374 | * Scroll to Highlighted Section |
| 1375 | * |
| 1376 | * @since 4.0 |
| 1377 | */ |
| 1378 | scrollToHighLightedSection : function(sectionId){ |
| 1379 | const element = document.getElementById(sectionId); |
| 1380 | if(element != undefined && element != null){ |
| 1381 | const y = element.getBoundingClientRect().top - 100 + window.pageYOffset - 10; |
| 1382 | window.scrollTo({top: y, behavior: 'smooth'}); |
| 1383 | } |
| 1384 | }, |
| 1385 | |
| 1386 | /** |
| 1387 | * Enable & Show Color Picker |
| 1388 | * |
| 1389 | * @since 4.0 |
| 1390 | */ |
| 1391 | showColorPickerPospup : function(controlId){ |
| 1392 | this.customizerScreens.activeColorPicker = controlId; |
| 1393 | }, |
| 1394 | |
| 1395 | /** |
| 1396 | * Hide Color Picker |
| 1397 | * |
| 1398 | * @since 4.0 |
| 1399 | */ |
| 1400 | hideColorPickerPospup : function(){ |
| 1401 | this.customizerScreens.activeColorPicker = null; |
| 1402 | }, |
| 1403 | |
| 1404 | switchCustomizerPreviewDevice : function(previewScreen){ |
| 1405 | var self = this; |
| 1406 | self.customizerScreens.previewScreen = previewScreen; |
| 1407 | self.loadingBar = true; |
| 1408 | self.reinitCarouselHTML(); |
| 1409 | setTimeout(function(){ |
| 1410 | self.generateMasonryGridHeight('update'); |
| 1411 | self.loadingBar = false; |
| 1412 | },200) |
| 1413 | cffBuilder.$forceUpdate(); |
| 1414 | }, |
| 1415 | switchCustomizerTab : function(tabId){ |
| 1416 | var self = this, |
| 1417 | domBody = document.getElementsByTagName("body")[0]; |
| 1418 | self.customizerScreens.activeTab = tabId; |
| 1419 | self.customizerScreens.activeSection = null; |
| 1420 | self.customizerScreens.activeSectionData = null; |
| 1421 | self.highLightedSection = 'all'; |
| 1422 | |
| 1423 | self.dummyLightBoxData.visibility = 'hidden'; |
| 1424 | domBody.classList.remove("no-overflow"); |
| 1425 | cffBuilder.$forceUpdate(); |
| 1426 | }, |
| 1427 | switchCustomizerSection : function(sectionId, section, isNested = false, isBackElements){ |
| 1428 | var self = this; |
| 1429 | self.customizerScreens.parentActiveSection = null; |
| 1430 | self.customizerScreens.parentActiveSectionData = null; |
| 1431 | if(isNested){ |
| 1432 | self.customizerScreens.parentActiveSection = self.customizerScreens.activeSection; |
| 1433 | self.customizerScreens.parentActiveSectionData = self.customizerScreens.activeSectionData; |
| 1434 | } |
| 1435 | self.customizerScreens.activeSection = sectionId; |
| 1436 | self.customizerScreens.activeSectionData = section; |
| 1437 | self.enableHighLightSection(sectionId); |
| 1438 | cffBuilder.$forceUpdate(); |
| 1439 | }, |
| 1440 | switchNestedSection : function(sectionId, section){ |
| 1441 | var self = this; |
| 1442 | if(section !== null){ |
| 1443 | self.customizerScreens.activeSection = sectionId; |
| 1444 | self.customizerScreens.activeSectionData = section; |
| 1445 | }else{ |
| 1446 | var sectionArray = sectionId['sections']; |
| 1447 | var elementSectionData = self.customizerSidebarBuilder; |
| 1448 | |
| 1449 | sectionArray.map(function(elm, index){ |
| 1450 | elementSectionData = (elementSectionData[elm] != undefined && elementSectionData[elm] != null) ? elementSectionData[elm] : null; |
| 1451 | }); |
| 1452 | if(elementSectionData != null){ |
| 1453 | self.customizerScreens.activeSection = sectionId['id']; |
| 1454 | self.customizerScreens.activeSectionData = elementSectionData; |
| 1455 | } |
| 1456 | } |
| 1457 | cffBuilder.$forceUpdate(); |
| 1458 | }, |
| 1459 | backToPostElements : function(){ |
| 1460 | var self = this, |
| 1461 | individual_elements = self.customizerSidebarBuilder['customize'].sections.customize_posts.nested_sections.individual_elements; |
| 1462 | self.customizerScreens.activeSection = 'customize_posts'; |
| 1463 | self.customizerScreens.activeSectionData= self.customizerSidebarBuilder['customize'].sections.customize_posts; |
| 1464 | self.switchCustomizerSection('individual_elements', individual_elements, true, true); |
| 1465 | cffBuilder.$forceUpdate(); |
| 1466 | }, |
| 1467 | |
| 1468 | processDateRange : function(){ |
| 1469 | var self = this, |
| 1470 | settings = self.customizerFeedData.settings; |
| 1471 | if(settings['daterangefromtype'] == 'relative'){ |
| 1472 | self.customizerFeedData.settings['from'] = settings['daterangefromrelative']; |
| 1473 | }else{ |
| 1474 | self.customizerFeedData.settings['from'] = settings['daterangefromspecific']; |
| 1475 | } |
| 1476 | |
| 1477 | if(settings['daterangeuntiltype'] == 'relative'){ |
| 1478 | self.customizerFeedData.settings['until'] = settings['daterangeuntilrelative']; |
| 1479 | }else{ |
| 1480 | self.customizerFeedData.settings['until'] = settings['daterangeuntilspecific']; |
| 1481 | } |
| 1482 | |
| 1483 | self.customizerControlAjaxAction('feedFlyPreview'); |
| 1484 | }, |
| 1485 | |
| 1486 | changeSettingValue : function(settingID, value, doProcess = true, ajaxAction = false) { |
| 1487 | var self = this, |
| 1488 | dateRangeElements = [ |
| 1489 | 'daterangefromtype', |
| 1490 | 'daterangefromspecific', |
| 1491 | 'daterangefromrelative', |
| 1492 | 'daterangeuntiltype', |
| 1493 | 'daterangeuntilspecific', |
| 1494 | 'daterangeuntilrelative' |
| 1495 | ]; |
| 1496 | if( dateRangeElements.includes(settingID) ){ |
| 1497 | self.processDateRange(); |
| 1498 | } |
| 1499 | |
| 1500 | if(settingID == 'feedlayout' && value == 'carousel' && !self.checkExtensionActive('carousel')){ |
| 1501 | self.viewsActive.extensionsPopupElement = 'carousel'; |
| 1502 | }else{ |
| 1503 | if(doProcess){ |
| 1504 | self.customizerFeedData.settings[settingID] = value; |
| 1505 | } |
| 1506 | if(settingID === 'showpoststypes' && value === 'all'){ |
| 1507 | ajaxAction = 'feedFlyPreview'; |
| 1508 | self.customizerFeedData.settings.type = [ |
| 1509 | 'links', |
| 1510 | 'events', |
| 1511 | 'videos', |
| 1512 | 'photos', |
| 1513 | 'albums', |
| 1514 | 'statuses' |
| 1515 | ]; |
| 1516 | } |
| 1517 | if(ajaxAction !== false){ |
| 1518 | self.customizerControlAjaxAction(ajaxAction); |
| 1519 | } |
| 1520 | var whenToGenerateFeed = [ |
| 1521 | 'layout', |
| 1522 | 'feedlayout', |
| 1523 | 'cols', |
| 1524 | 'colstablet', |
| 1525 | 'colsmobile', |
| 1526 | 'nummobile' |
| 1527 | ]; |
| 1528 | if( whenToGenerateFeed.includes( settingID ) ){ |
| 1529 | self.loadingBar = true; |
| 1530 | self.generateMasonryGridHeight('update'); |
| 1531 | self.reinitCarouselHTML(); |
| 1532 | setTimeout(function(){ |
| 1533 | self.processNotification('previewUpdated'); |
| 1534 | }, 1000) |
| 1535 | } |
| 1536 | self.checkReinitCarousel(settingID); |
| 1537 | } |
| 1538 | |
| 1539 | }, |
| 1540 | |
| 1541 | |
| 1542 | changeSwitcherSettingValue : function(settingID, onValue, offValue, ajaxAction = false) { |
| 1543 | var self = this; |
| 1544 | self.customizerFeedData.settings[settingID] = self.customizerFeedData.settings[settingID] == onValue ? offValue : onValue; |
| 1545 | if(ajaxAction !== false){ |
| 1546 | self.customizerControlAjaxAction(ajaxAction); |
| 1547 | } |
| 1548 | self.checkReinitCarousel(settingID); |
| 1549 | }, |
| 1550 | |
| 1551 | changeCheckboxSectionValue : function(settingID, value, ajaxAction = false){ |
| 1552 | var self = this; |
| 1553 | var settingValue = self.customizerFeedData.settings[settingID]; |
| 1554 | if(!Array.isArray(settingValue) && settingID == 'type'){ |
| 1555 | settingValue = [settingValue]; |
| 1556 | } |
| 1557 | if(settingValue.includes(value)){ |
| 1558 | settingValue.splice(settingValue.indexOf(value),1); |
| 1559 | }else{ |
| 1560 | settingValue.push(value); |
| 1561 | } |
| 1562 | if(settingID == 'type'){ |
| 1563 | self.processFeedTypesSources( settingValue ); |
| 1564 | } |
| 1565 | //settingValue = (settingValue.length == 1 && settingID == 'type') ? settingValue[0] : settingValue; |
| 1566 | self.customizerFeedData.settings[settingID] = settingValue; |
| 1567 | if(ajaxAction !== false){ |
| 1568 | self.customizerControlAjaxAction(ajaxAction); |
| 1569 | } |
| 1570 | if(settingID == 'include'){ |
| 1571 | setTimeout(function(){ |
| 1572 | self.generateMasonryGridHeight('update'); |
| 1573 | },250); |
| 1574 | } |
| 1575 | event.stopPropagation() |
| 1576 | |
| 1577 | }, |
| 1578 | checkboxSectionValueExists : function(settingID, value){ |
| 1579 | var self = this; |
| 1580 | var settingValue = self.customizerFeedData.settings[settingID]; |
| 1581 | return settingValue.includes(value) ? true : false; |
| 1582 | }, |
| 1583 | |
| 1584 | /** |
| 1585 | * Check Control Condition |
| 1586 | * |
| 1587 | * @since 4.0 |
| 1588 | */ |
| 1589 | checkControlCondition : function(conditionsArray = [], checkExtensionActive = false, checkExtensionActiveDimmed = false){ |
| 1590 | var self = this, |
| 1591 | isConditionTrue = 0; |
| 1592 | Object.keys(conditionsArray).forEach(function(condition, index){ |
| 1593 | if(conditionsArray[condition].indexOf(self.customizerFeedData.settings[condition]) !== -1) |
| 1594 | isConditionTrue += 1 |
| 1595 | }); |
| 1596 | var extensionCondition = checkExtensionActive != undefined && checkExtensionActive != false ? self.checkExtensionActive(checkExtensionActive) : true, |
| 1597 | extensionCondition = checkExtensionActiveDimmed != undefined && checkExtensionActiveDimmed != false && !self.checkExtensionActive(checkExtensionActiveDimmed) ? false : extensionCondition; |
| 1598 | |
| 1599 | return (isConditionTrue == Object.keys(conditionsArray).length) ? ( extensionCondition ) : false; |
| 1600 | }, |
| 1601 | |
| 1602 | /** |
| 1603 | * Check Color Override Condition |
| 1604 | * |
| 1605 | * @since 4.0 |
| 1606 | */ |
| 1607 | checkControlOverrideColor : function(overrideConditionsArray = []){ |
| 1608 | var self = this, |
| 1609 | isConditionTrue = 0; |
| 1610 | overrideConditionsArray.forEach(function(condition, index){ |
| 1611 | if(self.checkNotEmpty(self.customizerFeedData.settings[condition]) && self.customizerFeedData.settings[condition].replace(/ /gi,'') != '#'){ |
| 1612 | isConditionTrue += 1 |
| 1613 | } |
| 1614 | }); |
| 1615 | return (isConditionTrue >= 1) ? true : false; |
| 1616 | }, |
| 1617 | |
| 1618 | /** |
| 1619 | * Show Control |
| 1620 | * |
| 1621 | * @since 4.0 |
| 1622 | */ |
| 1623 | isControlShown : function( control ){ |
| 1624 | var self = this; |
| 1625 | if(control.checkExtension != undefined && control.checkExtension != false && !self.checkExtensionActive(control.checkExtension)){ |
| 1626 | return self.checkExtensionActive(control.checkExtension); |
| 1627 | } |
| 1628 | |
| 1629 | if(control.conditionDimmed != undefined && self.checkControlCondition(control.conditionDimmed) ) |
| 1630 | return self.checkControlCondition(control.conditionDimmed); |
| 1631 | if(control.overrideColorCondition != undefined){ |
| 1632 | return self.checkControlOverrideColor( control.overrideColorCondition ); |
| 1633 | } |
| 1634 | |
| 1635 | return ( control.conditionHide != undefined && control.condition != undefined || control.checkExtension != undefined ) |
| 1636 | ? self.checkControlCondition(control.condition, control.checkExtension) |
| 1637 | : true; |
| 1638 | }, |
| 1639 | |
| 1640 | checkExtensionActive : function(extension){ |
| 1641 | var self = this; |
| 1642 | return self.activeExtensions[extension]; |
| 1643 | }, |
| 1644 | |
| 1645 | expandSourceInfo : function(sourceId){ |
| 1646 | var self = this; |
| 1647 | self.customizerScreens.sourceExpanded = (self.customizerScreens.sourceExpanded === sourceId) ? null : sourceId; |
| 1648 | window.event.stopPropagation() |
| 1649 | }, |
| 1650 | |
| 1651 | resetColor: function(controlId){ |
| 1652 | this.customizerFeedData.settings[controlId] = ''; |
| 1653 | }, |
| 1654 | |
| 1655 | //Source Active Customizer |
| 1656 | isSourceActiveCustomizer : function(source){ |
| 1657 | var self = this; |
| 1658 | return ( |
| 1659 | Array.isArray(self.customizerFeedData.settings.sources.map) || |
| 1660 | self.customizerFeedData.settings.sources instanceof Object |
| 1661 | ) && |
| 1662 | self.customizerScreens.sourcesChoosed.map(s => s.account_id).includes(source.account_id); |
| 1663 | //self.customizerFeedData.settings.sources.map(s => s.account_id).includes(source.account_id); |
| 1664 | }, |
| 1665 | //Choose Source From Customizer |
| 1666 | selectSourceCustomizer : function(source, isRemove = false){ |
| 1667 | var self = this, |
| 1668 | isMultifeed = (self.activeExtensions['multifeed'] !== undefined && self.activeExtensions['multifeed'] == true), |
| 1669 | sourcesListMap = Array.isArray(self.customizerFeedData.settings.sources) || self.customizerFeedData.settings.sources instanceof Object ? self.customizerFeedData.settings.sources.map(s => s.account_id) : []; |
| 1670 | if(isMultifeed){ |
| 1671 | if(sourcesListMap.includes(source.account_id)){ |
| 1672 | var indexToRemove = self.customizerFeedData.settings.sources.findIndex(src => src.account_id === source.account_id); |
| 1673 | self.customizerScreens.sourcesChoosed.splice(indexToRemove, 1); |
| 1674 | if(isRemove){ |
| 1675 | self.customizerFeedData.settings.sources.splice(indexToRemove, 1); |
| 1676 | } |
| 1677 | }else{ |
| 1678 | self.customizerScreens.sourcesChoosed.push(source); |
| 1679 | } |
| 1680 | }else{ |
| 1681 | self.customizerScreens.sourcesChoosed = (sourcesListMap.includes(source)) ? [] : [source]; |
| 1682 | } |
| 1683 | cffBuilder.$forceUpdate(); |
| 1684 | }, |
| 1685 | closeSourceCustomizer : function(){ |
| 1686 | var self = this; |
| 1687 | self.viewsActive['sourcePopup'] = false; |
| 1688 | //self.customizerFeedData.settings.sources = self.customizerScreens.sourcesChoosed; |
| 1689 | cffBuilder.$forceUpdate(); |
| 1690 | }, |
| 1691 | customizerFeedTypePrint : function(){ |
| 1692 | var self = this, |
| 1693 | combinedTypes = self.feedTypes.concat(self.advancedFeedTypes); |
| 1694 | result = combinedTypes.filter(function(tp){ |
| 1695 | return tp.type === self.customizerFeedData.settings.feedtype |
| 1696 | }); |
| 1697 | self.customizerScreens.printedType = result.length > 0 ? result[0] : []; |
| 1698 | return result.length > 0 ? true : false; |
| 1699 | }, |
| 1700 | choosedFeedTypeCustomizer : function(feedType){ |
| 1701 | var self = this, result = false; |
| 1702 | if( |
| 1703 | (self.viewsActive.feedTypeElement === null && self.customizerFeedData.settings.feedtype === feedType) || |
| 1704 | (self.viewsActive.feedTypeElement !== null && self.viewsActive.feedTypeElement == feedType) |
| 1705 | ){ |
| 1706 | result = true; |
| 1707 | } |
| 1708 | return result; |
| 1709 | }, |
| 1710 | |
| 1711 | |
| 1712 | |
| 1713 | updateFeedTypeCustomizer : function(){ |
| 1714 | var self = this; |
| 1715 | if (self.viewsActive.feedTypeElement === 'socialwall') { |
| 1716 | window.location.href = cff_builder.pluginsInfo.social_wall.settingsPage; |
| 1717 | return; |
| 1718 | } |
| 1719 | self.setType( self.viewsActive.feedTypeElement ); |
| 1720 | |
| 1721 | self.customizerFeedData.settings.feedtype = self.viewsActive.feedTypeElement; |
| 1722 | self.viewsActive.feedTypeElement = null; |
| 1723 | self.viewsActive.feedtypesPopup = false; |
| 1724 | self.customizerControlAjaxAction('feedFlyPreview'); |
| 1725 | cffBuilder.$forceUpdate(); |
| 1726 | }, |
| 1727 | updateInputWidth : function(){ |
| 1728 | this.customizerScreens.inputNameWidth = ((document.getElementById("cff-csz-hd-input").value.length + 6) * 8) + 'px'; |
| 1729 | }, |
| 1730 | customizerStyleMaker : function(){ |
| 1731 | var self = this; |
| 1732 | if(self.customizerSidebarBuilder){ |
| 1733 | self.feedStyle = ''; |
| 1734 | Object.values(self.customizerSidebarBuilder).map( function(tab) { |
| 1735 | self.customizerSectionStyle(tab.sections); |
| 1736 | }); |
| 1737 | return '<style type="text/css">' + self.feedStyle + '</style>'; |
| 1738 | } |
| 1739 | return false; |
| 1740 | }, |
| 1741 | |
| 1742 | /** |
| 1743 | * Get Feed Preview Global CSS Class |
| 1744 | * |
| 1745 | * @since 4.0 |
| 1746 | * @return String |
| 1747 | */ |
| 1748 | feedPreviewCssClasses : function(){ |
| 1749 | var self = this, |
| 1750 | colorScheme = self.customizerFeedData.settings.colorpalette; |
| 1751 | |
| 1752 | }, |
| 1753 | |
| 1754 | customizerSectionStyle : function(sections){ |
| 1755 | var self = this; |
| 1756 | Object.values(sections).map(function(section){ |
| 1757 | if(section.controls){ |
| 1758 | Object.values(section.controls).map(function(control){ |
| 1759 | self.returnControlStyle(control); |
| 1760 | }); |
| 1761 | } |
| 1762 | if(section.nested_sections){ |
| 1763 | self.customizerSectionStyle(section.nested_sections); |
| 1764 | Object.values(section.nested_sections).map(function(nestedSections){ |
| 1765 | Object.values(nestedSections.controls).map(function(nestedControl){ |
| 1766 | if(nestedControl.section){ |
| 1767 | self.customizerSectionStyle(nestedControl); |
| 1768 | } |
| 1769 | }); |
| 1770 | }); |
| 1771 | } |
| 1772 | }); |
| 1773 | }, |
| 1774 | returnControlStyle : function( control ){ |
| 1775 | var self = this; |
| 1776 | if(control.style){ |
| 1777 | Object.entries(control.style).map( function(css) { |
| 1778 | var condition = control.condition != undefined || control.checkExtension != undefined ? self.checkControlCondition(control.condition, control.checkExtension) : true; |
| 1779 | if( condition ){ |
| 1780 | self.feedStyle += |
| 1781 | css[0] + '{' + |
| 1782 | css[1].replace("{{value}}", self.customizerFeedData.settings[control.id]) + |
| 1783 | '}'; |
| 1784 | } |
| 1785 | }); |
| 1786 | } |
| 1787 | }, |
| 1788 | |
| 1789 | /** |
| 1790 | * Check Reinit Carousel |
| 1791 | * |
| 1792 | * @since 4.0 |
| 1793 | */ |
| 1794 | checkReinitCarousel : function(settingID){ |
| 1795 | var self = this, |
| 1796 | whenToReiniCarousel = [ |
| 1797 | 'carouselheight', |
| 1798 | 'carouseldesktop_cols', |
| 1799 | 'carouselmobile_cols', |
| 1800 | 'carouselnavigation', |
| 1801 | 'carouselpagination', |
| 1802 | 'carouselautoplay', |
| 1803 | 'carouselinterval', |
| 1804 | 'reviewshidenotext', |
| 1805 | 'hidenegative', |
| 1806 | 'reviewsrated' |
| 1807 | ]; |
| 1808 | if( whenToReiniCarousel.includes( settingID ) ){ |
| 1809 | self.reinitCarouselHTML(); |
| 1810 | } |
| 1811 | }, |
| 1812 | |
| 1813 | |
| 1814 | /** |
| 1815 | * Customizer Control Ajax |
| 1816 | * Some of the customizer controls need to perform Ajax |
| 1817 | * Calls in order to update the preview |
| 1818 | * |
| 1819 | * @since 4.0 |
| 1820 | */ |
| 1821 | customizerControlAjaxAction : function( actionType ){ |
| 1822 | var self = this; |
| 1823 | switch (actionType) { |
| 1824 | case 'feedFlyPreview': |
| 1825 | self.loadingBar = true; |
| 1826 | var previewFeedData = { |
| 1827 | action : 'cff_feed_saver_manager_fly_preview', |
| 1828 | feedID : self.customizerFeedData.feed_info.id, |
| 1829 | previewSettings : self.customizerFeedData.settings, |
| 1830 | }; |
| 1831 | self.ajaxPost(previewFeedData, function(_ref){ |
| 1832 | var data = _ref.data; |
| 1833 | if( data !== false ){ |
| 1834 | self.disableJQueryNodes(); |
| 1835 | self.customizerFeedData.posts = data.posts; |
| 1836 | self.customizerFeedData.header = data.header; |
| 1837 | self.processNotification("previewUpdated"); |
| 1838 | }else{ |
| 1839 | self.processNotification("unkownError"); |
| 1840 | } |
| 1841 | setTimeout(function(){ |
| 1842 | self.reinitCarouselHTML(); |
| 1843 | self.generateMasonryGridHeight('update'); |
| 1844 | }, 150); |
| 1845 | }); |
| 1846 | break; |
| 1847 | case 'feedPreviewRender': |
| 1848 | setTimeout(function(){ |
| 1849 | self.generateMasonryGridHeight('update'); |
| 1850 | }, 150); |
| 1851 | break; |
| 1852 | } |
| 1853 | }, |
| 1854 | |
| 1855 | /** |
| 1856 | * Process & Re-Order Post Array for Masonry layouts |
| 1857 | * |
| 1858 | * @since 4.0 |
| 1859 | * |
| 1860 | * @return Array |
| 1861 | */ |
| 1862 | processPostArrayDisplay : function(postsArray){ |
| 1863 | var self = this, |
| 1864 | feedlayout = self.customizerFeedData.settings.feedlayout, |
| 1865 | feedtype = self.customizerFeedData.settings.feedtype, |
| 1866 | currentDevice = self.customizerScreens.previewScreen; |
| 1867 | if(feedlayout === 'masonry'){ |
| 1868 | var colsNumber = 1; |
| 1869 | switch (currentDevice) { |
| 1870 | case 'desktop': |
| 1871 | colsNumber = self.customizerFeedData.settings.cols; |
| 1872 | break; |
| 1873 | case 'tablet': |
| 1874 | colsNumber = self.customizerFeedData.settings.colstablet; |
| 1875 | break; |
| 1876 | case 'mobile': |
| 1877 | colsNumber = self.customizerFeedData.settings.colsmobile; |
| 1878 | break; |
| 1879 | } |
| 1880 | colsNumber = parseInt(colsNumber); |
| 1881 | if(colsNumber > 1){ |
| 1882 | var reorderedPostsArray = [], |
| 1883 | counter = 0; |
| 1884 | while(counter < colsNumber) { |
| 1885 | for(var i = 0; i < postsArray.length; i += colsNumber) { |
| 1886 | var elementIndex = parseInt(i) + parseInt(counter); |
| 1887 | var _val = postsArray[elementIndex]; |
| 1888 | if (_val !== undefined) |
| 1889 | reorderedPostsArray.push(_val); |
| 1890 | } |
| 1891 | counter++; |
| 1892 | } |
| 1893 | postsArray = reorderedPostsArray; |
| 1894 | } |
| 1895 | } |
| 1896 | return postsArray; |
| 1897 | }, |
| 1898 | |
| 1899 | /** |
| 1900 | * Generate the Feed Posts Height For Masonry & Grid Layouts |
| 1901 | * |
| 1902 | * @since 4.0 |
| 1903 | */ |
| 1904 | generateCarouselSettings : function(){ |
| 1905 | var self = this, |
| 1906 | carouselElement = jQuery('.cff-preview-posts-list-ctn'), |
| 1907 | customizerSettings = self.customizerFeedData.settings, |
| 1908 | currentDevice = self.customizerScreens.previewScreen; |
| 1909 | if(customizerSettings.feedlayout === 'carousel' && self.activeExtensions['carousel'] == true){ |
| 1910 | carouselElement.addClass('cff-carousel'); |
| 1911 | var carouselHeightInput = customizerSettings.carouselheight, |
| 1912 | carouselMobileCols = parseInt(customizerSettings.carouselmobile_cols), |
| 1913 | carouselCols = (currentDevice == 'desktop') ? parseInt(customizerSettings.carouseldesktop_cols) : carouselMobileCols, |
| 1914 | carouselArrowsInput = parseInt(customizerSettings.carouselnavigation), |
| 1915 | carouselArrows = true, |
| 1916 | carouselPag = self.valueIsEnabled(customizerSettings.carouselpagination) ? true : false, |
| 1917 | carouselautoplay = self.valueIsEnabled(customizerSettings.carouselautoplay) ? true : false, |
| 1918 | carouselTime = customizerSettings.carouselinterval, |
| 1919 | afterUpdate = true; |
| 1920 | //afterInit = cffShowCarousel, |
| 1921 | singleItem = false, |
| 1922 | autoHeight = false; |
| 1923 | if(customizerSettings.carouselheight == 'autoexpand'){ |
| 1924 | singleItem = true; |
| 1925 | autoHeight = true; |
| 1926 | carouselCols = 1; |
| 1927 | carouselMobileCols = 1; |
| 1928 | } |
| 1929 | |
| 1930 | |
| 1931 | var carouselSettings = { |
| 1932 | items: carouselCols, |
| 1933 | itemsDesktop: [1199, carouselCols], |
| 1934 | itemsDesktopSmall: false, |
| 1935 | itemsTablet: false, |
| 1936 | itemsTabletSmall: false, |
| 1937 | itemsMobile: [479, carouselMobileCols], |
| 1938 | navigation: carouselArrows, |
| 1939 | navigationText: ['<i class="fa fa-chevron-left"></i>','<i class="fa fa-chevron-right"></i>'], |
| 1940 | dots: carouselPag, |
| 1941 | autoplay:carouselautoplay, |
| 1942 | autoplayTimeout:carouselTime, |
| 1943 | stopOnHover: true, |
| 1944 | singleItem : singleItem, |
| 1945 | autoHeight : autoHeight, |
| 1946 | margin: 20, |
| 1947 | |
| 1948 | // afterUpdate: afterUpdate, |
| 1949 | // afterInit: afterInit |
| 1950 | }; |
| 1951 | carouselElement.owlCarousel(carouselSettings); |
| 1952 | carouselElement.on('changed.owl.carousel',function(){ |
| 1953 | self.generateNavigationCarousel(customizerSettings, carouselElement); |
| 1954 | }) |
| 1955 | self.generateCarouselHTMLAttributes(carouselElement); |
| 1956 | |
| 1957 | } |
| 1958 | }, |
| 1959 | |
| 1960 | /** |
| 1961 | * Generate Carousel HTML Attributes |
| 1962 | * |
| 1963 | * @since 4.0 |
| 1964 | */ |
| 1965 | generateCarouselHTMLAttributes : function(carouselElement){ |
| 1966 | var self = this, |
| 1967 | customizerSettings = self.customizerFeedData.settings; |
| 1968 | carouselElement.attr({ |
| 1969 | 'data-navigation' : customizerSettings.carouselnavigation |
| 1970 | }); |
| 1971 | self.generateNavigationCarousel(customizerSettings, carouselElement); |
| 1972 | }, |
| 1973 | |
| 1974 | /** |
| 1975 | * Generate Carousel Navigation |
| 1976 | * |
| 1977 | * @since 4.0 |
| 1978 | */ |
| 1979 | generateNavigationCarousel : function(customizerSettings, carouselElement){ |
| 1980 | if(customizerSettings.carouselnavigation == 'below'){ |
| 1981 | var $navigation = carouselElement.find('.owl-dots'); |
| 1982 | carouselElement.find('.owl-nav').remove(); |
| 1983 | if($navigation.children('.owl-prev').length <= 0){ |
| 1984 | $navigation.prepend('<button type="button" role="presentation" class="owl-prev"><span aria-label="Previous">‹</span></button>'); |
| 1985 | } |
| 1986 | if($navigation.children('.owl-next').length <= 0){ |
| 1987 | $navigation.append('<button type="button" role="presentation" class="owl-next"><span aria-label="Next">›</span></button>'); |
| 1988 | } |
| 1989 | |
| 1990 | } |
| 1991 | }, |
| 1992 | |
| 1993 | /** |
| 1994 | * Disable JQuery Plugin Nodes |
| 1995 | * |
| 1996 | * @since 4.0 |
| 1997 | */ |
| 1998 | disableJQueryNodes : function(){ |
| 1999 | var self = this, |
| 2000 | customizerSettings = self.customizerFeedData.settings, |
| 2001 | carouselElement = jQuery('.cff-preview-posts-list-ctn'); |
| 2002 | if(self.activeExtensions['carousel'] == true){ |
| 2003 | carouselElement.owlCarousel('destroy'); |
| 2004 | carouselElement.removeClass('cff-carousel'); |
| 2005 | carouselElement.removeAttr('data-navigation'); |
| 2006 | } |
| 2007 | }, |
| 2008 | |
| 2009 | /** |
| 2010 | * Reinit Carousel Element |
| 2011 | * |
| 2012 | * @since 4.0 |
| 2013 | */ |
| 2014 | reinitCarouselHTML : function(){ |
| 2015 | var self = this, |
| 2016 | customizerSettings = self.customizerFeedData.settings, |
| 2017 | carouselElement = jQuery('.cff-preview-posts-list-ctn'); |
| 2018 | if(self.activeExtensions['carousel'] == true){ |
| 2019 | carouselElement.owlCarousel('destroy'); |
| 2020 | carouselElement.removeClass('cff-carousel'); |
| 2021 | carouselElement.removeAttr('data-navigation'); |
| 2022 | if(customizerSettings.feedlayout === 'carousel'){ |
| 2023 | self.loadingBar = true; |
| 2024 | setTimeout(function(){ |
| 2025 | self.generateCarouselSettings(); |
| 2026 | self.processNotification('carouselLayoutUpdated'); |
| 2027 | }, 150) |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | }, |
| 2032 | |
| 2033 | /** |
| 2034 | * Generate the Feed Posts Height For Masonry & Grid Layouts |
| 2035 | * |
| 2036 | * @since 4.0 |
| 2037 | */ |
| 2038 | generateMasonryGridHeight : function(typeAppend){ |
| 2039 | var self = this, |
| 2040 | feedlayout = self.customizerFeedData.settings.feedlayout, |
| 2041 | feedtype = self.customizerFeedData.settings.feedtype, |
| 2042 | currentDevice = self.customizerScreens.previewScreen; |
| 2043 | //Masonry Layout |
| 2044 | if(feedlayout === 'masonry'){ |
| 2045 | var $masonryParent = jQuery('.cff-preview-posts-masonry').isotope({ |
| 2046 | itemSelector: '.cff-post-item-ctn', |
| 2047 | percentPosition: true, |
| 2048 | masonry: { |
| 2049 | columnWidth: '.cff-post-item-ctn' |
| 2050 | } |
| 2051 | }); |
| 2052 | // layout Isotope after each image loads |
| 2053 | $masonryParent.imagesLoaded().progress( function() { |
| 2054 | if(typeAppend == 'update'){ |
| 2055 | $masonryParent.isotope('reloadItems').isotope(); |
| 2056 | }else{ |
| 2057 | $masonryParent.isotope('layout'); |
| 2058 | } |
| 2059 | }); |
| 2060 | |
| 2061 | }else{ |
| 2062 | if(jQuery('.cff-preview-posts-list-ctn').data('isotope')){ |
| 2063 | jQuery('.cff-preview-posts-list-ctn').isotope('destroy') |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | //Grid Layout |
| 2068 | if(feedlayout === 'grid'){ |
| 2069 | var grid = document.getElementsByClassName('cff-preview-posts-grid')[0]; |
| 2070 | if( grid ) { |
| 2071 | var allItems = document.querySelectorAll('.cff-post-item-ctn'); |
| 2072 | if( allItems ) { |
| 2073 | var plusHeight = (feedtype == 'videos' || feedtype == 'albums') ? 70 : 0; |
| 2074 | allItems.forEach( function(item, index) { |
| 2075 | item.style.height = parseFloat(item.getBoundingClientRect().width + plusHeight) + 'px'; |
| 2076 | item.style.gridRowEnd = 'unset'; |
| 2077 | }); |
| 2078 | } |
| 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | if(feedlayout == 'carousel' && feedtype == 'singlealbum'){ |
| 2083 | var allItems = document.querySelectorAll('.owl-item'); |
| 2084 | if( allItems ) { |
| 2085 | allItems.forEach( function(item, index) { |
| 2086 | item.style.height = item.getBoundingClientRect().width + 'px'; |
| 2087 | item.style.gridRowEnd = 'unset'; |
| 2088 | }); |
| 2089 | } |
| 2090 | } |
| 2091 | }, |
| 2092 | |
| 2093 | |
| 2094 | /** |
| 2095 | * Get Feed Columns Depending on the Settings |
| 2096 | * |
| 2097 | * @since 4.0 |
| 2098 | * |
| 2099 | * @return String | Bool |
| 2100 | */ |
| 2101 | getFeedColumns : function(){ |
| 2102 | var self = this, |
| 2103 | feedlayout = self.customizerFeedData.settings.feedlayout, |
| 2104 | feedtype = self.customizerFeedData.settings.feedtype, |
| 2105 | currentDevice = self.customizerScreens.previewScreen; |
| 2106 | |
| 2107 | if(feedlayout === 'masonry' || (feedlayout === 'grid' && feedtype !== 'timeline')){ |
| 2108 | switch (currentDevice) { |
| 2109 | case 'desktop': |
| 2110 | return self.customizerFeedData.settings.cols; |
| 2111 | case 'tablet': |
| 2112 | return self.customizerFeedData.settings.colstablet; |
| 2113 | case 'mobile': |
| 2114 | return self.customizerFeedData.settings.colsmobile; |
| 2115 | } |
| 2116 | } |
| 2117 | return false; |
| 2118 | }, |
| 2119 | |
| 2120 | /** |
| 2121 | * Toggle Comment Section |
| 2122 | * |
| 2123 | * @since 4.0 |
| 2124 | */ |
| 2125 | toggleCommentSection : function(postID){ |
| 2126 | var self = this; |
| 2127 | if(self.showedCommentSection.includes(postID)){ |
| 2128 | self.showedCommentSection.splice(self.showedCommentSection.indexOf(postID), 1); |
| 2129 | }else{ |
| 2130 | self.showedCommentSection.push(postID); |
| 2131 | } |
| 2132 | setTimeout(function(){ |
| 2133 | self.generateMasonryGridHeight('update'); |
| 2134 | }, 100) |
| 2135 | cffBuilder.$forceUpdate(); |
| 2136 | }, |
| 2137 | |
| 2138 | /** |
| 2139 | * Ajax Action : Save Feed Settings |
| 2140 | * |
| 2141 | * @since 4.0 |
| 2142 | */ |
| 2143 | saveFeedSettings : function(){ |
| 2144 | var self = this, |
| 2145 | sources = [], |
| 2146 | updateFeedData = { |
| 2147 | action : 'cff_feed_saver_manager_builder_update', |
| 2148 | update_feed : 'true', |
| 2149 | feed_id : self.customizerFeedData.feed_info.id, |
| 2150 | feed_name : self.customizerFeedData.feed_info.feed_name, |
| 2151 | settings : self.customizerFeedData.settings, |
| 2152 | sources : [] |
| 2153 | }; |
| 2154 | |
| 2155 | if(self.customizerFeedData.settings.sources.length > 0){ |
| 2156 | self.customizerFeedData.settings.sources.forEach(function(source){ |
| 2157 | updateFeedData.sources.push(source.account_id); |
| 2158 | }) |
| 2159 | } |
| 2160 | self.loadingBar = true; |
| 2161 | self.ajaxPost(updateFeedData, function(_ref){ |
| 2162 | var data = _ref.data; |
| 2163 | if(data && data.success === true){ |
| 2164 | self.processNotification('feedSaved'); |
| 2165 | self.customizerFeedDataInitial = self.customizerFeedData; |
| 2166 | }else{ |
| 2167 | self.processNotification('feedSavedError'); |
| 2168 | } |
| 2169 | }); |
| 2170 | cffBuilder.$forceUpdate(); |
| 2171 | }, |
| 2172 | |
| 2173 | /** |
| 2174 | * Ajax Action : Clear Single Feed Cache |
| 2175 | * Update Feed Preview Too |
| 2176 | * @since 4.0 |
| 2177 | */ |
| 2178 | clearSingleFeedCache : function(){ |
| 2179 | var self = this, |
| 2180 | sources = [], |
| 2181 | clearFeedData = { |
| 2182 | action : 'cff_feed_saver_manager_clear_single_feed_cache', |
| 2183 | feedID : self.customizerFeedData.feed_info.id, |
| 2184 | previewSettings : self.customizerFeedData.settings, |
| 2185 | }; |
| 2186 | self.loadingBar = true; |
| 2187 | self.ajaxPost(clearFeedData, function(_ref){ |
| 2188 | var data = _ref.data; |
| 2189 | if( data !== false ){ |
| 2190 | self.customizerFeedData.posts = data.posts; |
| 2191 | self.customizerFeedData.header = data.header; |
| 2192 | self.processNotification('cacheCleared'); |
| 2193 | }else{ |
| 2194 | self.processNotification("unkownError"); |
| 2195 | } |
| 2196 | }) |
| 2197 | cffBuilder.$forceUpdate(); |
| 2198 | }, |
| 2199 | |
| 2200 | /** |
| 2201 | * Clear & Reset Color Override |
| 2202 | * |
| 2203 | * @since 4.0 |
| 2204 | */ |
| 2205 | resetColorOverride : function(settingID){ |
| 2206 | this.customizerFeedData.settings[settingID] = ''; |
| 2207 | }, |
| 2208 | |
| 2209 | /** |
| 2210 | * Print Story |
| 2211 | * |
| 2212 | * @since 4.0 |
| 2213 | * |
| 2214 | * @return String |
| 2215 | */ |
| 2216 | printStory : function(singlePost){ |
| 2217 | var self = this, |
| 2218 | authorName = self.hasOwnNestedProperty(singlePost, 'from.name') ? singlePost.from.name : null, |
| 2219 | postStory = self.hasOwnNestedProperty(singlePost, 'story') && authorName != null ? singlePost.story.replace(authorName, '') : null; |
| 2220 | return postStory; |
| 2221 | }, |
| 2222 | |
| 2223 | |
| 2224 | /** |
| 2225 | * Format & Print Date |
| 2226 | * |
| 2227 | * @since 4.0 |
| 2228 | * |
| 2229 | * @return String |
| 2230 | */ |
| 2231 | printDate : function( postDate, eventDate = false ){ |
| 2232 | var self = this, |
| 2233 | originalDate = Date.parse(postDate) / 1000, |
| 2234 | dateOffset = new Date(), |
| 2235 | offsetTimezone = dateOffset.getTimezoneOffset(), |
| 2236 | periods = [ |
| 2237 | self.translatedText.secondText, |
| 2238 | self.translatedText.minuteText, |
| 2239 | self.translatedText.hourText, |
| 2240 | self.translatedText.dayText, |
| 2241 | self.translatedText.weekText, |
| 2242 | self.translatedText.monthText, |
| 2243 | self.translatedText.yearText |
| 2244 | ], |
| 2245 | periodsPlural = [ |
| 2246 | self.translatedText.secondsText, |
| 2247 | self.translatedText.minutesText, |
| 2248 | self.translatedText.hoursText, |
| 2249 | self.translatedText.daysText, |
| 2250 | self.translatedText.weeksText, |
| 2251 | self.translatedText.monthsText, |
| 2252 | self.translatedText.yearsText |
| 2253 | ], |
| 2254 | lengths = ["60","60","24","7","4.35","12","10"], |
| 2255 | now = dateOffset.getTime() / 1000, |
| 2256 | newTime = originalDate + offsetTimezone, |
| 2257 | printDate = '', |
| 2258 | dateFortmat = eventDate ? self.customizerFeedData.settings.eventdateformat : self.customizerFeedData.settings.dateformat, |
| 2259 | agoText = self.translatedText.agoText, |
| 2260 | difference = null, |
| 2261 | formatsChoices = { |
| 2262 | '2' : 'F jS, g:i a', |
| 2263 | '3' : 'F jS', |
| 2264 | '4' : 'D F jS', |
| 2265 | '5' : 'l F jS', |
| 2266 | '6' : 'D M jS, Y', |
| 2267 | '7' : 'l F jS, Y', |
| 2268 | '8' : 'l F jS, Y - g:i a', |
| 2269 | '9' : "l M jS, 'y", |
| 2270 | '10' : 'm.d.y', |
| 2271 | '11' : 'm/d/y', |
| 2272 | '12' : 'd.m.y', |
| 2273 | '13' : 'd/m/y', |
| 2274 | '14' : 'd-m-Y, G:i', |
| 2275 | '15' : 'jS F Y, G:i', |
| 2276 | '16' : 'd M Y, G:i', |
| 2277 | '17' : 'l jS F Y, G:i', |
| 2278 | '18' : 'm.d.y - G:i', |
| 2279 | '19' : 'd.m.y - G:i' |
| 2280 | }; |
| 2281 | |
| 2282 | if(formatsChoices.hasOwnProperty(dateFortmat)){ |
| 2283 | printDate = date_i18n( formatsChoices[dateFortmat], newTime ); |
| 2284 | }else if(dateFortmat == 'custom'){ |
| 2285 | printDate = date_i18n( self.customizerFeedData.settings.datecustom, newTime ); |
| 2286 | |
| 2287 | } |
| 2288 | else{ |
| 2289 | if( now > originalDate ) { |
| 2290 | difference = now - originalDate; |
| 2291 | |
| 2292 | }else{ |
| 2293 | difference = originalDate - now; |
| 2294 | } |
| 2295 | for(var j = 0; difference >= lengths[j] && j < lengths.length-1; j++) { |
| 2296 | difference /= lengths[j]; |
| 2297 | } |
| 2298 | difference = Math.round(difference); |
| 2299 | if(difference != 1) { |
| 2300 | periods[j] = periodsPlural[j]; |
| 2301 | } |
| 2302 | printDate = difference + " " + periods[j] + " "+ agoText; |
| 2303 | } |
| 2304 | |
| 2305 | return printDate; |
| 2306 | }, |
| 2307 | |
| 2308 | /** |
| 2309 | * Print Event Location |
| 2310 | * |
| 2311 | * @since 4.0 |
| 2312 | * |
| 2313 | * @return String |
| 2314 | */ |
| 2315 | getEventMapLink : function( place ){ |
| 2316 | var self = this; |
| 2317 | latitude = (self.hasOwnNestedProperty(place,'location.latitude')) ? self.htmlEntities(place.location.latitude) : '', |
| 2318 | longitude = (self.hasOwnNestedProperty(place,'location.longitude')) ? self.htmlEntities(place.location.longitude) : '', |
| 2319 | locationMap = self.hasOwnNestedProperty(place,'name') ? self.htmlEntities(place.name) : '', |
| 2320 | mapUrl = false; |
| 2321 | if( self.hasOwnNestedProperty(place, 'location') ){ |
| 2322 | mapUrl = 'https://maps.google.com/maps?q=' + latitude + ',+' + longitude; |
| 2323 | }else if( locationMap.match(/~[0-9]~/) && locationMap.length > 10 ){ |
| 2324 | mapUrl = 'https://maps.google.com/maps?q='+ location; |
| 2325 | } |
| 2326 | return mapUrl; |
| 2327 | }, |
| 2328 | |
| 2329 | /** |
| 2330 | * Posts List |
| 2331 | * |
| 2332 | * @since 4.0 |
| 2333 | * |
| 2334 | * @return Array |
| 2335 | */ |
| 2336 | returnPostList : function(){ |
| 2337 | var self = this, |
| 2338 | customizerSettings = self.customizerFeedData.settings |
| 2339 | if(customizerSettings.feedtype == 'reviews'){ |
| 2340 | return self.reviewsFeedTypeCheck(); |
| 2341 | }else{ |
| 2342 | var numberOfPosts = (self.customizerScreens.previewScreen == 'desktop') ? customizerSettings.num : (self.checkNotEmpty(customizerSettings.nummobile) ? customizerSettings.nummobile : customizerSettings.num); |
| 2343 | numberOfPosts = self.checkNotEmpty(numberOfPosts) ? numberOfPosts : 0; |
| 2344 | return (customizerSettings.feedlayout == 'carousel') ? self.customizerFeedData.posts : self.customizerFeedData.posts.slice(0, numberOfPosts); |
| 2345 | } |
| 2346 | }, |
| 2347 | |
| 2348 | /** |
| 2349 | * Create String of Views Rated |
| 2350 | * |
| 2351 | * @since 4.0 |
| 2352 | * |
| 2353 | * @return Array |
| 2354 | */ |
| 2355 | processReviewsRated : function(){ |
| 2356 | var self = this, |
| 2357 | settings = self.customizerFeedData.settings, |
| 2358 | reviewsratedArray = [], |
| 2359 | star5 = self.valueIsEnabled(settings.cff_reviews_rated_5) ? reviewsratedArray.push(5) : reviewsratedArray.splice(reviewsratedArray.indexOf(5)), |
| 2360 | star4 = self.valueIsEnabled(settings.cff_reviews_rated_4) ? reviewsratedArray.push(4) : reviewsratedArray.splice(reviewsratedArray.indexOf(4)), |
| 2361 | star3 = self.valueIsEnabled(settings.cff_reviews_rated_3) ? reviewsratedArray.push(3) : reviewsratedArray.splice(reviewsratedArray.indexOf(3)), |
| 2362 | star2 = self.valueIsEnabled(settings.cff_reviews_rated_2) ? reviewsratedArray.push(2) : reviewsratedArray.splice(reviewsratedArray.indexOf(2)), |
| 2363 | star1 = self.valueIsEnabled(settings.cff_reviews_rated_1) ? reviewsratedArray.push(1) : reviewsratedArray.splice(reviewsratedArray.indexOf(1)); |
| 2364 | self.customizerFeedData.settings.reviewsrated = reviewsratedArray.join(','); |
| 2365 | return reviewsratedArray; |
| 2366 | }, |
| 2367 | |
| 2368 | |
| 2369 | /** |
| 2370 | * Check & Process Reviews Feed Type |
| 2371 | * |
| 2372 | * @since 4.0 |
| 2373 | * |
| 2374 | * @return Array |
| 2375 | */ |
| 2376 | reviewsFeedTypeCheck : function(){ |
| 2377 | var self = this, |
| 2378 | reviewArray = [], |
| 2379 | reviewsratedArray = self.processReviewsRated(); |
| 2380 | |
| 2381 | self.customizerFeedData.posts.forEach( function(review, index) { |
| 2382 | if( |
| 2383 | ( |
| 2384 | self.valueIsEnabled(self.customizerFeedData.settings.reviewshidenotext) && self.checkNotEmpty(review.review_text) == true |
| 2385 | ) |
| 2386 | || !self.valueIsEnabled(self.customizerFeedData.settings.reviewshidenotext) |
| 2387 | ){ |
| 2388 | var hasReviewRating = review.rating != undefined && review.rating != null; |
| 2389 | if( ( hasReviewRating && reviewsratedArray.includes(review.rating) ) || !hasReviewRating ){ |
| 2390 | reviewArray.push({ |
| 2391 | created_time : review.created_time, |
| 2392 | recommendation_type : review.recommendation_type, |
| 2393 | message : review.review_text, |
| 2394 | from : review.reviewer, |
| 2395 | rating : review.rating ? review.rating : undefined |
| 2396 | }); |
| 2397 | } |
| 2398 | } |
| 2399 | }); |
| 2400 | return reviewArray; |
| 2401 | }, |
| 2402 | |
| 2403 | |
| 2404 | /** |
| 2405 | * HTML Entities |
| 2406 | * |
| 2407 | * @since 4.0 |
| 2408 | * |
| 2409 | * @return String |
| 2410 | */ |
| 2411 | htmlEntities : function (str) { |
| 2412 | return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); |
| 2413 | }, |
| 2414 | |
| 2415 | /** |
| 2416 | * Check Process Post Image |
| 2417 | * |
| 2418 | * @since 4.0 |
| 2419 | */ |
| 2420 | checkProcessPostImage : function( post ){ |
| 2421 | var self = this, |
| 2422 | showImage = self.customizerFeedData.settings.include.includes('media') && (post.status_type == 'added_photos' || post.status_type == 'created_event' || self.customizerFeedData.settings.feedtype == 'events'); |
| 2423 | imageExist = self.hasOwnNestedProperty(post, 'full_picture') ? true : ( self.hasOwnNestedProperty(post , 'attachments.data') && post.attachments.data[0] && post.attachments.data[0].media ? true : false); |
| 2424 | if( self.customizerFeedData.settings.feedtype == 'events' ){ |
| 2425 | imageExist = self.hasOwnNestedProperty(post, 'cover.source'); |
| 2426 | } |
| 2427 | return imageExist && showImage; |
| 2428 | }, |
| 2429 | |
| 2430 | /** |
| 2431 | * Process Post Image Source |
| 2432 | * |
| 2433 | * @since 4.0 |
| 2434 | */ |
| 2435 | processPostImageSrc : function( post ){ |
| 2436 | var self = this; |
| 2437 | if(self.customizerFeedData.settings.feedtype == 'events' && self.hasOwnNestedProperty(post, 'cover.source') ){ |
| 2438 | return post.cover.source; |
| 2439 | } |
| 2440 | return self.hasOwnNestedProperty(post, 'full_picture') ? post.full_picture : post.attachments.data[0].media.image.src |
| 2441 | }, |
| 2442 | |
| 2443 | /** |
| 2444 | * Process Video LightBox |
| 2445 | * |
| 2446 | * @since 4.0 |
| 2447 | */ |
| 2448 | processPostVideoSrc : function( singlePost ){ |
| 2449 | var self = this, |
| 2450 | videoInfo = self.processIframeAndLinkAndVideo( singlePost ), |
| 2451 | videoSource = null; |
| 2452 | if( self.hasOwnNestedProperty( videoInfo, 'type' ) ){ |
| 2453 | switch (videoInfo.type) { |
| 2454 | case 'embed': |
| 2455 | videoSource = self.hasOwnNestedProperty(videoInfo, 'url') ? videoInfo.url : null; |
| 2456 | break; |
| 2457 | case 'video': |
| 2458 | videoSource = self.hasOwnNestedProperty(videoInfo, 'args.unshimmedUrl') ? 'https://www.facebook.com/v2.3/plugins/video.php?href=' + videoInfo.args.unshimmedUrl : null; |
| 2459 | break; |
| 2460 | } |
| 2461 | } |
| 2462 | return videoSource; |
| 2463 | }, |
| 2464 | |
| 2465 | |
| 2466 | |
| 2467 | /** |
| 2468 | * Print Album Attachment Number |
| 2469 | * |
| 2470 | * @since 4.0 |
| 2471 | */ |
| 2472 | printAlbumImageNumberOverlay : function(subAttachmentsArray){ |
| 2473 | return '+' + (subAttachmentsArray.length - 3).toString(); |
| 2474 | }, |
| 2475 | |
| 2476 | /** |
| 2477 | * Print Element Overlay |
| 2478 | * |
| 2479 | * @since 4.0 |
| 2480 | */ |
| 2481 | getPostElementOverlay : function( singlePost ){ |
| 2482 | var self = this, |
| 2483 | postType = self.getPostTypeTimeline(singlePost), |
| 2484 | activeImage = null, |
| 2485 | videoSource = null, |
| 2486 | domBody = document.getElementsByTagName("body")[0]; |
| 2487 | /* |
| 2488 | videos |
| 2489 | links |
| 2490 | photos |
| 2491 | albums |
| 2492 | events |
| 2493 | */ |
| 2494 | switch (postType) { |
| 2495 | case 'photos': |
| 2496 | activeImage = self.processPostImageSrc(singlePost); |
| 2497 | break; |
| 2498 | case 'albums': |
| 2499 | activeImage = self.processPostImageSrc(singlePost); |
| 2500 | break; |
| 2501 | case 'events': |
| 2502 | activeImage = self.processPostImageSrc(singlePost); |
| 2503 | break; |
| 2504 | case 'videos' : |
| 2505 | postType = 'videos'; |
| 2506 | videoSource = self.processPostVideoSrc(singlePost); |
| 2507 | break; |
| 2508 | } |
| 2509 | if(self.customizerFeedData.settings.feedtype == 'videos'){ |
| 2510 | postType = 'embed_videos'; |
| 2511 | videoSource = singlePost.embed_html; |
| 2512 | } |
| 2513 | |
| 2514 | self.lightBox = { |
| 2515 | visibility : 'shown', |
| 2516 | type : postType, |
| 2517 | post : singlePost, |
| 2518 | activeImage : activeImage, |
| 2519 | albumIndex : 0, |
| 2520 | videoSource : videoSource |
| 2521 | }; |
| 2522 | |
| 2523 | document.body.scrollTop = 0; |
| 2524 | document.documentElement.scrollTop = 0; |
| 2525 | domBody.classList.add("no-overflow"); |
| 2526 | cffBuilder.$forceUpdate(); |
| 2527 | |
| 2528 | }, |
| 2529 | |
| 2530 | |
| 2531 | /** |
| 2532 | * Print Element Overlay |
| 2533 | * |
| 2534 | * @since 4.0 |
| 2535 | */ |
| 2536 | hideLightBox : function(){ |
| 2537 | var self = this, |
| 2538 | domBody = document.getElementsByTagName("body")[0]; |
| 2539 | domBody.classList.remove("no-overflow"); |
| 2540 | self.lightBox = { |
| 2541 | visibility : 'hidden', |
| 2542 | type : null, |
| 2543 | post : null, |
| 2544 | activeImage : null, |
| 2545 | albumIndex : 0, |
| 2546 | videoSource : null |
| 2547 | }; |
| 2548 | self.dummyLightBoxData.visibility = 'hidden'; |
| 2549 | cffBuilder.$forceUpdate(); |
| 2550 | }, |
| 2551 | |
| 2552 | /** |
| 2553 | * Switch Album Image onLick |
| 2554 | * |
| 2555 | * @since 4.0 |
| 2556 | */ |
| 2557 | switchLightboxAlbumImage : function(imageSource, imageIndex){ |
| 2558 | var self = this; |
| 2559 | self.lightBox.activeImage = imageSource; |
| 2560 | self.lightBox.albumIndex = imageIndex; |
| 2561 | cffBuilder.$forceUpdate(); |
| 2562 | }, |
| 2563 | |
| 2564 | /** |
| 2565 | * Navigate Album Image |
| 2566 | * Next / Previous |
| 2567 | * @since 4.0 |
| 2568 | */ |
| 2569 | navigateLightboxAlbumImage : function(navType, images){ |
| 2570 | var self = this, |
| 2571 | activeIndex = (navType == 'prev') ? ( self.lightBox.albumIndex === 0 ? images.length - 1 : self.lightBox.albumIndex - 1 ) : (self.lightBox.albumIndex === images.length - 1 ? 0 : self.lightBox.albumIndex + 1 ); |
| 2572 | self.lightBox.albumIndex = activeIndex; |
| 2573 | self.lightBox.activeImage = images[activeIndex].media.image.src; |
| 2574 | cffBuilder.$forceUpdate(); |
| 2575 | }, |
| 2576 | |
| 2577 | /** |
| 2578 | * Print Post Text |
| 2579 | * |
| 2580 | * @since 4.0 |
| 2581 | * |
| 2582 | * @return String |
| 2583 | */ |
| 2584 | printPostText : function( post, fullText = false ){ |
| 2585 | var self = this, |
| 2586 | postText = post.message ? post.message : (post.description ? post.description : ''), |
| 2587 | postText = ( !self.checkNotEmpty(postText) && self.getPostTypeTimeline(post) == 'links' && self.hasOwnNestedProperty( self.processIframeAndLinkAndVideo( post ), 'args.title' ) ) ? |
| 2588 | self.processIframeAndLinkAndVideo( post ).args.title : postText, |
| 2589 | |
| 2590 | //postVideoEmbed = self.processIframeAndLink( post, postText ), |
| 2591 | postText = (!fullText && postText != null) ? postText.substring(0, self.customizerFeedData.settings.textlength) : postText, |
| 2592 | postTags = post.message_tags ? post.message_tags : null, |
| 2593 | postText = ( !self.valueIsEnabled(self.customizerFeedData.settings.textlink) ) ? self.processPostTags( self.processPostUrls( self.processNewLine( postText ) ), postTags ) : '<a href="https://www.facebook.com/'+post.id+'" target="_blank">' + postText + '</a>'; |
| 2594 | return postText; |
| 2595 | }, |
| 2596 | |
| 2597 | /** |
| 2598 | * Return Tags Links for Post |
| 2599 | * |
| 2600 | * @since 4.0 |
| 2601 | * |
| 2602 | * @return String |
| 2603 | */ |
| 2604 | processPostTags : function( postText, postTags ){ |
| 2605 | if(postTags !== null){ |
| 2606 | postTags.forEach( function( singleTag ) { |
| 2607 | var regEx = new RegExp(singleTag.name, "ig"); |
| 2608 | postText = postText.replace(regEx, '<a href="https://facebook.com/' + singleTag.id + '" target="_blank" rel="nofollow">' + singleTag.name + '</a>'); |
| 2609 | }); |
| 2610 | } |
| 2611 | return postText; |
| 2612 | }, |
| 2613 | |
| 2614 | /** |
| 2615 | * Return Tags Links for Post |
| 2616 | * |
| 2617 | * @since 4.0 |
| 2618 | * |
| 2619 | * @return String |
| 2620 | */ |
| 2621 | processPostUrls: function( postText ){ |
| 2622 | var replacedText, |
| 2623 | httpPattern, |
| 2624 | wwwPattern, |
| 2625 | mailtoPattern; |
| 2626 | httpPattern = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim; |
| 2627 | replacedText = postText.replace(httpPattern, '<a href="$1" target="_blank">$1</a>'); |
| 2628 | |
| 2629 | wwwPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim; |
| 2630 | replacedText = replacedText.replace(wwwPattern, '$1<a href="http://$2" target="_blank">$2</a>'); |
| 2631 | |
| 2632 | mailtoPattern = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim; |
| 2633 | replacedText = replacedText.replace(mailtoPattern, '<a href="mailto:$1">$1</a>'); |
| 2634 | |
| 2635 | return replacedText |
| 2636 | }, |
| 2637 | |
| 2638 | /** |
| 2639 | * Process New Line Break |
| 2640 | * |
| 2641 | * @since 4.0 |
| 2642 | * |
| 2643 | * @return String |
| 2644 | */ |
| 2645 | processNewLine : function( postText ){ |
| 2646 | return postText.replace(/(?:\r\n|\r|\n)/g, '<br />'); |
| 2647 | }, |
| 2648 | |
| 2649 | /** |
| 2650 | * Create iFrame & External Link & Video |
| 2651 | * |
| 2652 | * @since 4.0 |
| 2653 | * |
| 2654 | * @return array |
| 2655 | */ |
| 2656 | processIframeAndLinkAndVideo : function( post ){ |
| 2657 | var self = this, |
| 2658 | postText = post.message ? post.message : (post.description ? post.description : ''), |
| 2659 | videoOrLink = self.processVideoAndLink( post ); |
| 2660 | |
| 2661 | if( videoOrLink != false && self.hasOwnNestedProperty(videoOrLink, 'args.unshimmedUrl') && videoOrLink.args.unshimmedUrl != null){ |
| 2662 | //Youtube Process |
| 2663 | var regExpYoutube = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/, |
| 2664 | matchYoutube = videoOrLink.args.unshimmedUrl.match(regExpYoutube), |
| 2665 | youtubeID = (matchYoutube && matchYoutube[2].split(' ')[0].length === 11) ? matchYoutube[2].split(' ')[0] : null; |
| 2666 | |
| 2667 | //Vimeo Process |
| 2668 | var regExpVimeo = /vimeo.*\/(\d+)/i , |
| 2669 | matchVimeo = regExpVimeo.exec( videoOrLink.args.unshimmedUrl ), |
| 2670 | vimeoID = (matchVimeo && matchVimeo[1]) ? matchVimeo[1] : null; |
| 2671 | |
| 2672 | //Soundcloud Process |
| 2673 | const regExpSoundCloud = /^.*(?:(https?):\/\/)?(?:(?:www|m)\.)?(soundcloud\.com|snd\.sc)\/(.*).*/, |
| 2674 | matchSoundCloud = videoOrLink.args.unshimmedUrl.match(regExpSoundCloud), |
| 2675 | soundCloudUrl = (matchSoundCloud && matchSoundCloud[2]) ? matchSoundCloud[3].split(' ')[0] : null; |
| 2676 | |
| 2677 | //Spotify Process |
| 2678 | var regExpSpotify = /^.*((open|play)\.spotify\.com\/)([^#&?]*).*/, |
| 2679 | matchSpotify = videoOrLink.args.unshimmedUrl.match(regExpSpotify); |
| 2680 | spotifyUrl = (matchSpotify && matchSpotify[2]) ? matchSpotify[3].split(' ')[0] : null; |
| 2681 | |
| 2682 | if(youtubeID != null){ |
| 2683 | return { |
| 2684 | 'type' : 'embed', |
| 2685 | 'url' : 'https://www.youtube.com/embed/' + youtubeID, |
| 2686 | 'site' : 'video' |
| 2687 | }; |
| 2688 | }else if( vimeoID != null ){ |
| 2689 | return { |
| 2690 | 'type' : 'embed', |
| 2691 | 'url' : '//player.vimeo.com/video/'+vimeoID, |
| 2692 | 'site' : 'video' |
| 2693 | }; |
| 2694 | }else if(soundCloudUrl != null){ |
| 2695 | return { |
| 2696 | 'type' : 'embed', |
| 2697 | 'url' : 'https://w.soundcloud.com/player/?url=https://soundcloud.com/'+soundCloudUrl+'&auto_play=false&hide_related=true&show_comments=false&show_user=true&show_reposts=false&visual=false', |
| 2698 | 'site' : 'soundcloud' |
| 2699 | }; |
| 2700 | }else if( spotifyUrl != null){ |
| 2701 | return { |
| 2702 | 'type' : 'embed', |
| 2703 | 'url' : 'https://open.spotify.com/embed/'+spotifyUrl, |
| 2704 | 'site' : 'spotify' |
| 2705 | }; |
| 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | return videoOrLink; |
| 2710 | }, |
| 2711 | |
| 2712 | |
| 2713 | /** |
| 2714 | * Process Video & External Link |
| 2715 | * |
| 2716 | * @since 4.0 |
| 2717 | * |
| 2718 | * @return array |
| 2719 | */ |
| 2720 | processVideoAndLink : function( post ){ |
| 2721 | var self = this; |
| 2722 | if( self.hasOwnNestedProperty(post, 'attachments.data') && post.attachments.data[0] ){ |
| 2723 | if( post.attachments.data[0] && ( post.attachments.data[0].media_type === 'link' || post.attachments.data[0].media_type === 'video' ) ){ |
| 2724 | var dataObject = post.attachments.data[0]; |
| 2725 | switch (dataObject.media_type) { |
| 2726 | case 'video': |
| 2727 | var domain = (self.hasOwnNestedProperty( dataObject, 'unshimmed_url')) ? (new URL(dataObject.unshimmed_url)).hostname : null; |
| 2728 | return { |
| 2729 | 'type' : 'video', |
| 2730 | 'args' : { |
| 2731 | 'title' : self.hasOwnNestedProperty( dataObject, 'title' ) ? dataObject.title : null, |
| 2732 | 'description' : self.hasOwnNestedProperty( dataObject, 'description') ? dataObject.description : null, |
| 2733 | 'source' : self.hasOwnNestedProperty( dataObject, 'media.source') ? dataObject.media.source : null, |
| 2734 | 'poster' : self.hasOwnNestedProperty( dataObject, 'media.image.src') ? dataObject.media.image.src : null, |
| 2735 | 'unshimmedUrl' : self.hasOwnNestedProperty( dataObject, 'unshimmed_url') ? dataObject.unshimmed_url : null, |
| 2736 | 'domain' : domain |
| 2737 | } |
| 2738 | }; |
| 2739 | case 'link': |
| 2740 | var domain = (self.hasOwnNestedProperty( dataObject, 'unshimmed_url')) ? (new URL(dataObject.unshimmed_url)).hostname : null; |
| 2741 | return { |
| 2742 | 'type' : 'link', |
| 2743 | 'args' : { |
| 2744 | 'title' : self.hasOwnNestedProperty( dataObject, 'title' ) ? dataObject.title : null, |
| 2745 | 'description' : self.hasOwnNestedProperty( dataObject, 'description') ? dataObject.description : null, |
| 2746 | 'poster' : self.hasOwnNestedProperty( post, 'full_picture') ? post.full_picture : null, |
| 2747 | 'unshimmedUrl' : self.hasOwnNestedProperty( dataObject, 'unshimmed_url') ? dataObject.unshimmed_url : null, |
| 2748 | 'domain' : domain |
| 2749 | } |
| 2750 | }; |
| 2751 | } |
| 2752 | } |
| 2753 | }else if(post.embed_html){ |
| 2754 | return { |
| 2755 | 'type' : 'video', |
| 2756 | 'args' : { |
| 2757 | 'title' : self.hasOwnNestedProperty( post, 'title' ) ? post.title : null, |
| 2758 | 'source' : self.hasOwnNestedProperty( post, 'source') ? post.source : null, |
| 2759 | 'poster' : self.hasOwnNestedProperty( post, 'format') ? post.format[post.format.length - 1].picture : null, |
| 2760 | 'unshimmedUrl' : self.hasOwnNestedProperty( post, 'from.id') && self.hasOwnNestedProperty( post, 'id') ? 'https://www.facebook.com/'+post.from.id+'/videos/'+ post.id +'/' : null |
| 2761 | } |
| 2762 | }; |
| 2763 | } |
| 2764 | |
| 2765 | return false; |
| 2766 | }, |
| 2767 | |
| 2768 | /** |
| 2769 | * Get Post Type |
| 2770 | * |
| 2771 | * @since 4.0 |
| 2772 | * |
| 2773 | * @return string |
| 2774 | */ |
| 2775 | getPostTypeTimeline : function( post ){ |
| 2776 | var self = this, |
| 2777 | postType = (post.message) ? 'statuses' : (post.description ? 'statuses' : 'empty'); |
| 2778 | if( self.hasOwnNestedProperty(post, 'attachments.data') && post.attachments.data[0] ){ |
| 2779 | if( post.attachments.data[0].media_type ){ |
| 2780 | switch (post.attachments.data[0].media_type) { |
| 2781 | case 'video': |
| 2782 | postType = 'videos'; |
| 2783 | break; |
| 2784 | case 'link': |
| 2785 | postType = 'links'; |
| 2786 | break; |
| 2787 | case 'photo': |
| 2788 | postType = 'photos'; |
| 2789 | break; |
| 2790 | case 'album': |
| 2791 | postType = 'albums'; |
| 2792 | break; |
| 2793 | case 'event': |
| 2794 | postType = 'events'; |
| 2795 | break; |
| 2796 | } |
| 2797 | } |
| 2798 | } |
| 2799 | return postType; |
| 2800 | }, |
| 2801 | |
| 2802 | /** |
| 2803 | * Show or Hide Post Depending on settings |
| 2804 | * |
| 2805 | * @since 4.0 |
| 2806 | * |
| 2807 | * @return bool |
| 2808 | */ |
| 2809 | checkShowPost : function( post ){ |
| 2810 | var self = this, |
| 2811 | feedType = self.customizerFeedData.settings.feedtype, |
| 2812 | type = self.customizerFeedData.settings.type, |
| 2813 | postType = self.getPostTypeTimeline( post ), |
| 2814 | showPost = true; |
| 2815 | //'links,events,videos,photos,albums,statuses', |
| 2816 | if(feedType == 'timeline'){ |
| 2817 | showPost = type.includes( postType ); |
| 2818 | } |
| 2819 | return showPost; |
| 2820 | }, |
| 2821 | |
| 2822 | |
| 2823 | /** |
| 2824 | * Process Photos Feedtype => Single Image Source |
| 2825 | * |
| 2826 | * @since 4.0 |
| 2827 | * |
| 2828 | * @return string |
| 2829 | */ |
| 2830 | processPhotoSource : function( post ){ |
| 2831 | var pictureSourceFallBack = 'https://graph.facebook.com/'+ post.id +'/picture?type=normal&width=9999&height=9999&access_token=' + (this.customizerFeedData.settings.sources[0] != undefined) ? this.customizerFeedData.settings.sources[0].access_token : '', |
| 2832 | pictureSrc = ( post.images && post.images[0] && post.images[0].source) ? post.images[0].source : pictureSourceFallBack; |
| 2833 | if(post.images){ |
| 2834 | var currentWidth = 0; |
| 2835 | post.images.forEach( function(singleImage) { |
| 2836 | if( singleImage.width > 500 && singleImage.width < 900 && currentWidth < singleImage.width){ |
| 2837 | pictureSrc = singleImage.source; |
| 2838 | currentWidth = singleImage.width; |
| 2839 | } |
| 2840 | }); |
| 2841 | } |
| 2842 | return pictureSrc; |
| 2843 | }, |
| 2844 | |
| 2845 | |
| 2846 | /** |
| 2847 | * Process Video Source Image |
| 2848 | * Videos Feed Type |
| 2849 | * @since 4.0 |
| 2850 | * |
| 2851 | * @return string |
| 2852 | */ |
| 2853 | processVideosFeedImage : function( videoPost ){ |
| 2854 | var self = this, |
| 2855 | pictureSrc = ''; |
| 2856 | if( self.hasOwnNestedProperty(videoPost, 'format') && Array.isArray(videoPost.format) ){ |
| 2857 | pictureSrc = videoPost.format[videoPost.format.length - 1].picture; |
| 2858 | } |
| 2859 | return pictureSrc; |
| 2860 | }, |
| 2861 | |
| 2862 | |
| 2863 | /** |
| 2864 | * Print Expand Text |
| 2865 | * |
| 2866 | * @since 4.0 |
| 2867 | * |
| 2868 | * @return String |
| 2869 | */ |
| 2870 | printExpandText : function( postID ){ |
| 2871 | var self = this; |
| 2872 | return self.expandedPostText.includes(postID) ? self.translatedText.seeLessText : self.translatedText.seeMoreText; |
| 2873 | }, |
| 2874 | |
| 2875 | /** |
| 2876 | * Print Expand Text |
| 2877 | * |
| 2878 | * @since 4.0 |
| 2879 | */ |
| 2880 | expandPostText : function( postID ){ |
| 2881 | var self = this; |
| 2882 | if(self.expandedPostText.includes(postID)){ |
| 2883 | self.expandedPostText.splice(self.expandedPostText.indexOf(postID), 1); |
| 2884 | }else{ |
| 2885 | self.expandedPostText.push(postID); |
| 2886 | } |
| 2887 | setTimeout(function(){ |
| 2888 | self.generateMasonryGridHeight('update'); |
| 2889 | }, 100) |
| 2890 | cffBuilder.$forceUpdate(); |
| 2891 | |
| 2892 | }, |
| 2893 | |
| 2894 | /** |
| 2895 | * Return Likebox Iframe |
| 2896 | * |
| 2897 | * @since 4.0 |
| 2898 | * |
| 2899 | * @return String |
| 2900 | */ |
| 2901 | displayLikeBoxIframe : function(){ |
| 2902 | var self = this, |
| 2903 | pageID = self.hasOwnNestedProperty(self.customizerFeedData, 'header.id') ? self.customizerFeedData.header.id : null, |
| 2904 | settings = self.customizerFeedData.settings, |
| 2905 | likeBoxWidth = self.valueIsEnabled(settings.likeboxcustomwidth) && self.checkNotEmpty(settings.likeboxcustomwidth) ? settings.likeboxwidth : 300, |
| 2906 | iframeURL = 'https://www.facebook.com/'+pageID+'/tabs&width=' + likeBoxWidth + |
| 2907 | '&small_header=' + self.valueIsEnabled(settings.likeboxsmallheader) + |
| 2908 | '&adapt_container_width=true' + |
| 2909 | '&hide_cover=' + !self.valueIsEnabled(settings.likeboxcover) + |
| 2910 | '&hide_cta=' + self.valueIsEnabled(settings.likeboxhidebtn) + |
| 2911 | '&show_facepile=' + self.valueIsEnabled(settings.likeboxfaces) + |
| 2912 | '&locale=' + settings.locale; |
| 2913 | return 'https://www.facebook.com/plugins/page.php?href='+iframeURL; |
| 2914 | }, |
| 2915 | |
| 2916 | /** |
| 2917 | * Single Post & Feature Post Holder Areas |
| 2918 | * |
| 2919 | * @since 4.0 |
| 2920 | */ |
| 2921 | singleHolderParams : function(){ |
| 2922 | var self = this, |
| 2923 | postsLength = self.customizerFeedData.posts ? self.customizerFeedData.posts.length : 0; |
| 2924 | holderIcon = '', |
| 2925 | holderHeading = '', |
| 2926 | holderText = '', |
| 2927 | settings = self.customizerFeedData.settings; |
| 2928 | |
| 2929 | if( settings.feedtype == 'singlealbum' ){ |
| 2930 | holderIcon = self.checkNotEmpty(settings.album) && postsLength == 0 ? self.svgIcons['issueSinglePreview'] : self.svgIcons['albumsPreview']; |
| 2931 | holderHeading = self.checkNotEmpty(settings.album) && postsLength == 0 ? self.addFeaturedAlbumScreen.couldNotFetch : self.addFeaturedAlbumScreen.previewHeading; |
| 2932 | holderText = self.checkNotEmpty(settings.album) && postsLength == 0 ? self.addFeaturedAlbumScreen.unablePreview : self.addFeaturedAlbumScreen.previewText; |
| 2933 | } |
| 2934 | if( settings.feedtype == 'featuredpost' ){ |
| 2935 | holderIcon = self.checkNotEmpty(settings.featuredpost) && postsLength == 0 ? self.svgIcons['issueSinglePreview'] : self.svgIcons['featuredPostPreview']; |
| 2936 | holderHeading = self.checkNotEmpty(settings.featuredpost) && postsLength == 0 ? self.addFeaturedPostScreen.couldNotFetch : self.addFeaturedPostScreen.previewHeading; |
| 2937 | holderText = self.checkNotEmpty(settings.featuredpost) && postsLength == 0 ? self.addFeaturedPostScreen.unablePreview : self.addFeaturedPostScreen.previewText; |
| 2938 | } |
| 2939 | |
| 2940 | return { |
| 2941 | icon : holderIcon, |
| 2942 | heading : holderHeading, |
| 2943 | text : holderText |
| 2944 | }; |
| 2945 | |
| 2946 | }, |
| 2947 | |
| 2948 | /** |
| 2949 | * Toggle Social Share Tooltip |
| 2950 | * |
| 2951 | * @since 4.0 |
| 2952 | */ |
| 2953 | toggleSocialShareTooltip : function( postID ){ |
| 2954 | var self = this; |
| 2955 | self.showedSocialShareTooltip = (self.showedSocialShareTooltip === postID) ? null : postID; |
| 2956 | cffBuilder.$forceUpdate(); |
| 2957 | }, |
| 2958 | |
| 2959 | |
| 2960 | /** |
| 2961 | * Open Dialog Box |
| 2962 | * |
| 2963 | * @since 4.0 |
| 2964 | */ |
| 2965 | openDialogBox : function(type, args = []){ |
| 2966 | var self = this, |
| 2967 | heading = self.dialogBoxPopupScreen[type].heading, |
| 2968 | description = self.dialogBoxPopupScreen[type].description; |
| 2969 | switch (type) { |
| 2970 | case "deleteSourceCustomizer": |
| 2971 | self.sourceToDelete = args; |
| 2972 | heading = heading.replace("#", self.sourceToDelete.username); |
| 2973 | break; |
| 2974 | case "deleteSingleFeed": |
| 2975 | self.feedToDelete = args; |
| 2976 | heading = heading.replace("#", self.feedToDelete.feed_name); |
| 2977 | break; |
| 2978 | case "deleteSource": |
| 2979 | self.sourceToDelete = args; |
| 2980 | heading = heading.replace("#", self.sourceToDelete.username); |
| 2981 | break; |
| 2982 | |
| 2983 | } |
| 2984 | self.dialogBox = { |
| 2985 | active : true, |
| 2986 | type : type, |
| 2987 | heading : heading, |
| 2988 | description : description |
| 2989 | }; |
| 2990 | window.event.stopPropagation(); |
| 2991 | }, |
| 2992 | |
| 2993 | |
| 2994 | /** |
| 2995 | * Confirm Dialog Box Actions |
| 2996 | * |
| 2997 | * @since 4.0 |
| 2998 | */ |
| 2999 | confirmDialogAction : function(){ |
| 3000 | var self = this; |
| 3001 | switch (self.dialogBox.type) { |
| 3002 | case 'deleteSourceCustomizer': |
| 3003 | self.selectSourceCustomizer(self.sourceToDelete, true); |
| 3004 | self.customizerControlAjaxAction('feedFlyPreview'); |
| 3005 | break; |
| 3006 | case 'deleteSingleFeed': |
| 3007 | self.feedActionDelete([self.feedToDelete.id]); |
| 3008 | break; |
| 3009 | case 'deleteMultipleFeeds': |
| 3010 | self.feedActionDelete(self.feedsSelected); |
| 3011 | break; |
| 3012 | case 'backAllToFeed': |
| 3013 | window.location = self.builderUrl; |
| 3014 | break; |
| 3015 | case 'deleteSource': |
| 3016 | self.deleteSource(self.sourceToDelete); |
| 3017 | break; |
| 3018 | } |
| 3019 | }, |
| 3020 | |
| 3021 | /* |
| 3022 | closeConfirmDialog : function(){ |
| 3023 | this.sourceToDelete = {}; |
| 3024 | this.feedToDelete = {}; |
| 3025 | this.dialogBox = { |
| 3026 | active : false, |
| 3027 | type : null, |
| 3028 | heading : null, |
| 3029 | description : null |
| 3030 | }; |
| 3031 | }, |
| 3032 | */ |
| 3033 | |
| 3034 | /** |
| 3035 | * Show Tooltip on Hover |
| 3036 | * |
| 3037 | * @since 4.0 |
| 3038 | */ |
| 3039 | toggleElementTooltip : function(tooltipText, type, align = 'center'){ |
| 3040 | var self = this, |
| 3041 | target = window.event.currentTarget, |
| 3042 | tooltip = (target != undefined && target != null) ? document.querySelector('.sb-control-elem-tltp-content') : null; |
| 3043 | if(tooltip != null && type == 'show'){ |
| 3044 | self.tooltip.text = tooltipText; |
| 3045 | var position = target.getBoundingClientRect(), |
| 3046 | left = position.left + 7, |
| 3047 | top = position.top - 15; |
| 3048 | tooltip.style.left = left + 'px'; |
| 3049 | tooltip.style.top = top + 'px'; |
| 3050 | tooltip.style.textAlign = align; |
| 3051 | self.tooltip.hover = true; |
| 3052 | } |
| 3053 | if(type == 'hide'){ |
| 3054 | setTimeout(function(){ |
| 3055 | if(self.tooltip.hoverType != 'inside'){ |
| 3056 | self.tooltip.hover = false; |
| 3057 | } |
| 3058 | }, 200) |
| 3059 | } |
| 3060 | }, |
| 3061 | |
| 3062 | /** |
| 3063 | * Hover Tooltip |
| 3064 | * |
| 3065 | * @since 4.0 |
| 3066 | */ |
| 3067 | hoverTooltip : function(type, hoverType){ |
| 3068 | this.tooltip.hover = type; |
| 3069 | this.tooltip.hoverType = hoverType; |
| 3070 | }, |
| 3071 | |
| 3072 | /** |
| 3073 | * Loading Bar & Notification |
| 3074 | * |
| 3075 | * @since 4.0 |
| 3076 | */ |
| 3077 | processNotification : function( notificationType ){ |
| 3078 | var self = this, |
| 3079 | notification = self.genericText.notification[ notificationType ]; |
| 3080 | self.loadingBar = false; |
| 3081 | self.notificationElement = { |
| 3082 | type : notification.type, |
| 3083 | text : notification.text, |
| 3084 | shown : "shown" |
| 3085 | }; |
| 3086 | setTimeout(function(){ |
| 3087 | self.notificationElement.shown = "hidden"; |
| 3088 | }, 5000); |
| 3089 | }, |
| 3090 | |
| 3091 | ctaToggleFeatures: function() { |
| 3092 | this.freeCtaShowFeatures = !this.freeCtaShowFeatures; |
| 3093 | }, |
| 3094 | |
| 3095 | /** |
| 3096 | * Next Wizard Step |
| 3097 | * |
| 3098 | * @since 6.3 |
| 3099 | */ |
| 3100 | nextWizardStep : function( action = false ){ |
| 3101 | const self = this; |
| 3102 | if( action === 'submit' ){ |
| 3103 | self.submitWizardData() |
| 3104 | } |
| 3105 | |
| 3106 | if( self.currentOnboardingWizardStep < self.onboardingWizardContent.steps.length ){ |
| 3107 | self.currentOnboardingWizardStep +=1; |
| 3108 | self.recordUsageEvent( 'setup_wizard_step_completed' ); |
| 3109 | } |
| 3110 | }, |
| 3111 | |
| 3112 | // |
| 3113 | submitWizardData : function(){ |
| 3114 | const self = this, |
| 3115 | wizardData = { |
| 3116 | action: 'cff_feed_saver_manager_process_wizard', |
| 3117 | data: JSON.stringify(self.currentOnboardingWizardActiveSettings) |
| 3118 | }; |
| 3119 | |
| 3120 | self.ajaxPost(wizardData, function (_ref) { |
| 3121 | }); |
| 3122 | |
| 3123 | if( self.sourcesList.length > 0 ){ |
| 3124 | self.onboardingSuccessMessagesDisplay.push( self.onboardingSuccessMessages.connectAccount ); |
| 3125 | } |
| 3126 | self.onboardingSuccessMessagesDisplay.push( self.onboardingSuccessMessages.setupFeatures ); |
| 3127 | |
| 3128 | const settingsValues = Object.values(self.currentOnboardingWizardActiveSettings), |
| 3129 | settingsKeys = Object.keys(self.currentOnboardingWizardActiveSettings); |
| 3130 | settingsValues.map( ( st, stInd ) => { |
| 3131 | if( st?.plugins && st?.plugins === 'smash' ){ |
| 3132 | self.onboardingSuccessMessagesDisplay.push( self.onboardingSuccessMessages.feedPlugins.replace('#', settingsKeys[stInd]) ); |
| 3133 | }else if( st?.id === 'reviews' ){ |
| 3134 | self.onboardingSuccessMessagesDisplay.push( 'Reviews ' + self.genericText.installed ); |
| 3135 | }else if( st?.id === 'wpchat' ){ |
| 3136 | self.onboardingSuccessMessagesDisplay.push( 'WPChat ' + self.genericText.installed ); |
| 3137 | }else if( st?.type === 'install_plugins' ){ |
| 3138 | self.onboardingSuccessMessagesDisplay.push( '<span class="sb-onboarding-wizard-succes-name"> ' + st?.pluginName + '</span> ' + self.genericText.installed ); |
| 3139 | } |
| 3140 | } ) |
| 3141 | setTimeout(function(){ |
| 3142 | self.onboardingWizardDone = 'true'; |
| 3143 | self.recordUsageEvent( 'setup_wizard_completed' ); |
| 3144 | }, 100) |
| 3145 | cffBuilder.$forceUpdate(); |
| 3146 | }, |
| 3147 | |
| 3148 | /** |
| 3149 | * Previous Wizard Step |
| 3150 | * |
| 3151 | * @since 6.3 |
| 3152 | */ |
| 3153 | previousWizardStep : function(){ |
| 3154 | const self = this; |
| 3155 | if( self.currentOnboardingWizardStep > 0 ){ |
| 3156 | self.currentOnboardingWizardStep -=1; |
| 3157 | } |
| 3158 | }, |
| 3159 | |
| 3160 | /** |
| 3161 | * Delete Source Ajax |
| 3162 | * |
| 3163 | * @since 4.0 |
| 3164 | */ |
| 3165 | deleteSource: function (sourceToDelete) { |
| 3166 | var self = this, |
| 3167 | deleteSourceData = { |
| 3168 | action: 'cff_feed_saver_manager_delete_source', |
| 3169 | source_id: sourceToDelete.id, |
| 3170 | username : sourceToDelete.username, |
| 3171 | nonce : self.admin_nonce |
| 3172 | }; |
| 3173 | self.ajaxPost(deleteSourceData, function (_ref) { |
| 3174 | var data = _ref.data; |
| 3175 | self.sourcesList = data; |
| 3176 | }); |
| 3177 | }, |
| 3178 | |
| 3179 | //Get Source Avatarr |
| 3180 | getSourceListAvatar: function ( source ) { |
| 3181 | return typeof source.avatar_url !== 'undefined' && source.account_type === 'group' ? source.avatar_url : 'https://graph.facebook.com/'+source.account_id+'/picture' |
| 3182 | }, |
| 3183 | |
| 3184 | //Switcher Onboarding Wizard Click |
| 3185 | switcherOnboardingWizardClick : function ( elem ) { |
| 3186 | const self = this; |
| 3187 | if( elem?.uncheck === true ){ |
| 3188 | return false; |
| 3189 | } |
| 3190 | |
| 3191 | if(self.currentOnboardingWizardActiveSettings[elem?.data?.id] !== undefined){ |
| 3192 | delete self.currentOnboardingWizardActiveSettings[elem.data.id]; |
| 3193 | }else{ |
| 3194 | self.currentOnboardingWizardActiveSettings[elem.data.id] = elem.data; |
| 3195 | } |
| 3196 | cffBuilder.$forceUpdate(); |
| 3197 | }, |
| 3198 | |
| 3199 | //Select Option Wizard change |
| 3200 | selectOptionOnboardingWizardChange : function ( elem ) { |
| 3201 | const self = this, |
| 3202 | elemValue = event.target.value, |
| 3203 | elemData = { |
| 3204 | ...elem.data, |
| 3205 | value : elemValue |
| 3206 | }; |
| 3207 | self.currentOnboardingWizardActiveSettings[elem.data.id] = elemData; |
| 3208 | console.log(elemData); |
| 3209 | cffBuilder.$forceUpdate(); |
| 3210 | }, |
| 3211 | |
| 3212 | switcherOnboardingWizardCheckActive : function ( elem ) { |
| 3213 | const self = this; |
| 3214 | if( elem?.uncheck === true ){ |
| 3215 | return elem?.active; |
| 3216 | }else{ |
| 3217 | return self.currentOnboardingWizardActiveSettings[elem?.data?.id] !== undefined ? 'true' : 'false' |
| 3218 | } |
| 3219 | |
| 3220 | }, |
| 3221 | |
| 3222 | checkActiveOnboardingWizardSettings : function (){ |
| 3223 | const self = this, |
| 3224 | currentStepContentSteps = self.onboardingWizardContent.steps; |
| 3225 | |
| 3226 | currentStepContentSteps.map( (step, stepId) => { |
| 3227 | let = currentStepContentValues = Object.values(step), |
| 3228 | currentStepContentKeys = Object.keys(step); |
| 3229 | currentStepContentValues.map( (sec, secId) => { |
| 3230 | if( (self.onboardingWizardContent.saveSettings.includes(currentStepContentKeys[secId])) ){ |
| 3231 | currentStepContentValues[secId].forEach( elem => { |
| 3232 | if( elem.active === true && elem?.data){ |
| 3233 | self.currentOnboardingWizardActiveSettings[elem.data.id] = elem.data; |
| 3234 | } |
| 3235 | } ); |
| 3236 | } |
| 3237 | }); |
| 3238 | }); |
| 3239 | }, |
| 3240 | |
| 3241 | recordUsageEvent : function( eventName ) { |
| 3242 | if ( typeof window.cffSmashUsageRecordEvent === 'function' ) { |
| 3243 | window.cffSmashUsageRecordEvent( eventName ); |
| 3244 | } |
| 3245 | }, |
| 3246 | |
| 3247 | dismissOnboardingWizard : function(){ |
| 3248 | this.recordUsageEvent( 'setup_wizard_abandoned' ); |
| 3249 | const self = this, |
| 3250 | dismissWizardData = { |
| 3251 | action: 'cff_feed_saver_manager_dismiss_wizard' |
| 3252 | }; |
| 3253 | |
| 3254 | self.ajaxPost(dismissWizardData, function (_ref) { |
| 3255 | window.location = self.builderUrl; |
| 3256 | }); |
| 3257 | cffBuilder.$forceUpdate(); |
| 3258 | }, |
| 3259 | //One CLick Upgrade |
| 3260 | runOneClickUpgrade : function(){ |
| 3261 | const self = this, |
| 3262 | oneClickUpgradeData = { |
| 3263 | action: 'cff_maybe_upgrade_redirect', |
| 3264 | license_key: self.setupLicencekey, |
| 3265 | nonce : self.admin_nonce |
| 3266 | }; |
| 3267 | self.setupLicencekeyError = null |
| 3268 | if( self.checkNotEmpty( self.setupLicencekey ) ){ |
| 3269 | self.licenseLoading = true; |
| 3270 | self.ajaxPost(oneClickUpgradeData, function (_ref) { |
| 3271 | var data = _ref.data; |
| 3272 | if (data.success === false) { |
| 3273 | self.licenseLoading = false; |
| 3274 | if (typeof data.data !== 'undefined') { |
| 3275 | self.setupLicencekeyError = data.data.message |
| 3276 | } |
| 3277 | } |
| 3278 | if (data.success === true) { |
| 3279 | window.location.href = data.data.url |
| 3280 | } |
| 3281 | |
| 3282 | }); |
| 3283 | } |
| 3284 | |
| 3285 | }, |
| 3286 | |
| 3287 | //Source Ative |
| 3288 | isSourceSelectActive : function(source){ |
| 3289 | if(this.selectedSources.includes(source.account_id)){ |
| 3290 | return (this.selectedFeed == 'events' && (source.privilege == 'events' || source.account_type == 'group')) || (this.selectedFeed != 'events' && source.privilege != 'events'); |
| 3291 | } |
| 3292 | return false; |
| 3293 | }, |
| 3294 | |
| 3295 | //Source Ative |
| 3296 | isSourceSelectActivePopup : function(source){ |
| 3297 | if(this.selectedSources.includes(source.account_id)){ |
| 3298 | return (this.customizerFeedData.settings.feedtype == 'events' && source.privilege == 'events') || (this.customizerFeedData.settings.feedtype != 'events' && source.privilege != 'events'); |
| 3299 | } |
| 3300 | return false; |
| 3301 | }, |
| 3302 | checkTypeForGroupPopup : function(source){ |
| 3303 | return source.account_type === 'group' && this.customizerFeedData.settings.feedtype === 'photos'; |
| 3304 | }, |
| 3305 | |
| 3306 | } |
| 3307 | |
| 3308 | }); |
| 3309 | |
| 3310 | |
| 3311 |