Preface You will also need to know the

Preface You will also need to know the basics of client-side web development. This includes HTML, CSS, but you should also have a rudimentary grasp of JavaScript syntax. Familiarity with PHP programming will be an advantage, since we will be writing PHPTemplate files and (at the end) creating Drupal modules. However, PHP is covered thoroughly enough that even the PHP neophyte will not find the text too demanding. The book also covers the jQuery JavaScript library and its use in Drupal, but no knowledge of jQuery is expected. You will learn everything you need in this book. Conventions In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning. Code words in text are shown as follows, “We can include other contexts through the use of the include directive.” A block of code will be set as follows: Drupal.behaviors.countParagraphs = function (context) { if ($(‘#lots’, context).size() > 0) { return; } else if ($(‘p’, context).size() > 5) { $(‘body’).append(‘

Lots of Text!

‘); } }; When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold: if( == txtareaID && sel.start != sel.end) { txtareaEle.value = SimpleEditor.insertTag( sel.start, sel.end, $(this).hasClass(‘bold’) ? ‘strong’ : ‘em’, txtareaEle.value ); sel.start = sel.end = -1; } New terms and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: “clicking the Next button moves you to the next screen”. [ 3 ]

Preface Chapter 2 covers the basics on how

Preface Chapter 2 covers the basics on how JavaScript can be used within Drupal 6. We will begin by exploring how JavaScript is included in Drupal pages, and then create our first script for Drupal. Chapter 3 focuses on jQuery. Initially, we will look at jQuery independently of Drupal, and then we will take a closer look at how jQuery is integrated with Drupal. Chapter 4 focuses on Drupal Behaviors and the major utility functions provided by drupal.js, which provides functions for behaviors, translation, theming, as well as other utility functions. Chapter 5 focuses on the translation system in Drupal, and the JavaScript tools that are used in conjunction with that system. We will look at installing and configuring multiple languages using JavaScript functions, and then extracting and translating strings. Chapter 6 focuses on the JavaScript theming system. We will look at the JavaScript theming module, and examine some of the themes and user interface tools that it provides. We will implement our own template system based on HTML, CSS, and JavaScript. Chapter 7 focuses on the AJAX family of tools. We will learn to use jQuery’s built-in AJAX support to get content from Drupal, and also use JSON (JavaScript Object Notation) as a JavaScript-friendly way of sending data from Drupal. Chapter 8 focuses on module development. We will discuss how modules work, and will learn how to create modules and use them for adding JavaScript features. We will also learn to make our JavaScript available to other modules. Chapter 9 focuses on advanced topics. We will look at integrating existing Drupal JavaScript tools with our own site design, and then we will see how to extend the JavaScript libraries with the jQuery UI library. We will also extend jQuery’s library with our own functions, building a jQuery plug-in in the process. Who this book is for This book is for web designers and developers who want to add JavaScript elements to Drupal themes or modules to create more flexible and responsive user interfaces. You are expected to know about the basic operation of Drupal, and be familiar with the concept of theming and modules in Drupal. No experience with creating themes or modules is required. [ 2 ]

Preface JavaScript: It’s not just for calculators and

Preface JavaScript: It’s not just for calculators and image rollovers. Drupal 6 is loaded with new features, not all of which are necessarily implemented in PHP. This unique book, for web designers and developers, will guide you through what can be done with JavaScript (and especially with jQuery) in Drupal 6. With the combination of the powerhouse jQuery library, with its own robust set of JavaScript tools, Drupal 6 comes with a pre-packaged killer JavaScript environment. Cross-platform by nature, it provides all of the tools necessary to create powerful AJAX-enabled scripts, gorgeous visual effects, and view-enhancing behaviors. In addition, Drupal developers have ported some of its most powerful PHP tools (like a theming engine and support for localization and language translation) to JavaScript, making it possible to write simple scripts, where once only complex PHP code could be used. This book gives you the keys to the toolbox, showing you how to use Drupal’s JavaScript libraries to make your modules and themes more dynamic, interactive, and responsive, and add effects to make your Drupal site explode into life! If you’ve dipped your toe in the water of theme or module development with Drupal 6, this is the book that will make the look and behavior of your work something special. With it’s project-based approach, this book is carefully constructed to guide you from how JavaScript fits into the overall Drupal architecture, to making you a master of the jQuery library in the world of Drupal themes and modules. What this book covers Chapter 1 focuses on various languages and technologies used in Drupal. We will have a high-level overview of the Drupal architecture followed by an examination of some key Drupal concepts such as users, blocks, and nodes. From there, we will move on to developers tools and learn about a few utilities that can expedite Drupal JavaScript development.

Table of Contents The bettereditor.js script 268 The

Table of Contents The bettereditor.js script 268 The editor() behavior 272 The insertTag() function 277 The addTag() theme 278 The button() theme function 284 The buttonBar() theme function 285 A last question 285 Summary 286 Chapter 9: Integrating and Extending 287 Project: autocompletion and search 287 The theory 288 Our plan 289 First step: creating the taxonomy 289 The new module 291 The search autocomplete JavaScript 294 Project: jQuery UI 299 What is jQuery UI? 299 Getting jQuery UI 300 The accordion module 301 The .info and .module files 302 The accordion JavaScript 303 Project: writing a jQuery plug-in 309 The plug-in code 310 A brief introduction to closures 312 The divWrap() function 315 Summary 318 Index 319

Table of Contents A word of warning 194

Table of Contents A word of warning 194 Summary 196 Chapter 7: AJAX and Drupal Web Services 197 AJAX, JSON, XHR, AHAH, and Web 2.0 198 Web application and Web 2.0 198 The position of AJAX in Web 2.0 199 Getting technical 200 Move over, XML 201 Project: web clips with RSS and AJAX 204 Really Simple Syndication (RSS) 205 The project goals 206 Creating the web clips tool 207 The WebClips behavior 209 The WebClips.showItem() function 217 Project: real-time comment notifications 219 Displaying comments as notifications 219 Installing Views and Views Datasource 220 Creating a JSON view 221 The comment watcher 226 The comment watcher behavior 230 The CommentWatcher.check() function 231 Theming the comment notification 235 Managing cookies 237 Summary 240 Chapter 8: Building a Module 241 How modules work 241 The module structure 242 The directory 243 The .info file 243 The .module file 243 Where do modules go? 243 Project: creating a JavaScript loader module 244 Creating the module directory 245 A JavaScript sample 246 The module’s .info file 247 A custom addition 248 The .module file 248 The jsloader_help() function 249 The jsloader_init() function 252 Project: the editor revisited 256 First step: creating the module 256 The CSS file 258 The bettereditor.module file 258 [ iv ]

Table of Contents The Drupal.encodeURIComponent() function 112 The

Table of Contents The Drupal.encodeURIComponent() function 112 The Drupal.getSelection() function 113 Project: a simple text editor 113 The main behavior 118 Step 1: find text areas that need processing 119 Step 2: add event handlers 119 Step 3: attach the button bar 120 Summary 126 Chapter 5: Lost in Translations 127 Translations and drupal.js 128 Translation and languages 128 Turning on translation support 129 Getting and installing translations 129 Configuring languages 130 Adding the language 130 Configuring languages 131 Using the translation functions 133 The Drupal.t() function 134 The Drupal.formatPlural() function 136 Adding a translated string 138 Project: weekend countdown 139 Translating the project’s strings 144 Changing a translation file 153 Summary 154 Chapter 6: JavaScript Theming 155 Theming in PHP, theming in JavaScript 155 The Drupal.theme() function 159 Project: menus and blocks 161 Adding a block with a menu in it 162 Theming a block 164 Theming a menu 168 The JavaScript theming module 174 Theming tables 175 Sending notifications to the user 178 Adding links 179 Project: templates for JavaScript 180 The node template 181 From a template to a system: what next? 183 A template system 184 Theming with templates 187 Using the template system 192

Table of Contents Drupal coding standards 34 Stylistic

Table of Contents Drupal coding standards 34 Stylistic differences between PHP and JavaScript 35 The first lines 36 The print() function 38 Creating a theme 43 Full themes and subthemes 44 Creating a theme: first steps 45 Creating a theme directory 45 Creating the .info file 47 Adding files to the theme 48 The CSS file 52 Adding JavaScript to a theme 52 Overriding a template 52 Adding the script file 57 Summary 58 Chapter 3: jQuery: Do More with Drupal 59 jQuery: the write less, do more library 59 A first jQuery script 62 Getting jQuery 62 Starting with a basic HTML document 62 Querying with jQuery (and the Firebug console) 63 Bye bye, jQuery(); hello $() 67 Doing more with jQuery 68 Using jQuery in Drupal 71 Don’t do it yourself! 73 Project: rotating sticky node teasers 73 The StickyRotate functions 76 The init() function 78 The periodicRefresh() function 86 Adding an event handler with jQuery 89 A brief look backward 91 Summary 92 Chapter 4: Drupal Behaviors 93 The drupal.js library 93 Drupal JavaScript behaviors 95 Defining a behavior to handle repeatable events 96 Telling Drupal to attach behaviors 98 Context and behaviors: bug potential 99 Project: collapsing blocks 102 Utilities 107 Checking capabilities with Drupal.jsEnabled 107 The Drupal.checkPlain() function (and the jQuery alternative) 108 The Drupal.parseJson() function 111

Table of Contents Preface 1 Chapter 1: Drupal

Table of Contents Preface 1 Chapter 1: Drupal and JavaScript 7 Do you speak…? 8 PHP 9 SQL 10 HTML 11 CSS 12 XML 13 JavaScript 14 Drupal’s architecture 15 The Drupal Core 16 The Theme Engine 18 Modules 18 Users, nodes, and blocks 19 Users 19 Blocks 20 Nodes 22 Drupal JavaScript development tools 23 A good editor 24 Firebug 24 The Drupal Devel package 26 Summary 28 Chapter 2: Working with JavaScript in Drupal 29 How Drupal handles JavaScript 30 Where Drupal JavaScript comes from? 31 Project overview: printer-friendly page content 32 The printer script 33

Drupal 6 JavaScript and jQuery Copyright 2009

Drupal 6 JavaScript and jQuery Copyright 2009 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: February 2009 Production Reference: 1180209 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847196-16-3 Cover Image by Damian Carvill (

If you want to learn more check our

If you want to learn more check our

viagra instructions | cheap cialis levitracom viagra | viagra uk | lowest price viagra | viagra | viagra pills | soft gel viagra | buying viagra in the us | alternative search viagra | cialis dosage | generic cialis next day delivery | where to buy viagra | generic viagra made in india | viagra | free trial of viagra | generic viagra uk supplies | prescription viagra | buy online pharmacy viagra | viagra ingredients | best price for generic viagra | real viagra online | viagra for women | brand drug generic name viagra | viagra cheap prescription | viagra effects on women | herbal risk viagra | alternative doctor viagra | viagra order | viagra success stories | viagra prices | pfizer viagra | order viagra 1 | dangers of viagra | buy herbal viagra | pfizer viagra 50 mg | is viagra legal | does generic viagra work | cialis for less 20 mg | imitation viagra | buying viagra with no prescription | discount lowest price viagra | getting viagra | buy real viagra without prescription | how can i make homemade viagra | buy viagra uk | super viagra | viagra chemical structure | where to get viagra cheap | how does viagra work | dangers of viagra | cialis philippines | viagra herb alternative | what is cialis | herbal alternatives to viagra ]

Blog about Java, PHP5 & MySQL5 programming techniques