New GitHub Repository for KnockoutJS Binding Handlers
Yesterday I created a new GitHub repo for KnockoutJS binding handlers for use with SharePoint. I’ve been using KnockoutJS for over a year now, and love working with it to build Single Page Application (SPAs) and other interactive functionality inside SharePoint.
I thought starting a repo that could store bindingHandlers for KnockoutJS that are generally useful for working with SharePoint would be useful for a lot of people.
See the Creating custom bindings section of the KnockoutJS documentation for an overview on what binding handlers are all about.
I’ve collected some of these binding handlers and built others. Where possible, I give credit to the source in each file. Unfortunately, in my first year or so of using KnockoutJS, I collected a lot of these without maintaining the source location. If you see your work here, please let me know and I will give you credit!
- /src contains one file per bindingHandler
- /html contains example usage of the corresponding bindingHandler
If you’ve been working with KnockoutJS and SharePoint and would like to contribute, feel free to issue a pull request. I’m hoping this will become a repo that is useful for the SharePoint community as well as the KnockoutJS community at large.
I’m also very open to suggestions on how to structure the repo to make it optimally useful. To get things rolling, I’ve posted some of the simpler binding handlers I use, most of which help in working with jQueryUI capabilities.
I have some good ones I could add. One of them binds to an input and allows you to async upload files to a document library. I need to go back and dig through my code.
Great, Bryan!
M.
Could the GitHub repo link to a JSFiddle for some of your custom bindings? Workable examples could always help.
For example the jqDatePicker: https://jsfiddle.net/jkerski/34daz78s/
Only downside is any specific references to SharePoint links/libraries won’t work. Unless somebody knows a way to do it (Office 365?).
John:
This is always a struggle with SharePoint. I’m still running a public-facing WSS 3.0 site at FPWeb that has old demos on it. Office365 doesn’t give us a good anonymous capability.
The goal with these custom bindings is to give an assist to people who are already using KnockoutJS and would like some shortcuts. I started with these more generic bindings intentionally, but you’re right that as we get more SharePoint specific, demos will be tricky.
M.
I don’t use SharePoint, but I do use Knockout and I’d love to see more binding libraries like this. One thing I would suggest is that you make this an NPM module by adding a package.json file to your repo and then publishing it to NPM. I’m not sure how many KO users are using Browserify but I do and I find that it works really well with KO.
Jesse:
Good suggestion. Pull request? ;=) But seriously, I’m really hoping that the community can jump into this and turn it into a great resource.
How are you liking Browserify? I’m on the RequireJS bandwagon right now and it looks like they aim to accomplish similar things?
M.