E-Book, Englisch, 400 Seiten
Lengstorf Pro PHP and jQuery
1. ed
ISBN: 978-1-4302-2848-6
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
E-Book, Englisch, 400 Seiten
ISBN: 978-1-4302-2848-6
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
This book is for intermediate programmers interested in building Ajax web applications using jQuery and PHP. Along with teaching some advanced PHP techniques, it will show you how to take your dynamic applications to the next level by adding a JavaScript layer with jQuery. Learn to utilize built-in PHP functions to build calendar tools. Learn how jQuery can be used for Ajax, animation, client-side validation, and more.
Jason Lengstorf is a 27-year-old turbogeek from Portland, OR. He started building websites in his late teens when his band couldn t afford to pay someone to do it, and he continued building websites after he realized his band wasn t actually very good. He s been a full-time freelance web developer since 2007, and expanded his business under the name Copter Labs, which is now a distributed freelance collective, keeping about 10 freelancers worldwide busy. He is also the author of PHP for Absolute Beginners and Pro PHP and jQuery.
Autoren/Hrsg.
Weitere Infos & Material
1;Title Page;1
2;Copyright page;2
3;Contents at a Glance;3
4;Table of Contents;4
5;About the Author;11
6;About the Technical Reviewer;12
7;Acknowledgments;13
8;PART 1 Getting Comfortable with jQuery;14
9;CHAPTER 1 Introducing jQuery;15
9.1;Choosing jQuery over JavaScript;15
9.1.1;Understanding JavaScript Libraries;15
9.1.2;Understanding the Benefits of jQuery;16
9.1.3;Understanding the History of jQuery;16
9.2;Setting Up a Testing Environment;16
9.2.1;Installing Firefox;17
9.2.2;Installing Firebug;17
9.3;Including jQuery in Web Pages;19
9.3.1;Including a Downloaded Copy of the jQuery Library;19
9.3.2;Including a Remotely Hosted Copy of the jQuery Library;20
9.3.3;Using the Google AJAX Libraries API;20
9.4;Setting up a Test File;20
9.4.1;Introducing the jQuery Function ($);21
9.4.2;Selecting DOM Elements Using CSS Syntax;22
9.4.2.1;Basic Selectors;23
9.4.2.2;Hierarchy Selectors;25
9.4.2.3;Basic Filters;27
9.4.2.4;Content Filters;29
9.4.2.5;Visibility Filters;31
9.4.2.6;Attribute Filters;31
9.4.2.7;Child Filters;32
9.4.2.8;Form Filters;33
9.5;Summary;35
10;CHAPTER 2 Common jQuery Actions and Methods;36
10.1;Understanding the Basic Behavior of jQuery Scripts;36
10.2;Understanding jQuery Methods;36
10.2.1;Traversing DOM Elements;37
10.2.1.1;.eq();37
10.2.1.2;.filter() and .not();38
10.2.1.3;.first() and .last();38
10.2.1.4;.has();39
10.2.1.5;.is();39
10.2.1.6;.slice();39
10.2.1.7;.children();40
10.2.1.8;.closest();41
10.2.1.9;.find();41
10.2.1.10;.next(), .nextAll(), and .nextUntil();41
10.2.1.11;.prev(), .prevAll(), and .prevUntil();43
10.2.1.12;.siblings();43
10.2.1.13;.parent();44
10.2.1.14;.parents() and .parentsUntil();44
10.2.1.15;.add();45
10.2.1.16;.andSelf();46
10.2.1.17;.contents();46
10.2.1.18;.end();47
10.2.2;Creating and Inserting DOM Elements;47
10.2.2.1;Creating New DOM Elements;49
10.2.2.2;Inserting New Elements into the DOM;50
10.2.2.3;.remove() and .detach();63
10.2.3;Accessing and Modifying CSS and Attributes;64
10.2.3.1;.attr();64
10.2.3.2;.removeAttr();65
10.2.3.3;.css();66
10.2.3.4;.val();68
10.2.3.5;.data();69
10.2.3.6;.addClass(), .removeClass(), and .toggleClass();70
10.2.3.7;.hasClass();71
10.2.3.8;.height() and .width();72
10.2.3.9;.innerHeight(), .innerWidth(), .outerHeight(), and .outerWidth();73
10.2.4;Affecting Result Sets;73
10.2.4.1;.map() and .each();74
10.2.5;Using Animation and Other Effects;76
10.2.5.1;.show() and .hide();76
10.2.5.2;.fadeIn(), .fadeOut(), and .fadeTo();77
10.2.5.3;.slideUp(), .slideDown(), and .slideToggle();78
10.2.5.4;.animate();78
10.2.5.5;.delay();81
10.2.5.6;.stop();81
10.2.6;Handling Events;82
10.2.6.1;Browser Events;82
10.2.6.2;Handling Document Loading Events;83
10.2.6.3;Handling Event Attachment;84
10.2.6.4;Shortcut Event Methods;88
10.2.7;Using AJAX Controls;89
10.2.7.1;$.ajax();89
10.2.7.2;$.ajaxSetup();91
10.2.7.3;Using Shorthand AJAX Methods;93
10.3;Summary;95
11;PART 2 Getting Into Advanced PHP Programming;96
12;CHAPTER 3 Object-Oriented Programming;97
12.1;Understanding Object-Oriented Programming;97
12.2;Understanding Objects and Classes;97
12.2.1;Recognizing the Differences Between Objects and Classes;98
12.2.2;Structuring Classes;98
12.2.3;Defining Class Properties;99
12.2.4;Defining Class Methods;100
12.2.4.1;Using Constructors and Destructors;103
12.2.4.2;Converting to a String;106
12.2.5;Using Class Inheritance;109
12.2.5.1;Overwriting Inherited Properties and Methods;110
12.2.5.2;Preserving Original Method Functionality While Overwriting Methods;112
12.2.6;Assigning the Visibility of Properties and Methods;113
12.2.6.1;Public Properties and Methods;113
12.2.6.2;Protected Properties and Methods;114
12.2.6.3;Private Properties and Methods;117
12.2.6.4;Static Properties and Methods;118
12.2.7;Commenting with DocBlocks;120
12.3;Comparing Object-Oriented and Procedural Code;122
12.3.1;Ease of Implementation;123
12.3.1.1;The Procedural Approach;123
12.3.1.2;The OOP Approach;125
12.3.2;Better Organization;127
12.3.3;Easier Maintenance;127
12.4;Summary;128
13;CHAPTER 4 Build an Events Calendar;129
13.1;Planning the Calendar;129
13.1.1;Defining the Database Structure;129
13.1.2;Creating the Class Map;129
13.1.3;Planning the Application’s Folder Structure;130
13.1.3.1;Public Files;130
13.1.3.2;Nonpublic Application Files;131
13.1.4;Modifying the Development Environment;132
13.1.4.1;Local Development;132
13.1.4.2;Remote Development;134
13.2;Building the Calendar;134
13.2.1;Creating the Database;134
13.2.2;Connecting to the Database with a Class;135
13.2.3;Creating the Class Wrapper;137
13.2.4;Adding Class Properties;137
13.2.5;Building the Constructor;139
13.2.5.1;Checking the Database Connection;140
13.2.5.2;Creating an Initialization File;142
13.2.5.3;Creating an Index File to Pull It All Together;143
13.2.5.4;Setting Basic Properties;144
13.2.6;Loading Events Data;146
13.2.6.1;Creating an Array of Event Objects for Use in the Calendar;149
13.2.6.2;Creating an Event Class;150
13.2.6.3;Creating the Method to Store Event Objects in an Array;152
13.2.7;Outputting HTML to Display the Calendar and Events;153
13.2.7.1;Modifying the Index File;155
13.2.7.2;Building the Calendar;156
13.2.7.3;Displaying Events in the Calendar;161
13.2.7.4;Making the Calendar Look Like a Calendar;164
13.2.7.5;Creating the Common Files—Header and Footer;168
13.2.7.6;Adding the Files to the Index;168
13.2.8;Outputing HTML to Display Full Event Descriptions;170
13.2.8.1;Creating a Method to Format Single Event Data;170
13.2.8.2;Creating a Method to Generate Markup;172
13.2.8.3;Creating a New File to Display Full Events;174
13.3;Summary;176
14;CHAPTER 5 Add Controls to Create, Edit, and Delete Events;177
14.1;Generating a Form to Create or Edit Events;177
14.1.1;Adding a Token to the Form;179
14.1.2;Creating a File to Display the Form;181
14.1.3;Adding a New Stylesheet for Administrative Features;182
14.2;Saving New Events in the Database;186
14.2.1;Adding a Processing File to Call the Processing Method;189
14.2.2;Adding a Button to the Main View to Create New Events;191
14.3;Adding Edit Controls to the Full Event View;195
14.3.1;Modifying the Full Event Display Method to Show Admin Controls;197
14.3.2;Adding the Admin Stylesheet to the Full Event View Page;198
14.4;Deleting Events;200
14.4.1;Generating a Delete Button;201
14.4.2;Creating a Method to Require Confirmation;202
14.4.3;Creating a File to Display the Confirmation Form;205
14.5;Summary;208
15;CHAPTER 6 Password Protecting Sensitive Actions and Areas;209
15.1;Building the Admin Table in the Database;209
15.2;Building a File to Display a Login Form;210
15.3;Creating the Admin Class;212
15.3.1;Defining the Class;212
15.3.2;Building a Method to Check the Login Credentials;213
15.3.2.1;Building a Method to Create Salted Hashes;217
15.3.2.2;Creating a Test Method for Salted Hashes;220
15.3.2.3;Creating a User to Test Administrative Access;222
15.3.3;Modifying the App to Handle the Login Form Submission;223
15.4;Allowing the User to Log Out;228
15.4.1;Adding a Log Out Button to the Calendar;228
15.4.2;Creating a Method to Process the Logout;230
15.4.3;Modifying the App to Handle the User Logout;231
15.5;Displaying Admin Tools Only to Administrators;233
15.5.1;Showing Admin Options to Administrators;233
15.5.1.1;Modifying the General Admin Options Method;234
15.5.1.2;Modifying the Event Options Method;236
15.5.2;Limiting Access to Administrative Pages;238
15.5.2.1;Disallowing Access to the Event Creation Form Without Login;238
15.5.2.2;Ensuring Only Logged In Users Can Delete Events;239
15.6;Summary;241
16;PART 3 Combining jQuery with PHP Applications;242
17;CHAPTER 7 Enhancing the User Interface with jQuery;243
17.1;Adding Progressive Enhancements with jQuery;243
17.1.1;Setting Progressive Enhancement Goals;244
17.2;Include jQuery in the Calendar App;244
17.2.1;Create a JavaScript Initialization File;245
17.2.1.1;Include the Initialization File in the Application;245
17.2.1.2;Ensuring the Document Is Ready Before Script Execution;245
17.2.2;Creating a New Stylesheet for Elements Created by jQuery;245
17.2.2.1;Including the Stylesheet in the Index File;247
17.3;Creating a Modal Window for Event Data;248
17.3.1;Binding a Function to the Click Event of Title Links;248
17.3.2;Preventing the Default Action and Adding an Active Class;248
17.3.3;Extracting the Query String with Regular Expressions;249
17.3.3.1;Using the Lazy Approach: String-Based Replacement;249
17.3.3.2;Adopting a Better Solution: Regular Expressions;249
17.3.3.3;Incorporating a Regular Expression into a Script;250
17.3.4;Creating a Modal Window;251
17.3.4.1;Creating the Utility Function to Check for a Modal Window;251
17.3.4.2;Calling the Utility Function from the Event Handler;253
17.3.5;Retrieve and Display Event Information with AJAX;255
17.3.5.1;Creating a File to Handle AJAX Requests;256
17.3.5.2;Loading Event Data Using AJAX;258
17.3.6;Add a Close Button;261
17.3.7;Add Effects to the Creation and Destruction of the Modal Window;262
17.3.7.1;Fade Out the Modal Window;263
17.3.7.2;Adding an Overlay and Fade in the Modal Window;265
17.4;Summary;270
18;CHAPTER 8 Editing the Calendar with AJAX and jQuery;271
18.1;Opening the Event Creation Form;271
18.1.1;Adding an AJAX Call to Load the Form;272
18.1.2;Modifying the AJAX Processing File to Load the Form;273
18.1.3;Making the Cancel Button Behave Like the Close Button;276
18.2;Saving New Events in the Database;277
18.2.1;Serializing the Form Data;278
18.2.2;Submitting the Serialized Form Data to the Processing File;279
18.2.3;Modifying the AJAX Processing File to Handle New Submissions;279
18.3;Adding Events Without Refreshing;281
18.3.1;Deserializing the Form Data;282
18.3.1.1;Decode Any URL-Encoded Characters in Form Values;284
18.3.1.2;Bring It All Together;286
18.3.2;Creating Date Objects;287
18.3.2.1;Modifying the Calendar Class with an ID;287
18.3.2.2;Building Date Objects in JavaScript;288
18.3.2.3;Fixing Timezone Inconsistencies;289
18.3.2.4;Ensuring the Event Occurs in the Current Month;290
18.3.3;Appending the Event to the Calendar;291
18.3.4;Getting the New Event’s ID;294
18.3.4.1;Modifying the Event Creation Method to Return New Event IDs;295
18.4;Editing Events in a Modal Window;298
18.4.1;Determining the Form Action;299
18.4.2;Storing the Event ID if One Exists;300
18.4.2.1;Adding the Event ID to the Query String;301
18.4.3;Remove Event Data from the Modal Window;302
18.4.4;Ensuring Only New Events Are Added to the Calendar;304
18.5;Confirming Deletion in a Modal Window;306
18.5.1;Displaying the Confirmation Dialog;306
18.5.2;Configuring the Form Submission Event Handler for Deletion;309
18.5.2.1;Modifying the Processing File to Confirm Deletion;310
18.5.3;Remove the Event from the Calendar After Deletion;312
18.5.3.1;Modifying the Form Submission Handler to Remove Deleted Events;313
18.6;Summary;315
19;PART 4 Advancing jQuery and PHP;316
20;CHAPTER 9 Performing Form Validation with Regular Expressions;317
20.1;Getting Comfortable with Regular Expressions;317
20.1.1;Understanding Basic Regular Expression Syntax;317
20.1.1.1;Setting up a Test File;318
20.1.1.2;Replacing Text with Regexes;319
20.1.1.3;Choosing Regexes vs. Regular String Replacement;320
20.1.2;Drilling Down on the Basics of Pattern Modifiers;322
20.1.3;Getting Fancy with Backreferences;324
20.1.4;Matching Character Classes;326
20.1.4.1;Matching Any Character Except...;328
20.1.4.2;Using Character Class Shorthand;329
20.1.5;Finding Word Boundaries;329
20.1.6;Using Repetition Operators;329
20.1.7;Detecting the Beginning or End of a String;330
20.1.8;Using Alternation;330
20.1.9;Using Optional Items;331
20.1.10;Putting It All Together;332
20.2;Adding Server-Side Date Validation;334
20.2.1;Defining the Regex Pattern to Validate Dates;334
20.2.1.1;Setting up Test Data;334
20.2.1.2;Matching the Date Format;336
20.2.2;Adding a Validation Method to the Calendar Class;339
20.2.3;Returning an Error if the Dates Don’t Validate;340
20.3;Adding Client-Side Date Validation;344
20.3.1;Creating a New JavaScript File to Validate the Date String;344
20.3.2;Including the New File in the Footer;345
20.3.3;Preventing the Form Submission if Validation Fails;345
20.4;Summary;349
21;CHAPTER 10 Extending jQuery;350
21.1;Adding Functions to jQuery;350
21.1.1;Adding Your Date Validation Function to jQuery;350
21.1.1.1;Allowing Custom Aliases in jQuery Plugins;350
21.1.1.2;Attaching the Function to the jQuery Object;351
21.1.1.3;Allowing Configurable Options;351
21.1.1.4;Extending Default Options with User-Supplied Options;352
21.1.1.5;Performing Validation and Returning a Value;353
21.1.1.6;Conforming to jQuery Plugin File Naming Conventions;353
21.1.2;Modifying the Include Script;353
21.1.3;Modifying the Initialization Script;354
21.2;Adding Methods to jQuery;356
21.2.1;Building Your Plugin;356
21.2.1.1;Creating a Properly Named Plugin File;356
21.2.1.2;Providing Publicly Accessible Default Options;357
21.2.1.3;Maintaining Chainability;358
21.2.1.4;Creating a Publicly Accessible Helper Method;359
21.2.1.5;Modifying Each Matched Element;361
21.2.2;Implementing Your Plugin;362
21.2.2.1;Including the Plugin File;362
21.2.2.2;Initializing the Plugin on a Set of Elements;363
21.3;Summary;365
22;Index;366




