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

Commit

Permalink
Merge pull request #111 from Yoast/stories/DT/sitename-#110
Browse files Browse the repository at this point in the history
Stories/dt/sitename #110
  • Loading branch information
atimmer committed Oct 27, 2015
2 parents 85b9910 + 00939aa commit a409e62
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 18 deletions.
41 changes: 33 additions & 8 deletions dist/yoast-seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,11 @@ YoastSEO.App.prototype.createSnippetPreviewTitle = function( target ) {
title.className = "title";
title.id = "snippet_title";
elem.appendChild( title );
var sitename;
sitename = document.createElement( "span" );
sitename.className = "title";
sitename.id = "snippet_sitename";
elem.appendChild( sitename );
};

/**
Expand Down Expand Up @@ -2026,6 +2031,10 @@ YoastSEO.SnippetPreview.prototype.init = function() {
this.output = this.htmlOutput();
this.renderOutput();
}
this.snippetSuffix = "";
if ( this.refObj.config.snippetSuffix !== "undefined" ) {
this.snippetSuffix = this.refObj.config.snippetSuffix;
}
};

/**
Expand Down Expand Up @@ -2054,6 +2063,8 @@ YoastSEO.SnippetPreview.prototype.formatTitle = function() {
}
if ( title === "" ) {
title = this.refObj.config.sampleText.title;
} else {
title += this.snippetSuffix;
}
title = this.refObj.stringHelper.stripAllTags( title );
if ( this.refObj.rawData.keyword !== "" ) {
Expand Down Expand Up @@ -2291,7 +2302,6 @@ YoastSEO.SnippetPreview.prototype.checkTextLength = function( ev ) {
if ( text.length > 70 ) {
YoastSEO.app.snippetPreview.unformattedText.snippet_title = ev.currentTarget.textContent;
ev.currentTarget.textContent = text.substring( 0, 70 );

}
break;
default:
Expand All @@ -2311,21 +2321,37 @@ YoastSEO.SnippetPreview.prototype.getUnformattedText = function( ev ) {
}
};

YoastSEO.SnippetPreview.prototype.setUnformattedElemText = function( elem ) {
this.unformattedText[ elem ] = document.getElementById( elem ).textContent;
};

/**
* 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 ) {
this.setUnformattedElemText ( ev.currentTarget.id );
var elem = ev.currentTarget.id;
this.unformattedText[ elem ] = document.getElementById( elem ).textContent;
};

/**
* Adds the siteName to the snippetTitle when editting starts, this adds the sitename to
* the snippet_sitename that cannot be edited.
* @param ev
*/
YoastSEO.SnippetPreview.prototype.setSiteName = function( ev ) {
if ( ev.currentTarget.id === "snippet_title" ) {
document.getElementById( "snippet_sitename" ).textContent = this.snippetSuffix;
}
};

/**
* adds and remove the tooLong class when a text is too long.
* Removes the siteName from the snippetTitle span when editing is finished, since it should only show
* when editing.
*/
YoastSEO.SnippetPreview.prototype.unsetSiteName = function() {
document.getElementById( "snippet_sitename" ).textContent = "";
};

/**
* Adds and remove the tooLong class when a text is too long.
* @param ev
*/
YoastSEO.SnippetPreview.prototype.textFeedback = function( ev ) {
Expand Down Expand Up @@ -2384,7 +2410,6 @@ YoastSEO.SnippetPreview.prototype.setFocus = function( ev ) {
}
}
};

;/* global YoastSEO: true */
YoastSEO = ( "undefined" === typeof YoastSEO ) ? {} : YoastSEO;

Expand Down
4 changes: 2 additions & 2 deletions dist/yoast-seo.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ YoastSEO.App.prototype.createSnippetPreviewTitle = function( target ) {
title.className = "title";
title.id = "snippet_title";
elem.appendChild( title );
var sitename;
sitename = document.createElement( "span" );
sitename.className = "title";
sitename.id = "snippet_sitename";
elem.appendChild( sitename );
};

/**
Expand Down
36 changes: 28 additions & 8 deletions js/snippetPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ YoastSEO.SnippetPreview.prototype.init = function() {
this.output = this.htmlOutput();
this.renderOutput();
}
this.snippetSuffix = "";
if ( this.refObj.config.snippetSuffix !== "undefined" ) {
this.snippetSuffix = this.refObj.config.snippetSuffix;
}
};

/**
Expand Down Expand Up @@ -62,6 +66,8 @@ YoastSEO.SnippetPreview.prototype.formatTitle = function() {
}
if ( title === "" ) {
title = this.refObj.config.sampleText.title;
} else {
title += this.snippetSuffix;
}
title = this.refObj.stringHelper.stripAllTags( title );
if ( this.refObj.rawData.keyword !== "" ) {
Expand Down Expand Up @@ -299,7 +305,6 @@ YoastSEO.SnippetPreview.prototype.checkTextLength = function( ev ) {
if ( text.length > 70 ) {
YoastSEO.app.snippetPreview.unformattedText.snippet_title = ev.currentTarget.textContent;
ev.currentTarget.textContent = text.substring( 0, 70 );

}
break;
default:
Expand All @@ -319,21 +324,37 @@ YoastSEO.SnippetPreview.prototype.getUnformattedText = function( ev ) {
}
};

YoastSEO.SnippetPreview.prototype.setUnformattedElemText = function( elem ) {
this.unformattedText[ elem ] = document.getElementById( elem ).textContent;
};

/**
* 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 ) {
this.setUnformattedElemText ( ev.currentTarget.id );
var elem = ev.currentTarget.id;
this.unformattedText[ elem ] = document.getElementById( elem ).textContent;
};

/**
* adds and remove the tooLong class when a text is too long.
* Adds the siteName to the snippetTitle when editting starts, this adds the sitename to
* the snippet_sitename that cannot be edited.
* @param ev
*/
YoastSEO.SnippetPreview.prototype.setSiteName = function( ev ) {
if ( ev.currentTarget.id === "snippet_title" ) {
document.getElementById( "snippet_sitename" ).textContent = this.snippetSuffix;
}
};

/**
* Removes the siteName from the snippetTitle span when editing is finished, since it should only show
* when editing.
*/
YoastSEO.SnippetPreview.prototype.unsetSiteName = function() {
document.getElementById( "snippet_sitename" ).textContent = "";
};

/**
* Adds and remove the tooLong class when a text is too long.
* @param ev
*/
YoastSEO.SnippetPreview.prototype.textFeedback = function( ev ) {
Expand Down Expand Up @@ -392,4 +413,3 @@ YoastSEO.SnippetPreview.prototype.setFocus = function( ev ) {
}
}
};

0 comments on commit a409e62

Please sign in to comment.