Skip to content

Commit

Permalink
fix: compatibility with Sassy Social share plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoreMihai authored and selul committed Jan 14, 2020
1 parent ce1c162 commit d4224cb
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cypress/integration/test_ss_pintereset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe( 'Sassy Social Share', function () {
it( 'successfully loads', function () {
cy.visit( '/sassy-social-share/' )
} );
it( 'click on button', function () {
cy.get( '.heateorSssSharing.heateorSssPinterestBackground' ).click( { multiple: true } )
} );
it( 'images should not have quality:eco', function () {
cy.get( 'img' ).should( ( $imgs ) => {
expect( $imgs ).to.have.length( 5 )
expect( $imgs.eq( 0 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' )
expect( $imgs.eq( 1 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' )
expect( $imgs.eq( 2 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' )
expect( $imgs.eq( 3 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' )
} );
} );
} );
72 changes: 72 additions & 0 deletions inc/compatibilities/sassy_social_share.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/**
* Class Optml_sassy_social_share.
*
* @reason Sassy social share picks eco images to share
*/
class Optml_sassy_social_share extends Optml_compatibility {
/**
* Should we load the integration logic.
*
* @return bool Should we load.
*/
function should_load() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

if ( ! is_plugin_active( 'sassy-social-share/sassy-social-share.php' ) ) {
return false;
}
$ss_options = get_option( 'heateor_sss' );
$ss_bars = ['vertical_re_providers', 'horizontal_re_providers'];
if ( ! is_array( $ss_options ) ) {
return false;
}
foreach ( $ss_bars as $key => $bar ) {
if ( ! isset( $ss_options[ $bar ] ) ) {
continue;
}
foreach ( $ss_options[ $bar ] as $index => $value ) {
if ( isset( $value ) && is_string( $value ) ) {
if ( strpos( $value, 'pinterest' ) !== false ) {
return true;
}
}
}
}

return false;
}

/**
* Register integration details.
*/
public function register() {
add_action(
'wp_enqueue_scripts',
function () {
wp_register_script( 'optml-typekit', false );
wp_enqueue_script( 'optml-typekit' );
$script = '
(function(w, d){
w.addEventListener("load", function(){
let p=d.querySelectorAll( ".heateorSssSharing.heateorSssPinterestBackground" );
p.forEach ( function (button,index) {
button.addEventListener( "mouseover", () => {
let images = d.getElementsByTagName( "img" );
for ( let i = 0; i < images.length; i++ ) {
if ( "optSrc" in images[i].dataset ) {
images[i].src = images[i].dataset.optSrc ;
}
}
},{once:true} );
});
});
}(window, document));
';
wp_add_inline_script( 'optml-typekit', $script );
}
);
}
}
1 change: 1 addition & 0 deletions inc/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ final class Optml_Manager {
'divi_builder',
'thrive',
'master_slider',
'sassy_social_share',
);

/**
Expand Down

0 comments on commit d4224cb

Please sign in to comment.