Skip to content

Commit

Permalink
Refactor to improve specificity of jQuery selectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
mendezcode committed Dec 20, 2018
1 parent 2b93de8 commit 62cb626
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions js/app/main.js
Expand Up @@ -20,7 +20,7 @@ o2.Routers.App = ( function( $, Backbone ) {

initialize: function( options ) {
// Load post action states dictionary
var postActionStateDict = $( '.o2-post-action-states-dict' );
var postActionStateDict = $( 'script.o2-post-action-states-dict' );
if ( postActionStateDict.length ) {
o2.PostActionStates.stateDictionary = $.parseJSON( postActionStateDict.text() );
}
Expand Down Expand Up @@ -248,14 +248,14 @@ o2.Routers.App = ( function( $, Backbone ) {

bootstrapUsers: function() {
var that = this; // keep a reference to the app
$( '.o2-user-data' ).each( function( index, element ) {
$( 'script.o2-user-data' ).each( function( index, element ) {
var me = $( element );
var userdatum = $.parseJSON( me.text() );
_.each( userdatum, function( frag ) {
that.addUser( frag );
} );
} );
$( '.o2-user-data' ).remove();
$( 'script.o2-user-data' ).remove();
},

addPost: function( post ) {
Expand Down Expand Up @@ -513,7 +513,7 @@ o2.Routers.App = ( function( $, Backbone ) {
*/
$( document ).on( 'post-load', function() {
o2.Events.doAction( 'pre-infinite-scroll-response.o2' );
$( '.infinite-wrap .o2-data' ).each( function() {
$( '.infinite-wrap script.o2-data' ).each( function() {
o2.Notifications.close();
o2.App.suppressHighlighting();
var me = $( this );
Expand Down
2 changes: 1 addition & 1 deletion modules/live-comments/js/live-comments-widget.js
Expand Up @@ -10,7 +10,7 @@ o2.Routers.LiveComments = ( function( $, Backbone ) {

// consume the bootstrap data, if present
var liveBootstrap = [];
var bootstrapEl = $( '.o2-live-widget-bootstrap-data' );
var bootstrapEl = $( 'script.o2-live-widget-bootstrap-data' );
if ( bootstrapEl.length ) {
liveBootstrap = $.parseJSON( bootstrapEl.text() );
}
Expand Down
2 changes: 1 addition & 1 deletion modules/notifications/js/app/notifications.js
Expand Up @@ -9,7 +9,7 @@ o2.Routers.Notifications = ( function( $, Backbone ) {

// Acquire bootstrap data if available
var bootstrap = [];
var bootstrapEl = $( '.o2-notifications-data' );
var bootstrapEl = $( 'script.o2-notifications-data' );
if ( bootstrapEl.length > 0 ) {
_.each( $.parseJSON( bootstrapEl.text() ), function( fragment ) {
bootstrap.push( fragment );
Expand Down
4 changes: 2 additions & 2 deletions modules/to-do/inc/class-to-do-widget.php
Expand Up @@ -300,14 +300,14 @@ function wp_footer() {
<script type='text/javascript'>
jQuery( document ).ready( function( $ ) {
var bootstrap = { data: [], found: [] };
var resolvedPostsData = $( '.o2-resolved-posts-data' );
var resolvedPostsData = $( 'script.o2-resolved-posts-data' );
if ( resolvedPostsData.length > 0 ) {
_.each( $.parseJSON( resolvedPostsData.text() ), function( fragment ) {
bootstrap.data.push( fragment );
} );
resolvedPostsData.remove();
}
var foundPostsData = $( '.o2-resolved-posts-found' );
var foundPostsData = $( 'script.o2-resolved-posts-found' );
if ( foundPostsData.length > 0 ) {
_.each( $.parseJSON( foundPostsData.text() ), function( fragment ) {
bootstrap.found.push( fragment );
Expand Down
2 changes: 1 addition & 1 deletion o2.php
Expand Up @@ -809,7 +809,7 @@ public function wp_footer() {
<script>
jQuery(document).ready(function($) {
var bootstrap = { data: [] };
o2Data = $( '.o2-data' );
o2Data = $( 'script.o2-data' );
if ( o2Data.length > 0 ) {
o2Data.each( function() {
// Parse the JSON that's embedded in the page and add it to the bootstrap data
Expand Down

0 comments on commit 62cb626

Please sign in to comment.