Moodle JavaScript Cookbook - Alastair Hole - E-Book

Moodle JavaScript Cookbook E-Book

Alastair Hole

0,0
31,19 €

oder
-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Moodle is the best e-learning solution on the block and is revolutionizing courses on the Web. Using JavaScript in Moodle is very useful to administrators and dynamic developers as it uses built-in libraries to provide the modern and dynamic experience that is expected by web users today.The Moodle JavaScript Cookbook will take you through the basics of combining Moodle with JavaScript and its various libraries and explain how JavaScript can be used along with Moodle. It will explain how to integrate Yahoo! User Interface Library (YUI) with Moodle. YUI will be the main focus of the book, and is the key to implementing modern, dynamic feature-rich interfaces to help your users get a more satisfying and productive Moodle experience. It will enable you to add effects, make forms more responsive, use AJAX and animation, all to create a richer user experience. You will be able to work through a range of YUI features, such as pulling in and displaying information from other websites, enhancing existing UI elements to make users' lives easier, and even how to add animation to your pages for a nice finishing touch.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Veröffentlichungsjahr: 2011

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Moodle JavaScript Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Combining Moodle and JavaScript
Introduction
Creating a new Moodle PHP page
Getting ready
How to do it...
How it works...
Loading a JavaScript file
Getting ready
How to do it...
How it works...
Loading a JavaScript file in <head>
Getting ready
How to do it...
How it works...
Generating a JavaScript function call from PHP
Getting ready
How to do it...
How it works…
Passing variables from PHP to JavaScript
Getting ready
How to do it...
How it works…
Ensuring compliance with XHTML Strict
Getting ready
How to do it...
How it works…
Retrieving language strings from Moodle
Getting ready
How to do it...
How it works…
2. Moodle and Yahoo! User Interface Library (YUI)
Introduction
Initializing the YUI 3 library
Getting ready
How to do it...
How it works...
Loading additional YUI modules
How to do it...
Loading YUI 2 modules from YUI 3
Getting ready
How to do it...
How it works...
Attaching basic event handlers
Getting ready
How to do it...
How it works...
Attaching advanced DOM event handlers
Getting ready
How to do it...
How it works...
Implementing event delegation
Getting ready
How to do it...
How it works...
Debugging with the YUI console
Getting ready
How to do it...
How it works...
3. Moodle Forms Validation
Introduction
Adding a required field
Getting ready
How to do it...
How it works...
Adding a field with a maximum length
Getting ready
How to do it...
How it works...
Adding a field with a minimum length
Getting ready
How to do it...
How it works...
Adding a field length within in a specified range
Getting ready
How to do it...
How it works...
Adding a valid e-mail address field
Getting ready
How to do it...
How it works...
Adding custom validation with a Regular Expression
Getting ready
How to do it...
How it works...
Adding a field that accepts only alphabetic characters
Getting ready
How to do it...
How it works...
Adding a field that accepts only alphanumeric characters
Getting ready
How to do it...
How it works...
Adding a field that accepts only numeric characters
Getting ready
How to do it...
How it works...
Rejecting punctuation characters
Getting ready
How to do it...
How it works...
Rejecting input without a leading zero
Getting ready
How to do it...
How it works...
Comparing with another field
Getting ready
How to do it...
How it works...
Adding a custom JavaScript validation function callback
Getting ready
How to do it...
How it works...
4. Manipulating Data with YUI 3
Introduction
Using IO to request a URI
How to do it...
How it works...
Using IO's alternative transport method for requesting external URIs
Getting ready
How to do it...
How it works...
Using PHP as a proxy to load data from an external domain
How to do it...
How it works...
Parsing XML with DataSource
How to do it...
How it works...
Parsing JSON with DataSource
Getting ready
How to do it...
How it works...
Parsing CSV data with DataSource
Getting ready
How to do it...
How it works...
Retrieving data from a Moodle 2.0 web service
Getting ready
How to do it...
How it works…
5. Working with Data Tables
Introduction
Initializing a YUI DataSource
How to do it...
How it works...
Displaying data
How to do it...
How it works...
Basic column sorting
Getting ready
How to do it...
How it works...
Adding paging
Getting ready
How to do it...
How it works...
Enabling scrolling
Getting ready
How to do it...
How it works...
Enabling editing
Getting ready
How to do it...
How it works...
6. Enhancing Page Elements
Introduction
Adding a text box with auto-complete
How to do it...
How it works...
Adding a combo box with auto-complete
How to do it...
How it works...
Displaying auto-updating data
How to do it...
How it works...
Enabling resizable elements
How to do it...
How it works...
Adding custom tooltips
How to do it...
How it works...
Adding custom button controls
How to do it...
How it works...
7. Advanced Layout Techniques
Introduction
Adding a fly-out navigation menu
How to do it...
How it works...
Adding a drop-down navigation menu
Getting ready
How to do it...
How it works...
Displaying a tree-view navigation menu
How to do it...
How it works...
Adding a tabbed content control
How to do it...
How it works...
Displaying content in a modal window
How to do it...
How it works...
8. Animating Components
Introduction
Fading in an element
How to do it...
How it works...
Fading out an element
How to do it...
How it works...
Scrolling an element
How to do it...
How it works...
Resizing an element
How to do it...
How it works...
Animating with easing
How to do it...
How it works...
Moving an element along a straight path
How to do it...
How it works...
Moving an element along a curved path
How to do it...
How it works...
Changing an element's color
How to do it...
How it works...
Sequencing multiple animations
How to do it...
How it works...
9. Integrating External Libraries
Introduction
Adding the jQuery framework
Getting ready
How to do it...
How it works...
Adding the MooTools framework
Getting ready
How to do it...
How it works...
Adding the Dojo framework
Getting ready
How to do it...
How it works...
Adding the Prototype framework
Getting ready
How to do it...
How it works...
Adding the script.aculo.us add-on to Prototype
Getting ready
How to do it...
How it works...
There's more…
Adding image enlargement with Lightbox 2
Getting ready
How to do it...
How it works...
There's more…
Index

Moodle JavaScript Cookbook

Moodle JavaScript Cookbook

Copyright © 2011 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, nor Packt Publishing, and its dealers and 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 of 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: April 2011

Production Reference: 1180411

Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK.

ISBN 978-1-849511-90-2

www.packtpub.com

Cover Image by Rakesh Shejwal (<[email protected]>)

Credits

Author

Alastair Hole

Reviewers

Anthony Borrow

Mauno Korpelainen

Susan Smith Nash

Acquisition Editor

Chaitanya Apte

Development Editor

Roger D'souza

Technical Editor

Azharuddin Sheikh

Copy Editor

Neha Shetty

Indexer

Hemangini Bari

Editorial Team Leader

Akshara Aware

Project Team Leader

Priya Mukherji

Project Coordinator

Srimoyee Ghoshal

Proofreader

Joel T. Johnson

Production Coordinator

Kruthika Bangera

Cover Work

Kruthika Bangera

About the Author

Alastair Hole is a web software developer, who is currently specializing in educational software, particularly that which pertains to Further and Higher Education in the UK. His web development experience began in the post dot-com boom era, working on business-to-business e-commerce web applications in the publishing industry with a focus on back-office integration. He has since transferred his talents to the educational sector and has created projects which have gone on to receive awards from organizations such as The Times Educational Supplement and the IMS Global Learning Consortium.

Alastair is the author of the award-winning Moodle IMS Content Package repository plug-in "MrCUTE—Moodle Repository: Create, Upload, Tag, & Embed", which is an Open Source project commissioned by the Joint Information Systems Committee (JISC) that has seen significant use in Moodle sites worldwide, from Scotland to Australia.

Thank you to everyone who has contributed to this book's completion, be it patience with missed deadlines or encouragement when all seemed overwhelming. Thank you, Ma and Pa Hole for their foresight in recognizing that one day I would teach myself how to reassemble everything that I have ever unscrewed, detached, disassembled, or otherwise fiddled with. Thank you to The Internet for being an ever expanding well of autodidactic opportunity. And remember, "It's just a ride. And we can change it any time we want."

About the Reviewers

Anthony Borrow, S.J. is a Jesuit of the New Orleans Province who has been active in the Moodle community for five years. Anthony has an M.A. in Counseling from Saint Louis University, and a Masters of Divinity from the Jesuit School of Theology of Santa Clara University. Anthony has worked on the design and implementation of various database systems since 1992.

Anthony serves the Moodle community as its CONTRIB Coordinator. In that role, Anthony has presented at various MoodleMoots (conferences) across the United States and provided in-house training opportunities for institutions learning how to implement Moodle. Anthony is currently the Campus Minister at Cristo Rey Jesuit College Preparatory (http://cristoreyjesuit.org/) and provides technical advice to the Jesuit Secondary Education Association (http://jsea.org) and the Jesuit Virtual Learning Academy (http://jvla.org/).

Anthony is the co-author of the Honduras chapter of Teen Gangs: A Global View, and also has been a technical reviewer of various Packt books.

I am grateful to the Moodle community for continually inspiring me to learn more about educational technologies and fostering an environment where every voice contributes to building that community.

Mauno Korpelainen teaches Mathematics for high school and adult students in Hyvinkää, Finland, has been a PHM (Particularly Helpful Moodler) for several years, and is one of the moderators of the moodle.org forums.

Susan Smith Nash is currently the Director of Education and Professional Development for the American Association of Petroleum Geologists (AAPG) in Tulsa, Oklahoma, and an adjunct professor at The University of Oklahoma. She was the Associate Dean for graduate programs at Excelsior College (Albany, NY). Previous to that, she was the Online Courses Manager at the Institute for Exploration and Development Geosciences and Director of Curriculum Development for the College of Liberal Studies, University of Oklahoma, Norman, OK, where she developed an online degree program curriculum for online courses at The University of Oklahoma. She also developed an interface for courses, as well as administrative and procedural support, support programmers, protocol and training manuals, and marketing approaches. She obtained her Ph.D. and M.A. in English and a B.S. in Geology from the University of Oklahoma. Nash blogs at E-Learning Queen (http://www.elearningqueen.com) and E-Learners, and has written articles and chapters on mobile learning, poetics, contemporary culture, and e-learning for numerous publications, including Trends and Issues in Instructional Design and Technology (3rd ed), Mobile Information Communication Technologies Adoption in Developing Countries: Effects and Implications, Talisman, Press1, International Journal of Learning Objects, GHR, World Literature, Gargoyle. Her latest books include Moodle 1.9 Teaching Techniques (Packt Publishing, 2010), E-Learners Survival Guide (Texture Press, 2009), and Klub Dobrih Dejanj (2008).

www.PacktPub.com

Support files, eBooks, discount offers and more

You might want to visit www.PacktPub.com for support files and downloads related to your book.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

http://PacktLib.PacktPub.com

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print and bookmark contentOn demand and accessible via web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

Preface

Moodle is the best e-learning solution on the block and is revolutionizing courses on the Web. Using JavaScript in Moodle is very useful for administrators and dynamic developers, as it uses built-in libraries to provide the modern and dynamic experience that is expected by web users today.

The Moodle JavaScript Cookbook will take you through the basics of combining Moodle with JavaScript and its various libraries and explain how JavaScript can be used along with Moodle. It will explain how to integrate Yahoo! User Interface Library (YUI) with Moodle. YUI will be the main focus of the book, and is the key to implementing modern, dynamic, feature-rich interfaces to help your users get a more satisfying and productive Moodle experience. It will enable you to add effects, make forms more responsive, use AJAX and animation, all to create a richer user experience. You will be able to work through a range of YUI features, such as pulling in and displaying information from other websites, enhancing existing UI elements to make users' lives easier, and even adding animation to your pages for a nice finishing touch.

What this book covers

Chapter 1, Combining Moodle and JavaScript. In this chapter, we will learn the basic techniques for integrating our JavaScript code with Moodle 2.0. We will learn several methods of including our JavaScript code in a Moodle page through .js files, and how to get the code to run. Lastly, we will look at some best practices and also how to make Moodle data and language strings available to our JavaScript code.

Chapter 2, Moodle and Yahoo! User Interface Library (YUI). In this chapter, we will learn the basics of working with YUI. We will learn how to initialize the YUI and make it ready for use within our code and load additional modules from both Version 2 and 3 of the YUI. We will also learn how to manage the execution of code by attaching events to our controls, and finally how to debug our code with YUI logging tools.

Chapter 3, Moodle Forms Validation. Moodle provides a feature-rich web forms utility based on the PHP Extension and Application Repository (PEAR) library, QuickForm. Forms produced in Moodle not using this library are an exception. So, in this chapter, we will learn how to activate the built-in JavaScript form validation functions, and also how to add our own custom JavaScript form validation logic.

Chapter 4, Manipulating Data with YUI 3. In this chapter, we will look at the ways in which we can use JavaScript and YUI to retrieve and display data from a range of different sources. Using these techniques, we can integrate all types of data into our Moodle applications—from weather forecasts, stock updates, and news feeds to any type of custom text-based data you may have from external systems, and even data from Moodle itself (both the local Moodle system and any remote systems that your code is authorized to access), retrieved through Moodle's web services API.

Chapter 5, Working with Data Tables. Database driven applications, such as Moodle require efficient methods of displaying data to users, for example a table of assignment grades, or other recent user activity. This typically takes the form of an HTML table, the familiar grid of columns and rows in the style of a spreadsheet. So in this chapter, we will learn how to initialize a YUI DataSource, display data, sort columns, add paging, and enable scrolling and editing.

Chapter 6, Enhancing Page Elements. The Yahoo! UI Library (YUI) offers a range of widgets and utilities to bring modern enhancements to your traditional page elements. In this chapter, we will look at a selection of these, including features often seen on modern interactive interfaces such as auto-complete, auto-update, custom tooltips, and so on.

Chapter 7, Advanced Layout Techniques. In this chapter, we will look at a selection of techniques available that are designed to enhance the way in which users interact with our content. First of all, we will look at the different ways in which we can present a navigation menu, giving the user a convenient list of the content that we are making available to them. Secondly, we will look at two different ways in which we can present the actual content to which they have navigated. We will also look at methods of enhancing the display and navigation of page content, by extending existing markup in keeping with the concept of "progressive enhancement".

Chapter 8, Animating Components. Animation can provide beneficial effects in a range of situations. So, in this chapter, we will look at how to bring elements on our pages to life with the use of animation.

Chapter 9, Integrating External Libraries. In this chapter, we will look at the methods available to us for integrating external JavaScript libraries. We will also look at how to setup some of the more commonly used frameworks, and implement a basic "content ready" event handler for each one. Finally, we will look at some extensions for the Prototype framework, namely the script.aculo.us add-on, and we will finish by implementing the Lightbox image-viewer extension.

What you need for this book

To work with the code provided with the recipes in this book, you will need an installation of Moodle 2.0 to run the code along with your favorite text editor for making any changes. Visit http://moodle.org/ for downloading links and installation instructions for Moodle 2.0.

Who this book is for

This book is aimed at developers and administrators comfortable with customizing Moodle with the use of plugin modules, themes, and patches who want to make their site more dynamic. If you have prior knowledge of HTML, PHP, and CSS and a good working knowledge of the underlying structure of Moodle, then this book is for you. No prior experience with JavaScript is needed.

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 will create a simple MooTools script that will display a JavaScript alert when the domready event is fired."

A block of code is set as follows:

window.addEvent('domready', function() { alert('Hello from MooTools'); });

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

{ key: "title", label: "Title", formatter: "string", sortable: true }

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "When the user clicks on the Show panel button, the window's show method is called".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.