Skip to content

Commit

Permalink
Merge pull request #17 from superwebshare/disable-native-share-on-des…
Browse files Browse the repository at this point in the history
…ktop

Disable native share on desktop to forcefully show the fallback
  • Loading branch information
josevarghese authored Nov 30, 2022
2 parents 5be8bad + 930f7cb commit 736146d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 39 deletions.
86 changes: 48 additions & 38 deletions admin/class-super-web-share-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,75 +606,84 @@ function superwebshare_register_settings_floating() {
function superwebshare_register_settings_fallback(){
// Register Setting
register_setting(
'superwebshare_settings_fallback_group', // Group name
'superwebshare_fallback_settings', // Setting name = html form <input> name on settings form
'superwebshare_validater_and_sanitizer_fallback' // Input sanitizer
'superwebshare_settings_fallback_group', // Group name
'superwebshare_fallback_settings', // Setting name = html form <input> name on settings form
'superwebshare_validater_and_sanitizer_fallback' // Input sanitizer
);

// Floating Button Settings
add_settings_section(
'superwebshare_fallback_settings_section', // ID
__('Fallback Settings', 'super-web-share'), // Title
'__return_false', // Callback Function
'superwebshare_fallback_settings_section' // Page slug
'superwebshare_fallback_settings_section', // ID
__('Fallback Settings', 'super-web-share'), // Title
'__return_false', // Callback Function
'superwebshare_fallback_settings_section' // Page slug
);

// Description
add_settings_field(
'superwebshare_inline_description_share', // ID
__('', 'super-web-share'), // Title
'superwebshare_fallback_description_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
'superwebshare_inline_description_share', // ID
__('', 'super-web-share'), // Title
'superwebshare_fallback_description_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
);

// Since 2.0
add_settings_field(
'superwebshare_fallback_enable', // ID
__('Show fallback share buttons', 'super-web-share'), // Title
'superwebshare_fallback_enable_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
'superwebshare_fallback_enable', // ID
__('Show fallback share buttons', 'super-web-share'), // Title
'superwebshare_fallback_enable_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
);

//Since 2.1 for fallback modal color
add_settings_field(
'fallback_modal_background', // ID
'fallback_modal_background', // ID
__('Background color for fallback', 'super-web-share'), // Title
'superwebshare_fallback_modal_background_color_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
'superwebshare_fallback_modal_background_color_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
);

//Since 2.1 for layout selection for fallback
add_settings_field(
'superwebshare_fallback_modal_layout', // ID
__('Fallback layout', 'super-web-share'), // Title
'superwebshare_fallback_modal_layout_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
'superwebshare_fallback_modal_layout', // ID
__('Fallback layout', 'super-web-share'), // Title
'superwebshare_fallback_modal_layout_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
);

//Since 2.4 - Color settings for the Fallback text
add_settings_field(
'superwebshare_fallback_text_color', // ID
__('Fallback text color', 'super-web-share'), // Title
'superwebshare_fallback_text_color_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
);
'superwebshare_fallback_text_color', // ID
__('Fallback text color', 'super-web-share'), // Title
'superwebshare_fallback_text_color_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
);

//Since 2.4 - Disable native share on desktop to forcefully show the fallback
add_settings_field(
'superwebshare_fallback_show_fallback', // ID
__('Do you want to show the fallback modal within the desktop devices?', 'super-web-share'), // Title
'superwebshare_fallback_show_fallback_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
);

/**
* Since 2.3 for twitter via url parameter
* @see https://developer.twitter.com/en/docs/twitter-for-websites/tweet-button/guides/parameter-reference1
*/

add_settings_field(
'fallback_twitter_via', // ID
__('Twitter username', 'super-web-share'), // Title
'fallback_twitter_via_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
'fallback_twitter_via', // ID
__('Twitter username', 'super-web-share'), // Title
'fallback_twitter_via_cb', // CB
'superwebshare_fallback_settings_section', // Page slug
'superwebshare_fallback_settings_section' // Settings Section ID
);

}
Expand Down Expand Up @@ -829,7 +838,8 @@ function superwebshare_settings_default( $name ){
'fallback_modal_background' => '#BD3854', // default color for fallback modal - 2.1
'fallback_layout' => '1', // fallback layout color - 2.1
'fallback_twitter_via' => '', // default value none
'fallback_text_color' => '#fff' // default color #fff
'fallback_text_color' => '#fff', // default color #fff
'fallback_show_in_desktop' => 'disable' // default value as disable to trigger based on API support - 2.4
),
"appearance" => array(
'superwebshare_appearance_button_icon' => 'share-icon-1', // default value "share-icon-1"
Expand Down
16 changes: 16 additions & 0 deletions admin/partials/super-web-share-admin-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,22 @@ function superwebshare_fallback_text_color_cb(){
<?php
}

/**
* Disable native share on desktop to forcefully show the fallback
*
* @since 2.4
*/
function superwebshare_fallback_show_fallback_cb(){
$settings_fallback = superwebshare_get_settings_fallback();
$saved = isset( $settings_fallback[ 'fallback_show_in_desktop' ] ) ? esc_html( $settings_fallback[ 'fallback_show_in_desktop' ] ) : "disable";
superwebshare_input_toggle( 'superwebshare_fallback_settings[fallback_show_in_desktop]', 'enable', $saved );
?>
<p class="description">
<?php _e('This setting does not apply to Microsoft Edge Browser as the sharing dialog box has social media links same as our fallback.', 'super-web-share'); ?>
</p>
<?php
}

/**
* Fallback twitter Via parameter value field
* @since 2.3
Expand Down
14 changes: 13 additions & 1 deletion public/js/super-web-share-public.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,20 @@ function hasPermission() {
console.log('SuperWebShare: Your browser does not seems to support SuperWebShare, as the browser is incompatible');
}
}
const fallbackForcefullyShowDesktop = () =>{
// This settings not applicable for MS Edge browser.
if( window.superWebShareFallback.fallback_show_in_desktop === 'enable' ){

let isIEedge = window.navigator.userAgent.indexOf("Edg") > -1;
let regexp = /android|iphone|kindle|ipad|webos|ipod/i;
let isDesktop = ! regexp.test( window.navigator.userAgent )
return isDesktop && !isIEedge
}else{
return false;
}
}
async function SuperWebSharefn(Title, URL, Description) {
if (typeof navigator.share === 'undefined' || !navigator.share) {
if (typeof navigator.share === 'undefined' || !navigator.share || fallbackForcefullyShowDesktop()) {
modal();
} else if (window.location.protocol != 'https:') {
console.log('SuperWebShare: Seems like the website is not served fully via https://. As for supporting SuperWebShare the website should be served fully via https://');
Expand Down

0 comments on commit 736146d

Please sign in to comment.