Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SPSTC - SharePoint & jQuery Essentials


Published on

Updated Slide Deck for my jQuery and SharePoint presentation presented at SharePoint Saturday Twin Cities

Published in: Technology
  • You have to choose carefully. ⇒ ⇐ offers a professional writing service. I highly recommend them. The papers are delivered on time and customers are their first priority. This is their website: ⇒ ⇐
    Are you sure you want to  Yes  No
    Your message goes here
  • ◆◆◆
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

SPSTC - SharePoint & jQuery Essentials

  1. 1. SharePoint and jQuery EssentialsMark RackleyEmail: mrackley@juniper-strategy.comBlog: http://www.sharepointhillbilly.comTwitter: @mrackley
  2. 2. About Mark Rackley• SharePoint Practice Lead, Solutions Architect & Developer• 17+ years software architecture and development experience• Blogger, Writer, Speaker•• @mrackley•
  3. 3. Session Outline• What is jQuery and Why should I care?• jQuery Overview• Deployment & Development• Interacting with SharePoint & the DOM• Reading / Writing SharePoint List Data• Using Third Party Libraries• Demos3
  4. 4. What is jQuery?• What / Why jQuery? – JavaScript utility library supported by Microsoft – Don‟t have to crack open Visual Studio or deploy solutions (ideal for SharePoint online and tightly controlled environments) – It‟s the future
  5. 5. jQuery Overview• What skills do you need? – JavaScript – CSS, XML – A development background • It IS code • Uses development constructs • If you can‟t write code, your ability to do magic will be limited to what you can copy/paste – CAML, CAML, CAML… Sorry… – Ability to think outside the box • Use all the pieces together
  6. 6. Crappy Abstruse Markup Language<Query><Where> <And> <Geq><FieldRef Name="StartDate" /><ValueIncludeTimeValue="TRUE"Type="DateTime">+startDate+</Value></Geq> <Leq><FieldRef Name="EndDate" /><ValueIncludeTimeValue="TRUE"Type="DateTime">+endDate+</Value></Leq> </And></Where></Query>,
  7. 7. SharePoint & jQuery? Why?Resolves many common SharePoint complaints without having to crack open Visual Studio
  8. 8. SharePoint & jQuery? Why? “It looks like SharePoint”
  9. 9. SharePoint & jQuery? Why? “That‟s SharePoint?”
  10. 10. SharePoint & jQuery? Why?“I‟m so sorry… SharePoint can‟t do that out of the box”
  11. 11. SharePoint & jQuery? Why? “Sure, no problem”
  12. 12. SharePoint & jQuery? Why?“That will take 3 weeks???” becomes “2 days?Awesome! I love you… here, please accept thisbonus for being such a wonderful developer”
  13. 13. jQuery makes your SharePoint applications USABLE
  14. 14. jQuery Overview• What you need to be aware of – It is secure • It uses SharePoint‟s security. All scripts run with privileges of current user – It performs well… if done correctly • Reduce postbacks • Can delay queries more effectively – Privileges • They can not be elevated… thank goodness…
  15. 15. jQuery Overview• Why I hate jQuery (some days) – Too many options – Debugging – It can perform horribly – Inconsistent results – Changes in the jQuery library – It CAN harm your farm!
  16. 16. jQuery Overview – JavaScript Common MethodsJavaScript DescriptionClasses / Objects var myCar = { id: 1, make: “Jeep”, model: “Wrangler”, color: “Silver” } var vehicles = {}; vehicles[myCar.ID] = myCar;For each loops For (car in vehicles) { var thisCar = vehicles[car]; }.split() Var numbers = “1,2,3,4,5”; Var myArray = numbers.split(“,”); myArray[0] == “1”.replace() var myString = “This string has spaces”; var newString = myString.replace(/ /g,””); newString == “Thisstringhasspaces”;
  17. 17. jQuery Overview – Common MethodsMethod Description$(document).ready(function($){}) Where code execution begins after page is loaded$(“#ElementID”) Returns element with given id$(“Type[attrib=„value‟]”) Gets element of specific type and attribute value $(“input[Title=„First Name‟]”).show(), .hide(), .toggle() Shows, hides, toggles.html() Gets the raw html for an element with tags.text() Contents of an element with HTML tags stripped out
  18. 18. jQuery Overview – Common MethodsMethod Description.each(function() {}) Iterate through all elements that are found. $(“tr”).each(function() { }) would iterate through every row on the page..closest(selector) Get the first element that matches the selector, beginning at the currently element and progressing UP the DOM $("input[title=„Field Name]").closest("tr").hide();.contains() Check to see if a DOM element is within another DOM element.find() Get the child elements of current element, filtered by a selectorChaining:$("#WebPartWPDnn").find("nobr b:contains(Sum = )").html().split(" = ")[1].replace(",","");
  19. 19. Deployment• Deployment Options – Document Library • Easily modify scripts • Keep track of changes with Metadata • Recover from screw ups with Versioning • Less control, more flexibility versus other options – File System • Deployed with a WSP (don‟t think of manually copying) • Not an option for Office 365 or hosted SharePoint 2010 – CDN
  20. 20. Document Library
  21. 21. Reference Options<script type="text/javascript" src="/SiteAssets/jquery.min.js"></script>• ScriptLink • MasterPages, Delegate Controls, Web Parts, Controls, Custom Pages • Ensures Script is not loaded multiple times • Renders in the correct place in the markup • Need Visual Studio or SPD • More upfront work• Content Editor Web Part (CEWP) • Quick & Easy • Don‟t have to deploy anything • Adds CEWP overhead
  22. 22. Reference Options• Custom Action • Loads Script for entire Site Collection • Works in sandbox<?xml version="1.0" encoding="utf-8"?><Elements xmlns=""> <CustomAction ScriptSrc="~sitecollection/SiteAssets/jquery.min.js" Location="ScriptLink" Sequence="100" > </CustomAction></Elements>
  23. 23. Development• Development Tools – IDE • Visual Studio • Notepad++ • SharePoint Designer – Debugging • IE Developer Tools • Chrome debugger • Fiddler • Alerts… lots and lots of alerts • Avoid Console.log (or use it wisely)
  24. 24. Interacting with SharePoint & the DOM• View the DOM to understand what elements and classes exist on the page.• “View page source” (Chrome) and “View Source” (IE) displays the contests of the DOM when the page is initially loaded.• The DOM is always being modified, view the active DOM in your chosen debugger to view the DOM as it currently exists.
  25. 25. Interacting with SharePoint & the DOM Getting/Setting SharePoint Form Fields • Text Boxes – $(“input[title=‟My Text Field‟]”).val() • Selects – $(“select[title=‟My Choice‟]”).val(mySelectValue); • Checkboxes – $("input[title=My Check box]").removeAttr(checked); – $("input[title=My Check box]").attr(checked,checked);
  26. 26. Reading/Writing SharePoint List Data• SPServices vs. Client Object ModelFeature SPServices COMAllows CRUD against SharePoint List Data Yes YesWorks in SharePoint 2007 Yes NoWorks in SharePoint 2010 Yes YesWorks with Anonymous Access Yes NoComes with additional helper functions Yes YesWorks cross-site Yes No
  27. 27. Using Third Party Libraries• Tips for selection and integration – Look for supported / document libraries – Test in target browsers before implementing – Duplicate file structure – Test “vanilla” in SharePoint first
  28. 28. Using Third Party Libraries• Some of my favorites – Content Slider - showcase-a-jquery-plugin/ – Formatted Tables - – Modal Window - – SPServices - – Calendar -
  29. 29. DEMOSAnd Nifty Stuff
  30. 30. So, what’s the deal?
  31. 31. ”Fast Food” Development• You don‟t have to be a SharePoint Guru• It‟s Cheap• It‟s Quick• It‟s Easy• It gets the job done
  32. 32. ”Fast Food” Development• Don‟t abuse it, You‟ll pay for it later• Limited choices• There are healthier options• Adds page bloat• Can slow your performance
  33. 33. Questions? Don’t drink the haterade…Mark 33
  34. 34. SharePoint Saturday Ozarks Sept. 8, 2012 Chateau On The Lake Branson, MO