How it works (technical stuff)

The plugin is a combination of WordPress extending, the YouTube API and jQuery. When the plugin is activated it will add a post type in the WordPress installation called ‘annotated_video’, which is not visible in the administration menu. If a shortcode is used in a page, the plugin adds a ‘annotated_video’-post to the database using wp_insert_post(), with the YouTube code as title.

Whenever a page is being loaded in WordPress, the plugin uses global $wp_query to check if the shortcode is used in the pages and enqueues the necessary CSS and Javascript. The JavaScript checks or the generated HTML and fires up the YouTube API to load the different videos and adds a timer to each of the videos.

If a user is logged in, an input field is visible to add annotations to the video. The plugin uses WordPress’ standard commenting functionality to add a comment to the annotated video. Expect that it checks the current time of the YouTube player and saves this timestamp together with the comment. Also, it uses the jQuery Form Plugin to submit the form without a page refresh.

When the comment is saved, the comment is added to the DOM using jQuery (so no additional request to the server). From there on, jQuery sorts out which comments should be shown at what time using the timestamp classes added to the element.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>