Posts
json serializer in Sharepoint
There is a very handy JSON lib for serializing javascript objects. It is hosted on github under douglas crockford. Download json2.js and serialize with JSON.stringify function: EDIT: There is actually this function in core javascript. It exists since javascript 1.7 and ecmascript 5. So you don’t have to add anything to get this functionality:
var t = { name: "dev", city: "new york" }; JSON.stringify(t); ```There are actually built-in goodies for serializing javascript objects in [ASP.
Posts
Playing with play!
play! framework Inspired by ComputerSweden I played with Play! Here I’ll just put some commands to create and deploy a Play! web application, actually more for myself, to remember the steps to get started quickly. It would be great of course, if someone else finds it useful. The code for this little simple app. Play! is a java based framework for web applications. It reminds the rails framework and provides many useful features as CRUD, REST and more out of the box.
Posts
Load Profile Image with javascript
See a great post in “Learning Sharepoint” with an example how to get a picture of user with Client Object Model and javascript.
Posts
Get Distinguished Name for a user
To get the distinguished name for a user, it isn’t enough to get an SPUser object. The distinguished name is the unique string for identifying a user in Active Directory (eg. CN=BeforeDAfter,OU=Test,DC=North America,DC=Fabrikam,DC=COM) Even using UserProfile object is not that clear. The distinguished name can be found in a property which can be retrieved with brackets: up[PropertyConstants.DistinguishedName]
public static string GetDistinguishedName(string login) { var dn = ""; UserProfile up; using (var site = new SPSite("http://dev")) { var serviceContext = SPServiceContext.
Posts
css3 transform
See Richards Bradshaw’s page with explanations and examples of css3 transform and transitions. His code is also available for forking on Github.
Posts
jQuery timeago and the localization
If you have used SPUtility.TimeDeltaAsString you must know how useful it is. There is also the jQuery plugin that can perform counting of time deltas and (!) translate it. jQuery timeago is available for many languages, Swedish among others:
// Swedish jQuery.timeago.settings.strings = { prefixAgo: "för", prefixFromNow: "om", suffixAgo: "sedan", suffixFromNow: "", seconds: "mindre än en minut", minute: "ungefär en minut", minutes: "%d minuter", hour: "ungefär en timme", hours: "ungefär %d timmar", day: "en dag", days: "%d dagar", month: "ungefär en månad", months: "%d månader", year: "ungefär ett år", years: "%d år" }; ```The code is hosted on [Github](https://github.
Posts
Filtering in javascript
The simplest and the best way to filter an array is to extend the Array.prototype as described here:
if (!Array.prototype.filter) { Array.prototype.filter = function (func) { var len = this.length; if (typeof func != "function") throw new TypeError(); var res = new Array(); var thisp = arguments\[1\]; for (var i = 0; i < len; i++) { if (i in this) { var val = this\[i\]; if (func.call(thisp, val, i, this)) res.
Posts
Extend an event in javascript
If you use jQuery, you don’t need it. But if you for some reason must use javascript you must beware of adding events. The most dangerous is window.onload. Consider this scenario:
function doSomethingGreat() {}; window.onload = doSomethingGreat; ```It works fine if you are the only person who writes window.onload handler. But on such platforms like SharePoint you can't know which events exist. And if you just write **window.onload = doSomethingGreat;** you override all other window.
Posts
Sorting Dates in javascript
To sort an array in javascript, just run sort():
array = \["skåne", "blekinge", "halland"\]; array.sort(); ```To [perform a more intelligent sorting](http://stackoverflow.com/questions/3859239/sort-json-by-date "See the original answer in stackoverflow") we can define our sorting logic. What if an array has objects with different properties? For example, an object has title and lastupdated. We want to sort on lastupdated. Just create a function for this with two parameters: function custom_sort(a, b) { return new Date(a.
Posts
Google Analytics in Sharepoint
Google Analytics is a popular and mature tool for monitoring network activities on your site. Why not use it in Sharepoint? Dave Coleman and Mike Knowles provide good guides for doing that. There is a promising plugin to SP SPGoogleAnalytics which integrates both and provides an easy interface to put GA to your SharePoint installation and see the data directly on your intranet. It comes from codeplex: What do you think about spgoogleanalytics.