Last active
October 7, 2015 13:41
-
-
Save kraftner/84bc3f9cc938d157ba29 to your computer and use it in GitHub Desktop.
wordpress-seo_add_to_focus_keyword_test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function (){ | |
if(typeof window.ystTestFocusKw === 'undefined'){ | |
return; | |
} | |
/** | |
* Backups the original function | |
* @type {function} | |
*/ | |
var ystTestFocusKw_original = window.ystTestFocusKw; | |
/** | |
* Stores functions that manipulate the content | |
* @type {Array} | |
*/ | |
var ystTestFocusKw_content_filter = []; | |
yst_testFocusKw_content_filter.push( function (content){ | |
/* content += 'add stuff here' */ | |
return content; | |
}); | |
window.ystTestFocusKw = function () { | |
ystTestFocusKw_original(); | |
//If there are no filters we can bail out early | |
if(ystTestFocusKw_content_filter.length === 0){ | |
return; | |
} | |
/* See /wordpress-seo/js/wp-seo-metabox.js | |
start copy */ | |
// Retrieve focus keyword and trim | |
var focuskw = jQuery.trim(jQuery('#' + window.wpseoMetaboxL10n.field_prefix + 'focuskw').val()); | |
focuskw = window.ystEscapeFocusKw(focuskw).toLowerCase(); | |
var p; | |
/* jshint ignore:start */ | |
p = new RegExp( '(^|[ \\s\n\r\t\\.,\'\\("\\+;!?:\\-])' + ystRemoveLowerCaseDiacritics( focuskw ) + '($|[\\s\n\r\t.,\'\\)"\\+!?:;\\-])', 'gim' ); | |
/* jshint ignore:end */ | |
/* end copy */ | |
// Get current text | |
var content = jQuery('#content').val(); | |
// Call all filters (only if they are functions) | |
jQuery.each(ystTestFocusKw_content_filter, function( index, value ) { | |
if (typeof value === 'function') { | |
content = value(content); | |
} | |
}); | |
if( !content ){ | |
return; | |
} | |
// Regex that only selects the "Content" li item | |
var re = new RegExp('^' + window.wpseoMetaboxL10n.content_text, 'i'); | |
jQuery('#focuskwresults li').filter(function(){ | |
return re.test( jQuery(this).text() ); | |
}).html( window.wpseoMetaboxL10n.content_text + window.ystFocusKwTest(content, p) ); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment