Skip to content

Commit

Permalink
Twitter Timeline Widget: load js asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
Karen authored and blobaugh committed Mar 25, 2014
1 parent 5cbf1c0 commit b840a08
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
Binary file added modules/.DS_Store
Binary file not shown.
21 changes: 20 additions & 1 deletion modules/widgets/twitter-timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,28 @@ public function __construct() {
);

if ( is_active_widget( false, false, $this->id_base ) || is_active_widget( false, false, 'monster' ) ) {
wp_enqueue_script( 'twitter-widgets', '//platform.twitter.com/widgets.js', '', '', true );
add_action( 'wp_footer', array( $this, 'library' ) );
}
}

/**
* Enqueue Twitter's widget library
*/
public function library() {
?>
<script type="text/javascript">
!function(d,s,id){
var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';
if(!d.getElementById(id)){
js=d.createElement(s);
js.id=id;js.src=p+"://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js,fjs);
}
}
(document,"script","twitter-wjs");
</script>
<?php
}

/**
* Front-end display of widget.
Expand Down

2 comments on commit b840a08

@cathyjf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephdau, any objection to this being merged into wpcom?

@stephdau
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that very much too. So long as it's tested.
I'll never have an objection to working code making it in. :)
Hard to tell with just a diff. It's not like I authored all those and can commit to an answer off the top of my head. I inherited of them [too]. If you merge code up, I'll trust your judgement, and testing (on both platforms: jp and wpcom). All that matters is that it works, and is the same (when shared) on both platform as soon as reasonable/feasible.

Please sign in to comment.