Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

Commit

Permalink
Fixes snippet preview data handling. Now the correct data is sent to …
Browse files Browse the repository at this point in the history
…the analyzer, and unformatted data is stored in the snippetPreview
  • Loading branch information
terw-dan committed Sep 23, 2015
1 parent c4f9c03 commit 682ec6d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ <h3>Want to write better? Buy our eBook!</h3>
</aside>
</div>
</div>

</div>
<div class="footer-widgets">
<div class="wrap">
Expand Down
5 changes: 2 additions & 3 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,8 @@ YoastSEO.App.prototype.pluginsLoaded = function() {
* Runs a queue with tests where no keyword is required.
*/
YoastSEO.App.prototype.noKeywordQueue = function() {
var data = this.rawData;
data.queue = [ "keyWordCheck", "wordCount", "fleschReading", "pageTitleLength", "urlStopwords" ];
this.runAnalyzer( data );
this.rawData.queue = [ "keyWordCheck", "wordCount", "fleschReading", "pageTitleLength", "urlStopwords", "metaDescription" ];
this.runAnalyzer( this.rawData );
};

/**
Expand Down
9 changes: 7 additions & 2 deletions js/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ YoastSEO.PreProcessor.prototype.textFormat = function() {
YoastSEO.PreProcessor.prototype.countStore = function() {

/*wordcounters*/
this.__store.wordcount = this.__store.cleanText.split( " " ).length;
this.__store.wordcountNoTags = this.__store.cleanTextNoTags.split( " " ).length;
this.__store.wordcount = this.__store.cleanText === "" ?
0 :
this.__store.cleanText.split( " " ).length;

this.__store.wordcountNoTags = this.__store.cleanTextNoTags === "" ?
0 :
this.__store.cleanTextNoTags.split( " " ).length;

/*sentencecounters*/
this.__store.sentenceCount = this.sentenceCount( this.__store.cleanText );
Expand Down
52 changes: 24 additions & 28 deletions js/snippetPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ YoastSEO = ( "undefined" === typeof YoastSEO ) ? {} : YoastSEO;
*/
YoastSEO.SnippetPreview = function( refObj ) {
this.refObj = refObj;
this.unformattedText = {};
this.init();
};

Expand Down Expand Up @@ -97,7 +98,7 @@ YoastSEO.SnippetPreview.prototype.formatCite = function() {
* @returns formatted metatext
*/
YoastSEO.SnippetPreview.prototype.formatMeta = function() {
var meta = this.refObj.rawData.snippetMeta;
var meta = this.refObj.rawData.meta;
if ( meta === "" ) {
meta = this.getMetaText();
}
Expand Down Expand Up @@ -268,7 +269,7 @@ YoastSEO.SnippetPreview.prototype.checkTextLength = function( ev ) {
switch ( ev.currentTarget.id ) {
case "snippet_meta":
if ( text.length > YoastSEO.analyzerConfig.maxMeta ) {
ev.currentTarget.__unformattedText = ev.currentTarget.textContent;
YoastSEO.app.snippetPreview.unformattedText.snippet_meta = ev.currentTarget.textContent;
ev.currentTarget.textContent = text.substring(
0,
YoastSEO.analyzerConfig.maxMeta
Expand All @@ -278,7 +279,7 @@ YoastSEO.SnippetPreview.prototype.checkTextLength = function( ev ) {
break;
case "snippet_title":
if ( text.length > 40 ) {
ev.currentTarget.__unformattedText = ev.currentTarget.textContent;
YoastSEO.app.snippetPreview.unformattedText.snippet_title = ev.currentTarget.textContent;
ev.currentTarget.textContent = text.substring( 0, 40 );
ev.currentTarget.className = "title";
}
Expand All @@ -288,6 +289,26 @@ YoastSEO.SnippetPreview.prototype.checkTextLength = function( ev ) {
}
};

/**
* when clicked on an element in the snippet, checks fills the textContent with the data from the unformatted text.
* This removes the keyword highlighting and modified data so the original content can be editted.
* @param ev {event}
*/
YoastSEO.SnippetPreview.prototype.getUnformattedText = function( ev ) {
var currentElement = ev.currentTarget.firstChild.id;
ev.currentTarget.firstChild.textContent = YoastSEO.app.snippetPreview.unformattedText[ currentElement ];
};

/**
* when text is entered into the snippetPreview elements, the text is set in the unformattedText object.
* This allows the visible data to be editted in the snippetPreview.
* @param ev
*/
YoastSEO.SnippetPreview.prototype.setUnformattedText = function( ev ) {
var currentElement = ev.currentTarget.firstChild.id;
YoastSEO.app.snippetPreview.unformattedText[ currentElement ] = ev.currentTarget.firstChild.textContent;
};

/**
* adds and remove the tooLong class when a text is too long.
* @param ev
Expand Down Expand Up @@ -347,30 +368,5 @@ YoastSEO.SnippetPreview.prototype.setFocus = function( ev ) {
targetElem = targetElem.nextSibling;
}
}
targetElem.refObj.snippetPreview.setFocusToEnd( targetElem );
};

/**
* this function is needed for placing the caret at the end of the input when the text is changed
* at focus.
* Otherwise the cursor could end at the beginning of the text.
* @param elem
*/
YoastSEO.SnippetPreview.prototype.setFocusToEnd = function( elem ) {
if (
typeof window.getSelection !== "undefined" &&
typeof document.createRange !== "undefined"
) {
var range = document.createRange();
range.selectNodeContents( elem );
range.collapse( false );
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange( range );
} else if ( typeof document.body.createTextRange !== "undefined" ) {
var textRange = document.body.createTextRange();
textRange.moveToElementText( elem );
textRange.collapse( false );
textRange.select();
}
};

0 comments on commit 682ec6d

Please sign in to comment.