Skip to content

Commit

Permalink
Show confirmation message before clearing formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
boonebgorges committed Oct 8, 2014
1 parent cfe2796 commit c694ca5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 9 additions & 7 deletions assets/js/cacap.js
Expand Up @@ -226,13 +226,15 @@ window.wp = window.wp || {};
function init_clear_formatting() {
// Delegated
$( '.cacap-widgets-edit' ).on( 'click', 'a.cacap-clear-formatting', function( e ) {
$field_to_clear = $( e.target ).closest( '.cacap-widget-section-editable' ).find( '.editable-content' );
var field_html = $field_to_clear.html().replace( /<br>/g, "__CACAP__BR__" );
var new_div = document.createElement( "div" );
new_div.innerHTML = field_html;
var cleaned_text = new_div.textContent || new_div.innerText || "";
console.log( cleaned_text.replace( /__CACAP__BR__/g, "<br>" ) );
$field_to_clear.html( cleaned_text.replace( /__CACAP__BR__/g, "<br>" ) );
if ( confirm( CACAP_Strings.clear_formatting_confirm ) ) {
$field_to_clear = $( e.target ).closest( '.cacap-widget-section-editable' ).find( '.editable-content' );
var field_html = $field_to_clear.html().replace( /<br>/g, "__CACAP__BR__" );
var new_div = document.createElement( "div" );
new_div.innerHTML = field_html;
var cleaned_text = new_div.textContent || new_div.innerText || "";
$field_to_clear.html( cleaned_text.replace( /__CACAP__BR__/g, "<br>" ) );
}

return false;
} );
}
Expand Down
4 changes: 4 additions & 0 deletions includes/controller.php
Expand Up @@ -188,6 +188,10 @@ public function enqueue_scripts() {
$v
);

wp_localize_script( 'cacap', 'CACAP_Strings', array(
'clear_formatting_confirm' => __( 'Are you sure you want to remove all formatting from this field?', 'cacap' ),
) );

// enqueue CAC js for commons-profile pages
wp_enqueue_script( 'bp-dtheme-js' );
}
Expand Down

0 comments on commit c694ca5

Please sign in to comment.