about.js
2 weeks ago
admin-notifications.js
2 weeks ago
builders-preview-handler.js
2 weeks ago
callout.js
2 weeks ago
cff-admin-scripts.js
2 weeks ago
divi-handler.min.js
2 weeks ago
extensions.js
2 weeks ago
oembeds.js
2 weeks ago
settings.js
2 weeks ago
smash-usage-session.js
2 weeks ago
support.js
2 weeks ago
vue.min.js
2 weeks ago
oembeds.js
219 lines
| 1 | var oembeds_data = { |
| 2 | nonce: cff_oembeds.nonce, |
| 3 | genericText: cff_oembeds.genericText, |
| 4 | images: cff_oembeds.images, |
| 5 | modal: cff_oembeds.modal, |
| 6 | links: cff_oembeds.links, |
| 7 | supportPageUrl: cff_oembeds.supportPageUrl, |
| 8 | socialWallActivated: cff_oembeds.socialWallActivated, |
| 9 | socialWallLinks: cff_oembeds.socialWallLinks, |
| 10 | facebook: cff_oembeds.facebook, |
| 11 | instagram: cff_oembeds.instagram, |
| 12 | connectionURL: cff_oembeds.connectionURL, |
| 13 | isIntagramActivated: cff_oembeds.instagram.active, |
| 14 | instagramInstallBtnText: null, |
| 15 | fboEmbedLoader: false, |
| 16 | fboEmbedError: null, |
| 17 | instaoEmbedLoader: false, |
| 18 | openInstaInstaller: false, |
| 19 | loaderSVG: cff_oembeds.loaderSVG, |
| 20 | checkmarkSVG: cff_oembeds.checkmarkSVG, |
| 21 | installerStatus: null, |
| 22 | isSetupPage : false |
| 23 | } |
| 24 | |
| 25 | var cffoEmbeds = new Vue({ |
| 26 | el: "#cff-oembeds", |
| 27 | http: { |
| 28 | emulateJSON: true, |
| 29 | emulateHTTP: true |
| 30 | }, |
| 31 | data: oembeds_data, |
| 32 | methods: { |
| 33 | openInstallModal: function() { |
| 34 | this.openInstaInstaller = true |
| 35 | }, |
| 36 | closeModal: function() { |
| 37 | this.openInstaInstaller = false |
| 38 | }, |
| 39 | isoEmbedsEnabled: function() { |
| 40 | if ( this.facebook.doingOembeds && this.instagram.doingOembeds ) { |
| 41 | return true; |
| 42 | } |
| 43 | return; |
| 44 | }, |
| 45 | InstagramShouldInstallOrEnable: function() { |
| 46 | // if the plugin is activated and installed then just enable oEmbed |
| 47 | if( this.isIntagramActivated ) { |
| 48 | this.enableFboEmbed(); |
| 49 | return; |
| 50 | } |
| 51 | // if the plugin is not activated and installed then open the modal to install and activate the plugin |
| 52 | if( !this.isIntagramActivated ) { |
| 53 | this.openInstallModal(); |
| 54 | return; |
| 55 | } |
| 56 | }, |
| 57 | installInstagram: function() { |
| 58 | this.installerStatus = 'loading'; |
| 59 | let data = new FormData(); |
| 60 | data.append( 'action', cff_oembeds.instagram.installer.action ); |
| 61 | data.append( 'nonce', cff_oembeds.nonce ); |
| 62 | data.append( 'plugin', cff_oembeds.instagram.installer.plugin ); |
| 63 | data.append( 'type', 'plugin' ); |
| 64 | fetch(cff_oembeds.ajax_handler, { |
| 65 | method: "POST", |
| 66 | credentials: 'same-origin', |
| 67 | body: data |
| 68 | }) |
| 69 | .then(response => response.json()) |
| 70 | .then(data => { |
| 71 | if( data.success == false ) { |
| 72 | this.installerStatus = 'error' |
| 73 | } |
| 74 | if( data.success == true ) { |
| 75 | this.isIntagramActivated = true; |
| 76 | this.installerStatus = 'success' |
| 77 | } |
| 78 | this.instagramInstallBtnText = data.data.msg; |
| 79 | setTimeout(function() { |
| 80 | this.installerStatus = null; |
| 81 | }.bind(this), 3000); |
| 82 | return; |
| 83 | }); |
| 84 | }, |
| 85 | enableFboEmbed: function() { |
| 86 | this.fboEmbedLoader = true; |
| 87 | this.fboEmbedError = null; |
| 88 | |
| 89 | let oembedConnectUrl = this.connectionURL.connect, |
| 90 | appendURL = this.connectionURL.stateURL; |
| 91 | |
| 92 | const urlParams = { |
| 93 | 'cff_con' : this.connectionURL.cff_con, |
| 94 | 'state': "{'{url=" + appendURL + "}'}" |
| 95 | } |
| 96 | |
| 97 | let form = document.createElement('form'); |
| 98 | form.setAttribute('method', 'post'); |
| 99 | form.setAttribute('action', oembedConnectUrl); |
| 100 | |
| 101 | for (const key in urlParams) { |
| 102 | if (urlParams.hasOwnProperty(key)) { |
| 103 | let hiddenField = document.createElement('input'); |
| 104 | hiddenField.setAttribute('type', 'hidden'); |
| 105 | hiddenField.setAttribute('name', key); |
| 106 | hiddenField.setAttribute('value', urlParams[key]); |
| 107 | form.appendChild(hiddenField); |
| 108 | } |
| 109 | } |
| 110 | document.body.appendChild(form); |
| 111 | |
| 112 | // Record that this user started a connect before leaving the site. The connect |
| 113 | // service returns no parameters of ours, so this marker is what authorises the |
| 114 | // inbound cff_access_token in CFF_oEmbeds::processCffOembedAccessToken(). |
| 115 | let initData = new FormData(); |
| 116 | initData.append( 'action', 'cff_oembed_connect_init' ); |
| 117 | initData.append( 'nonce', this.nonce ); |
| 118 | fetch(cff_oembeds.ajax_handler, { |
| 119 | method: "POST", |
| 120 | credentials: 'same-origin', |
| 121 | body: initData |
| 122 | }) |
| 123 | .then(response => response.json()) |
| 124 | .then(data => { |
| 125 | if ( ! data || ! data.success ) { |
| 126 | throw new Error( 'connect marker was not set' ); |
| 127 | } |
| 128 | form.submit(); |
| 129 | }) |
| 130 | .catch(err => { |
| 131 | // Do not submit. Without the marker the token is refused on return, so the |
| 132 | // user would complete the whole Facebook flow only to land back here with |
| 133 | // nothing enabled and no explanation. |
| 134 | console.error( 'CFF: could not record oEmbed connect start', err ); |
| 135 | this.fboEmbedLoader = false; |
| 136 | this.fboEmbedError = this.genericText.connectError; |
| 137 | }); |
| 138 | }, |
| 139 | enableInstagramOembed: function() { |
| 140 | this.instaoEmbedLoader = true; |
| 141 | window.location = this.connectionURL; |
| 142 | return; |
| 143 | }, |
| 144 | disableFboEmbed: function() { |
| 145 | this.fboEmbedLoader = true; |
| 146 | let data = new FormData(); |
| 147 | data.append( 'action', 'disable_facebook_oembed' ); |
| 148 | data.append( 'nonce', this.nonce ); |
| 149 | fetch(cff_oembeds.ajax_handler, { |
| 150 | method: "POST", |
| 151 | credentials: 'same-origin', |
| 152 | body: data |
| 153 | }) |
| 154 | .then(response => response.json()) |
| 155 | .then(data => { |
| 156 | if( data.success == true ) { |
| 157 | this.fboEmbedLoader = false; |
| 158 | this.facebook.doingOembeds = false; |
| 159 | // get the updated connection URL after disabling oEmbed |
| 160 | this.connectionURL = data.data.connectionUrl; |
| 161 | } |
| 162 | return; |
| 163 | }); |
| 164 | }, |
| 165 | disableInstaoEmbed: function() { |
| 166 | this.instaoEmbedLoader = true; |
| 167 | let data = new FormData(); |
| 168 | data.append( 'action', 'disable_instagram_oembed' ); |
| 169 | data.append( 'nonce', this.nonce ); |
| 170 | fetch(cff_oembeds.ajax_handler, { |
| 171 | method: "POST", |
| 172 | credentials: 'same-origin', |
| 173 | body: data |
| 174 | }) |
| 175 | .then(response => response.json()) |
| 176 | .then(data => { |
| 177 | if( data.success == true ) { |
| 178 | this.instaoEmbedLoader = false; |
| 179 | this.instagram.doingOembeds = false; |
| 180 | // get the updated connection URL after disabling oEmbed |
| 181 | this.connectionURL = data.data.connectionUrl; |
| 182 | } |
| 183 | return; |
| 184 | }); |
| 185 | }, |
| 186 | installButtonText: function( buttonText = null ) { |
| 187 | if ( buttonText ) { |
| 188 | return buttonText; |
| 189 | } else if ( this.instagram.installer.nextStep == 'free_install' ) { |
| 190 | return this.modal.install; |
| 191 | } else if ( this.instagram.installer.nextStep == 'free_activate' ) { |
| 192 | return this.modal.activate; |
| 193 | } |
| 194 | }, |
| 195 | installIcon: function() { |
| 196 | if ( this.isIntagramActivated ) { |
| 197 | return; |
| 198 | } |
| 199 | if( this.installerStatus == null ) { |
| 200 | return this.modal.plusIcon; |
| 201 | } else if( this.installerStatus == 'loading' ) { |
| 202 | return this.loaderSVG; |
| 203 | } else if( this.installerStatus == 'success' ) { |
| 204 | return this.checkmarkSVG; |
| 205 | } else if( this.installerStatus == 'error' ) { |
| 206 | return `<i class="fa fa-times-circle"></i>`; |
| 207 | } |
| 208 | }, |
| 209 | }, |
| 210 | created() { |
| 211 | // Display the "Install" button text on modal depending on condition |
| 212 | if ( this.instagram.installer.nextStep == 'free_install' ) { |
| 213 | this.instagramInstallBtnText = this.modal.install; |
| 214 | } else if ( this.instagram.installer.nextStep == 'free_activate' || this.instagram.installer.nextStep == 'pro_activate' ) { |
| 215 | this.instagramInstallBtnText = this.modal.activate; |
| 216 | } |
| 217 | } |
| 218 | }) |
| 219 |