/* Name: SPUtility.js Version: 0.14.2 Built: 2016-04-19 Author: Kit Menke https://sputility.codeplex.com/ Copyright (c) 2016 License: The MIT License (MIT) */ Object.create||(Object.create=function(a){function b(){}if(arguments.length>1)throw new Error("Object.create implementation only accepts the first parameter.");return b.prototype=a,new b});var SPUtility=function(a){"use strict";function b(){return null===X&&(X=a("table.ms-formtoolbar input[value='Close']").length>=1),X}function c(){return navigator.userAgent.toLowerCase().indexOf("msie")>=0}function d(a){return"undefined"==typeof a}function e(a){return"string"==typeof a}function f(a){return"number"==typeof a}function g(a){return parseInt(a,10)}function h(a){return a.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1")}function i(a,b,c){return a.replace(new RegExp(h(b),"g"),c)}function j(a){return"string"==typeof a&&(a=i(a," ",""),a=i(a,Z.thousandsSeparator,""),a=a.replace(Z.decimalSeparator,"."),a=parseFloat(a)),a}function k(a){return String(a).replace(/&/g,"&").replace(/"/g,""").replace(/''/g,"'").replace(//g,">")}function l(){return 15===Y}function m(a,b,c,d){b=isNaN(b=Math.abs(b))?2:b,c=void 0===c?Z.decimalSeparator:c,d=void 0===d?Z.thousandsSeparator:d;var e=0>a?"-":"",f=parseInt(a=Math.abs(+a||0).toFixed(b),10)+"",g=(g=f.length)>3?g%3:0;return e+(g?f.substr(0,g)+d:"")+f.substr(g).replace(/(\d{3})(?=\d)/g,"$1"+d)+(b?c+Math.abs(a-f).toFixed(b).slice(2):"")}function n(b){if(null===b.Controls)return null;var c=a(b.Controls).find("input");if(null!==c&&1===c.length)return c[0];throw"Unable to retrieve the input control for "+b.Name}function o(b,c){var d,e=[],f=a(b.Controls).find(c),g=a(b.Controls).find("label");if(g.length0&&(c.type=f[0]);var g=e.match(/FieldName="[^"]+/);null!==g&&g.length>0&&(c.name=g[0].substring(11));var h=e.match(/FieldInternalName="\w+/);null!==h&&h.length>0&&(c.internalName=h[0].substring(19));break}null===c.type&&a(b).find("select[name$=ContentTypeChoice]").length>0&&(c.type="ContentTypeChoice",c.internalName="ContentType",c.name="Content Type")}function r(b){var c=null,d=null,e=a(b).siblings(".ms-formlabel");if(null!==e){var f=e.children("h3");if(c=f.length>0?f[0]:e,null!==c&&"NOBR"!==c.nodeName){var g=a.trim(a(c).text());g.length>2&&" *"===g.substring(g.length-2)&&(d=!0)}}var h={name:null,internalName:null,label:null!==c?a(c):null,labelRow:null!==c?c.parentNode:null,labelCell:e,isRequired:d,controlsRow:b.parentNode,controlsCell:b,type:null,spField:null};return q(b,h),h}function s(){if(null===V||null===W){"object"==typeof _spPageContextInfo&&(Y=15===_spPageContextInfo.webUIVersion?15:14),V={},W={};for(var b=a("table.ms-formtable td.ms-formbody"),c=0;c0?this.Controls=c[0]:this.Controls=null,this.ControlsRow=b.controlsRow,this.ReadOnlyLabel=null}function w(a){v.call(this,a),this.Textbox=n(this)}function x(a){w.call(this,a)}function y(a){x.call(this,a),this.FormatOptions={eventHandler:null,autoCorrect:!1,decimalPlaces:2}}function z(a){v.call(this,a),null!==this.Controls&&(this.Dropdown=this.Controls)}function A(b){if(v.call(this,b),null!==this.Controls){var c=a(this.Controls).find("input"),d=c.length;d>1&&"text"===c[d-1].type?(this.FillInTextbox=c[d-1],this.FillInElement=c[d-2],this.FillInAllowed=!0):(this.FillInAllowed=!1,this.FillInTextbox=null,this.FillInElement=null)}}function B(a,b){A.call(this,a),null!==this.Controls&&(this.Dropdown=b,this.Dropdown=1===this.Dropdown.length?this.Dropdown[0]:[])}function C(a){A.call(this,a),null!==this.Controls&&(this.RadioButtons=o(this,'input[type="radio"]'),this.FillInAllowed&&this.RadioButtons.pop())}function D(a){A.call(this,a),null!==this.Controls&&(this.Checkboxes=o(this,'input[type="checkbox"]'),this.FillInAllowed&&(this.FillInElement=this.Checkboxes.pop().value))}function E(a,b,c,e,f,g,h){this.Year=null,this.Month=null,this.Day=null,this.IsTimeIncluded=!1,this.Hour=null,this.Minute=null,this.TimeFormat=null,this.DateSeparator=null,d(a)||d(b)||d(c)||(this.SetDate(a,b,c),d(e)||d(f)||(this.SetTime(e,f),d(g)||(this.TimeFormat=g,d(h)||(this.DateSeparator=h))))}function F(b){if(v.call(this,b),this.DateTextbox=n(this),this.HourDropdown=null,this.MinuteDropdown=null,this.IsDateOnly=!0,this.HourValueFormat=null,null!==this.Controls){var c=a(this.Controls).find("select");null!==c&&2===c.length&&(this.HourDropdown=c[0],a(this.HourDropdown).val().indexOf(" ")>-1?this.HourValueFormat="string":this.HourValueFormat="number",this.MinuteDropdown=c[1],this.IsDateOnly=!1)}}function G(a){v.call(this,a),this.Checkbox=n(this)}function H(b){if(v.call(this,b),null!==this.Controls){this.TextboxURL=null,this.TextboxDescription=null,this.TextOnly=!1;var c=a(this.Controls).find("input");null!==c&&2===c.length&&(this.TextboxURL=a(c[0]),this.TextboxDescription=a(c[1]))}}function I(a,b){if(v.call(this,a),null!==this.Controls){if(1!==b.length)throw"Unable to get dropdown element for "+this.Name;this.Dropdown=b[0]}}function J(b,c){if(v.call(this,b),null!==this.Controls){if(1!==c.length)throw"Unable to get input elements for "+this.Name;this.Textbox=a(c[0]),this.HiddenTextbox=a('input[id="'+this.Textbox.attr("optHid")+'"]')}}function K(a,b){v.call(this,a),this.Textbox=b,this.TextType="Plain"}function L(a,b){K.call(this,a,b),this.TextType="Rich"}function M(b,c){v.call(this,b),this.Textbox=c[0],this.ContentDiv=a(this.Controls).find('div[contenteditable="true"]')[0],this.TextType="Enhanced"}function N(b){w.call(this,b),this.FileExtension=a(this.Textbox).parent().text()}function O(b){if(v.call(this,b),null!==this.Controls){var c=a(this.Controls).find("select");if(2!==c.length)throw"Error initializing SPLookupMultiField named "+this.Name+", unable to get select controls.";this.ListChoices=c[0],this.ListSelections=c[1],c=a(this.Controls).find("button"),0===c.length&&(c=a(this.Controls).find('input[type="button"]')),this.ButtonAdd=c[0],this.ButtonRemove=c[1]}}function P(b){if(v.call(this,b),null!==this.Controls){this.spanUserField=null,this.upLevelDiv=null,this.textareaDownLevelTextBox=null,this.linkCheckNames=null,this.txtHiddenSpanData=null;var c=a(this.Controls).find("span.ms-usereditor");null!==c&&1===c.length&&(this.spanUserField=c[0],this.upLevelDiv=byid(this.spanUserField.id+"_upLevelDiv"),this.textareaDownLevelTextBox=byid(this.spanUserField.id+"_downlevelTextBox"),this.linkCheckNames=byid(this.spanUserField.id+"_checkNames"),this.txtHiddenSpanData=byid(this.spanUserField.id+"_hiddenSpanData"))}}function Q(b){if(v.call(this,b),null!==this.Controls){var c=a(this.Controls).children()[0];this.ClientPeoplePicker=window.SPClientPeoplePicker.SPClientPeoplePickerDict[a(c).attr("id")],this.EditorInput=a(this.Controls).find("[id$='_EditorInput']")[0]}}function R(a,b){v.call(this,a),this.Controls=a.controlsCell,this.TextNode=b}function S(a,b){v.call(this,a),this.Controls=a.controlsCell,this.Element=b}function T(c){var d,e=null;if(b())return d=c.controlsCell.childNodes,5===d.length?new S(c,d[3]):new R(c,d[2]);switch(c.type){case"SPFieldText":e=new w(c);break;case"SPFieldNumber":e=new x(c);break;case"SPFieldCurrency":e=new y(c);break;case"ContentTypeChoice":e=new z(c);break;case"SPFieldChoice":d=a(c.controlsCell).find("select"),e=d.length>0?new B(c,d):new C(c);break;case"SPFieldMultiChoice":e=new D(c);break;case"SPFieldDateTime":e=new F(c);break;case"SPFieldBoolean":e=new G(c);break;case"SPFieldUser":case"SPFieldUserMulti":case"SPFieldBusinessData":e="undefined"==typeof window.SPClientPeoplePicker?new P(c):new Q(c);break;case"SPFieldURL":e=new H(c);break;case"SPFieldLookup":d=a(c.controlsCell).find("select"),d.length>0?e=new I(c,d):(d=a(c.controlsCell).find("input"),e=new J(c,d));break;case"SPFieldNote":d=a(c.controlsCell).find("textarea"),d.length>0?(d=d[0],window.RTE_GetEditorIFrame&&null!==window.RTE_GetEditorIFrame(d.id)&&(e=new L(c,d))):(d=a(c.controlsCell).find('input[type="hidden"]'),d.length>=1&&(e=new M(c,d))),null===e&&(e=new K(c,d));break;case"SPFieldFile":e=new N(c);break;case"SPFieldLookupMulti":e=new O(c);break;default:e=new v(c)}return e}function U(a){try{if(null===a.type)throw"Unknown SPField type.";return T(a)}catch(b){throw"Error creating field named "+a.name+": "+b.toString()}}var V=null,W=null,X=null,Y=12,Z={timeFormat:"12HR",dateSeparator:"/",decimalSeparator:".",thousandsSeparator:",",stringYes:"Yes",stringNo:"No"};v.prototype.Show=function(){return t(this.LabelRow,this.ControlsRow,!0),this},v.prototype.Hide=function(){return t(this.LabelRow,this.ControlsRow,!1),this},v.prototype.GetDescription=function(){if(l())return a(this.Controls.parentNode).children("span.ms-metadata").text();var b=this.Controls.parentNode,c=a(a(b).contents().toArray().reverse()).filter(function(){return 3===this.nodeType}).text();return c.replace(/^\s+/,"").replace(/\s+$/g,"")},v.prototype.SetDescription=function(b){var c;if(b=d(b)?"":b,l())c=a(this.Controls.parentNode).children("span.ms-metadata"),0===c.length&&(c=a('