This project has moved and is read-only. For the latest updates, please go here.

jQuery version in the works, need your feedback

Mar 20, 2013 at 4:07 AM
I think we can all agree at this point that the majority of people would prefer to use jQuery over prototype.js.

I wanted to let everyone know that I'm currently working on a version of SPUtility.js relies on jQuery instead.

Right now, the API is the same but I am considering implementing a new API.. namely because it could be more consistent with jQuery standards.

This would mean that changes would need to be made to existing code if you wanted to switch to use the jQuery version. Before I do though, I wanted to put it out there to the community:
  1. Do you want to switch from the prototype.js version to the jQuery version?
  2. If so, would a different API significantly impact you / prevent you from switching?
If you have any feedback let me know!
Mar 21, 2013 at 2:42 PM
Hello,

First of all, kudos to your great effort!

Coming back to your question, I would suggest creating the JQuery version for SharePoint 2013 onwards and you could leave the existing version for SP2010 and SP2007

Cheers,
Mar 22, 2013 at 4:25 AM
Thanks. :)

That is sort of what I was leaning towards. I get the impression that people won't really need to upgrade... if someone is currently using SPUtility.js then it probably is working fine for them right now.

I am figuring out if I can get access to a 2013 environment. Hopefully I can still support all three versions though! We shall see.
Feb 7, 2014 at 4:04 PM
Edited Feb 7, 2014 at 4:33 PM
Hello,

I'd like to submit 2 bug fixings and 2 new features.
  1. Bug: SPUserField, it misses the "#" part (around line 1286)
this.upLevelDiv = $("#" + this.spanUserField.id + '_upLevelDiv');
this.textareaDownLevelTextBox = $("#" + this.spanUserField.id + '_downlevelTextBox');
this.linkCheckNames = $("#" +this.spanUserField.id + '_checkNames');
this.txtHiddenSpanData = $("#" +this.spanUserField.id + '_hiddenSpanData');
GetValue() (line 1291)
this.GetValue = function () {
     var peopleSpans = this.upLevelDiv.find('span.ms-entity-resolved');
     if (peopleSpans.length > 0) {
        return arrayToSemicolonList(peopleSpans);
     }
     return '';
};
  1. Feature: add Description to SPField (line 377)
    This expose the Description of a field as a text element.
this.Description = (function(ctls) { var c = ctls.childNodes[ctls.childNodes.length-1]; return (c.nodeType!=3 || $(c).text().replace(/\s/g,'').length == 0)? null : c; })(fieldParams.controlsCell);
  1. Feature: registering "change" event in SPUserField (line 1334, at the bottom of SPUserField class)
var currentValue = null;
this.OnChange = function(fn) {
      var handler = getMethodName(fn) + "()";
      $(this.upLevelDiv[0], this.textareaDownLevelTextBox[0]).attr("onvaluesetfrompicker", handler);

      currentValue = this.GetValue();
      this.upLevelDiv.blur($.proxy(function() {
           if (this.GetValue() !== currentValue) {
               currentValue = this.GetValue();
               fn();
           }
      }, this));
};
Usage:
SPUtility.GetSPField("Nominated User").OnChange(requestUser);
function requestUser() {
    var val = SPUtility.GetSPField("Nominated User").GetValue();
    if (!val.length) return;
    alert(val);
}
And this method to get the list of resolved users by loginName/display Name:
this.GetUsers = function() {
    var people = [], peopleSpans = this.upLevelDiv.find('span.ms-entity-resolved');
    if (peopleSpans.length > 0) {
        $(peopleSpans).each(function () {
            var c = this.firstChild;
            people.push({ id: c.getAttribute('key'), title: c.getAttribute('displaytext') });
        });
    }
    return people;
};
Of course, feel free to rename the methods as you want.


Tested on IE 8 & Chrome
Feb 7, 2014 at 7:25 PM
Thanks, I'll take a look at adding these changes to the library.
Feb 8, 2014 at 11:04 PM
FYI... I'm going to track issues with the jQuery version in the GitHub repository. I've copied your comment over there: https://github.com/kitmenke/sputility/issues/3