Skip Ribbon Commands
Skip to main content

Vardhaman Deshpande | zevenseas | SharePoint Blog

:

Vardhaman Deshpande | zevenseas | SharePoint Blog > Posts > Working with CoffeeScript on SharePoint : Interacting through jQuery
January 31
Working with CoffeeScript on SharePoint : Interacting through jQuery

​Now in this next part, lets see how CoffeeScript can be used with jQuery on SharePoint:
Lets start with the most nifty feature first:

$(document).ready(function () { 
    //Code here.
});
is now:
$ ->
//Code here. 
CoffeeScript makes it extremely easy to iterate over jQuery collections using the for loop:
#All the hrefs are extracted from all the anchor links on the page and stored in the array 'anchorHrefs'
anchorHrefs = anchor.href for anchor in $("a")
Simple demo using CoffeeScript with jQuery to create a button, append it after the SP ribbon and assign a click function to it:
#Create a new button
myButton = $("<input id='cfLink' type='button' value='Click Me'/>")
#Assign a click function to the button which sends the button itself as the first parameter
myButton.click -> linkClicked (this)

#Push myLink into the DOM after the ribbon container.
$("#s4-ribbonrow").after myButton

#When this function is called, alert the value attribute of the button.
linkClicked = (button) ->
alert button.value
I hope you have enjoyed the series as much as me. Please feel free to leave me any feedback through comments or email. Happy Exploring!

GitHub Link to the project:
https://github.com/vman/SPCoffeeScript

Comments

There are no comments for this post.

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


ReCaptcha

 

Attachments

 

 Statistics

 
Views: 21772
Comments: 0
Tags:
Published:477 Days Ago