Skip to content

Commit

Permalink
Merge pull request #83 from wikimedia/gray-out-untokenized
Browse files Browse the repository at this point in the history
Gray out non-tokenized elements
  • Loading branch information
samwilson authored Nov 7, 2019
2 parents 88734a5 + 7e96279 commit ea9ad3f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from './config';
import InfoBarWidget from './InfoBarWidget';
import RevisionPopupWidget from './RevisionPopupWidget';
import wwtController from './Controller';
Expand Down Expand Up @@ -63,6 +64,7 @@ class App {
// only what's actually inside it
this.$content = $( $.parseHTML( html ) ).contents();
this.attachContentListeners( this.$content );
this.grayOutUntokenizedElements( this.$content );
}

/**
Expand Down Expand Up @@ -132,6 +134,28 @@ class App {
return out;
}

/**
* Gray out elements that aren't or do not contain tokens.
* See `untokenizedElements` in config.js for selectors of elements we know aren't tokenized.
* @param {jQuery} $content
*/
grayOutUntokenizedElements( $content ) {
// Disable various elements that may not be picked up by the $.each loop below.
// This NOT comprehensive, and is comprised of a manually maintained list in config.js
$content.find( config.untokenizedElements.join( ',' ) ).addClass( 'wwt-disabled' );

// Add the class to immediate children of the parser output
// that don't contain tokenized elements.
$.each( $content, ( _i, el ) => {
if ( !$( el ).hasClass( 'editor-token' ) && !$( el ).find( '.editor-token' ).length ) {
$( el ).addClass( 'wwt-disabled' )
// Remove .wtt-disabled elements added above to prevent compounding opacity.
.find( '.wwt-disabled' )
.removeClass( 'wwt-disabled' );
}
} );
}

/**
* Add listeners to:
* - highlight attribution;
Expand Down
9 changes: 8 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const config = {
wikiWhoUrl: 'https://www.wikiwho.net/',
// Set the output type between the extension and the gadget
outputEnvironment: ''
outputEnvironment: '',
// Elements that we know for sure are never tokenized and should be grayed out.
untokenizedElements: [
'.citation',
'.IPA',
'.mw-editsection',
'table'
]
};

// Set up a prefix for console outputs
Expand Down
8 changes: 8 additions & 0 deletions src/less/general.less
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ html.wwt-popup body {
top: 0;
left: 0;
}

.wwt-disabled {
opacity: 0.5;

&:hover {
opacity: 0.8;
}
}

0 comments on commit ea9ad3f

Please sign in to comment.