Book Image

Mastering jQuery UI

By : Vijay Joshi
Book Image

Mastering jQuery UI

By: Vijay Joshi

Overview of this book

Table of Contents (19 chapters)
Mastering jQuery UI
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding event handlers in the init method


The init method is the first method of the myReddit object that is called. Since this is a starting point for us, let's begin by creating the tabs and attaching all the event handlers that will be used later in the code.

Tip

It is good practice to define all event handlers in one place. Different event handlers scattered all over the code are bad for readability, as well as for debugging the code later.

Look for the init method in the myReddit.js file and write the following code to set up tabs and event handlers:

$( "#redditTabs" ).tabs();

$('#addNewSubreddit').button();

$('#tabList').on('click', '.ui-icon-close', function()
{
  var tabPanelContainer = $(this).prev('a').attr('href');
  $(this).parent('li').remove();
  $(tabPanelContainer).remove();
  $( "#redditTabs" ).tabs('refresh');
});


$('#redditTabs').on('click', '#addNewSubreddit', function()
{
  myReddit.getJSONFromAPI('posts', $('#subredditName').val());
});


$('#redditTabs').on('click'...