SlideShare a Scribd company logo
JavaScript and jQuery for
SharePoint Developers
Rob Windsor
rwindsor@portalsolutions.net
@robwindsor
About Me
• Senior SharePoint Architect with Portal Solutions
• Technical Contributor to the Pluralsight On-Demand Library
• Microsoft MVP, MCPD, MCT
• Founder and Past-President of the North Toronto .NET UG
• Co-author of Prof. Visual Basic 2012 and .NET 4.5 (Wrox)
Deploying JavaScript Files
• Content Delivery Network (CDN)
 Works with all project types
• Under Layouts folder
 Farm Solutions
• Virtual File System
 Virtual folder or document library
 Sandbox Solutions or Apps
Referencing JavaScript Files
• During page load:
 <script> tag
 ScriptLink control
• On demand:
 ExecuteOrDelayUntilScriptLoaded
 jQuery.getScript
• Feature activation:
 CustomAction
 Applies to entire site collection
Visual Studio Intellisense
• No Intellisense unless using <script> tag
• Visual Studio 2010
 ASPX or ASCX files
 Reference debug version of script using <script> tag
 Wrap in #if compiler directive so ignored in compiled page/control
 JavaScript files
 Use script reference
 /// <reference path=“<path or url to script file" />
• Visual Studio 2012
 Add _references.js file to project
 Must be in Scripts folder at root of project
 Add script reference
 References apply across project
JavaScript Global Namespace
• JavaScript namespaces implemented as objects
• Concept similar to namespaces in .NET
• Global namespace
 Variable and functions go here by default
 Easily “polluted”
 Keep your code out of here using:
 Nested functions
 Custom namespaces and classes
Classing Things Up
• JavaScript objects can simulate namespaces and classes
 Also addresses global namespace issue
 Feels more familiar to devs used to working in managed code
• This example uses the module pattern
// namespace
window.Pluralsight = window.Pluralsight || {};
// class
Pluralsight.Demo04 = function () {
// internal
var context = SP.ClientContext.get_current();
function getUserName() {
}
// public
return {
initialize: function () {
getUserName();
}
}
}
jQuery Promises
• Simplify asynchronous operations
function getUserName() {
var def = new jQuery.Deferred();
var user = context.get_web().get_currentUser();
context.load(user);
context.executeQueryAsync(onGetUserNameSuccess,
onGetUserNameFail);
function onGetUserNameSuccess() {
def.resolve(user.get_title());
}
function onGetUserNameFail(sender, args) {
def.reject(args.get_message());
}
return def.promise();
}
var page = new Pluralsight.Demo06();
var call = page.getUserName();
call.done(function (userName) {
var message = jQuery('#message');
message.text('Hello ' + userName);
});
call.fail(function (errorMessage) {
alert('Failed to get user name. Error:' +
errorMessage);
});
Data-binding using Templates
• Many template library options
 jQuery Templates, jsRender, Knockout
• Use “script” to define template
• Get data
• Bind data to template
<script id="products-template"
type="text/x-jsrender">
{{for #data}}
<tr>
<td>{{>#data.Title}}</td>
<td>{{>#data.UnitsInStock}}</td>
</tr>
{{/for}}
</script>
message.append("<table>");
var template = jQuery("#products-template");
message.append(template.render(result2[0].d));
message.append("</table>");
Thank You
• Big thanks to the organizers, sponsors and you for making
this event possible
• Please fill out your evaluation
• Please keep in touch
rwindsor@portalsolutions.net
@robwindsor
msmvps.com/blogs/windsor

More Related Content

PDF
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
PPTX
Advanced SharePoint Web Part Development
PPTX
Integrating SharePoint 2010 and Visual Studio Lightswitch
PPTX
SharePoint 2010 Application Development Overview
PDF
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
PDF
Advanced Asp.Net Concepts And Constructs
PDF
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
PPTX
SharePoint 2010 Client-side Object Model
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint Web Part Development
Integrating SharePoint 2010 and Visual Studio Lightswitch
SharePoint 2010 Application Development Overview
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
Advanced Asp.Net Concepts And Constructs
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
SharePoint 2010 Client-side Object Model

What's hot (20)

PDF
Practical management of development & QA environments for SharePoint 2013
PPTX
Developing Apps for SharePoint Store
PPTX
Chris O'Brien - Modern SharePoint development: techniques for moving code off...
PPTX
Introduction to the SharePoint Client Object Model and REST API
PPTX
SPTechCon 2014 How to develop and debug client side code in SharePoint
PPTX
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
PPTX
Web forms in ASP.net
DOC
Tutorial asp.net
PPTX
Introduction to Client Side Dev in SharePoint Workshop
PPTX
ASP.NET Lecture 1
PPTX
ECS19 - Vesa Juvonen - SharePoint and Office 365 Development PowerClass
PPTX
Codemotion 2013 - Designing complex applications using html5 and knockoutjs
PDF
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
PDF
WebNet Conference 2012 - Designing complex applications using html5 and knock...
PPTX
Chris OBrien - Weaving Enterprise Solutions into Office Products
PPTX
SharePoint 2013 Javascript Object Model
PPTX
Chris O'Brien - Comparing SharePoint add-ins (apps) with Office 365 apps
PPTX
Understanding and programming the SharePoint REST API
KEY
SharePoint 2010 Client Object Model
PPTX
Getting Started with SharePoint Development
Practical management of development & QA environments for SharePoint 2013
Developing Apps for SharePoint Store
Chris O'Brien - Modern SharePoint development: techniques for moving code off...
Introduction to the SharePoint Client Object Model and REST API
SPTechCon 2014 How to develop and debug client side code in SharePoint
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Web forms in ASP.net
Tutorial asp.net
Introduction to Client Side Dev in SharePoint Workshop
ASP.NET Lecture 1
ECS19 - Vesa Juvonen - SharePoint and Office 365 Development PowerClass
Codemotion 2013 - Designing complex applications using html5 and knockoutjs
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Chris OBrien - Weaving Enterprise Solutions into Office Products
SharePoint 2013 Javascript Object Model
Chris O'Brien - Comparing SharePoint add-ins (apps) with Office 365 apps
Understanding and programming the SharePoint REST API
SharePoint 2010 Client Object Model
Getting Started with SharePoint Development
Ad

Similar to JavaScript and jQuery for SharePoint Developers (20)

PDF
UKLUG 2012 - XPages, Beyond the basics
PDF
Apache DeltaSpike
PPT
Struts2-Spring=Hibernate
PDF
Apache Cayenne for WO Devs
PDF
Web Components v1
PPTX
OSH01 - Developing SharePoint Framework Solutions for the Enterprise
PPTX
Mcknight well built extensions
PPTX
JS Essence
PDF
An Introduction to Tornado
PPTX
[DanNotes] XPages - Beyound the Basics
PPTX
Advanced JavaScript
PPT
XPages -Beyond the Basics
PPTX
Advanced Web Technology.pptx
PPTX
Introduction to web application development with Vue (for absolute beginners)...
PDF
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
PPTX
SOLID Programming with Portable Class Libraries
PPTX
MVC 6 - the new unified Web programming model
PDF
Migrating to Jakarta EE 10
PDF
Intelligent Projects with Maven - DevFest Istanbul
KEY
Developing High Performance Web Apps - CodeMash 2011
UKLUG 2012 - XPages, Beyond the basics
Apache DeltaSpike
Struts2-Spring=Hibernate
Apache Cayenne for WO Devs
Web Components v1
OSH01 - Developing SharePoint Framework Solutions for the Enterprise
Mcknight well built extensions
JS Essence
An Introduction to Tornado
[DanNotes] XPages - Beyound the Basics
Advanced JavaScript
XPages -Beyond the Basics
Advanced Web Technology.pptx
Introduction to web application development with Vue (for absolute beginners)...
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
SOLID Programming with Portable Class Libraries
MVC 6 - the new unified Web programming model
Migrating to Jakarta EE 10
Intelligent Projects with Maven - DevFest Istanbul
Developing High Performance Web Apps - CodeMash 2011
Ad

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation theory and applications.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
The AUB Centre for AI in Media Proposal.docx
MYSQL Presentation for SQL database connectivity
Encapsulation theory and applications.pdf
NewMind AI Monthly Chronicles - July 2025
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing

JavaScript and jQuery for SharePoint Developers

  • 1. JavaScript and jQuery for SharePoint Developers Rob Windsor rwindsor@portalsolutions.net @robwindsor
  • 2. About Me • Senior SharePoint Architect with Portal Solutions • Technical Contributor to the Pluralsight On-Demand Library • Microsoft MVP, MCPD, MCT • Founder and Past-President of the North Toronto .NET UG • Co-author of Prof. Visual Basic 2012 and .NET 4.5 (Wrox)
  • 3. Deploying JavaScript Files • Content Delivery Network (CDN)  Works with all project types • Under Layouts folder  Farm Solutions • Virtual File System  Virtual folder or document library  Sandbox Solutions or Apps
  • 4. Referencing JavaScript Files • During page load:  <script> tag  ScriptLink control • On demand:  ExecuteOrDelayUntilScriptLoaded  jQuery.getScript • Feature activation:  CustomAction  Applies to entire site collection
  • 5. Visual Studio Intellisense • No Intellisense unless using <script> tag • Visual Studio 2010  ASPX or ASCX files  Reference debug version of script using <script> tag  Wrap in #if compiler directive so ignored in compiled page/control  JavaScript files  Use script reference  /// <reference path=“<path or url to script file" /> • Visual Studio 2012  Add _references.js file to project  Must be in Scripts folder at root of project  Add script reference  References apply across project
  • 6. JavaScript Global Namespace • JavaScript namespaces implemented as objects • Concept similar to namespaces in .NET • Global namespace  Variable and functions go here by default  Easily “polluted”  Keep your code out of here using:  Nested functions  Custom namespaces and classes
  • 7. Classing Things Up • JavaScript objects can simulate namespaces and classes  Also addresses global namespace issue  Feels more familiar to devs used to working in managed code • This example uses the module pattern // namespace window.Pluralsight = window.Pluralsight || {}; // class Pluralsight.Demo04 = function () { // internal var context = SP.ClientContext.get_current(); function getUserName() { } // public return { initialize: function () { getUserName(); } } }
  • 8. jQuery Promises • Simplify asynchronous operations function getUserName() { var def = new jQuery.Deferred(); var user = context.get_web().get_currentUser(); context.load(user); context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail); function onGetUserNameSuccess() { def.resolve(user.get_title()); } function onGetUserNameFail(sender, args) { def.reject(args.get_message()); } return def.promise(); } var page = new Pluralsight.Demo06(); var call = page.getUserName(); call.done(function (userName) { var message = jQuery('#message'); message.text('Hello ' + userName); }); call.fail(function (errorMessage) { alert('Failed to get user name. Error:' + errorMessage); });
  • 9. Data-binding using Templates • Many template library options  jQuery Templates, jsRender, Knockout • Use “script” to define template • Get data • Bind data to template <script id="products-template" type="text/x-jsrender"> {{for #data}} <tr> <td>{{>#data.Title}}</td> <td>{{>#data.UnitsInStock}}</td> </tr> {{/for}} </script> message.append("<table>"); var template = jQuery("#products-template"); message.append(template.render(result2[0].d)); message.append("</table>");
  • 10. Thank You • Big thanks to the organizers, sponsors and you for making this event possible • Please fill out your evaluation • Please keep in touch rwindsor@portalsolutions.net @robwindsor msmvps.com/blogs/windsor