设为首页 收藏本站
查看: 723|回复: 0

[经验分享] SharePoint JavaScript Functions

[复制链接]

尚未签到

发表于 2015-9-27 10:30:58 | 显示全部楼层 |阅读模式
  
  参考路径:http://blogs.msdn.com/b/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx
  function getTagFromIdentifierAndTitle(tagName, identifier, title) {
   var len = identifier.length;
   var tags = document.getElementsByTagName(tagName);
   for (var i=0; i < tags.length; i++) {
   var tempString = tags.id;
   if (tags.title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
   return tags;
   }
   }
   return null;
  }
  
  
  参考路径:
https://www.nothingbutsharepoint.com/sites/devwiki/SP2007Dev/Pages/SharePoint%20JavaScript%20Functions%20Overview.aspx  Map of Reusable SharePoint JavaScript
JSRequest
&#8226;version:  WSS 3.0
&#8226;source file: init.js (ln 1621)
&#8226;mapped by:  Itay Shakury
&#8226;purpose:  provides method to parse query string, filename, and pathname from URL
&#8226;example:
JSRequest.EnsureSetup();var qs = JSRequest.QueryString[value];var fn = JSRequest.FileName;var pt = JSRequest.PathName
  
  PreSaveAction()
&#8226;version:  WSS 3.0
&#8226;source file: n/a (ref: form.js ln 5909)
&#8226;mapped by:  Edin Kapic
&#8226;purpose:  provides hook for creating custom function interrupting submit action
&#8226;example:
function PreSaveAction(){  var input = getTagFromIdentifierAndTitle("textarea","","Test");  if(input && input.value == "") {    alert("You must complete Test");    return false; // Cancel the item save process    }  return true; // OK to proceed with the save item}
  _spBodyOnLoadFunctionNames
&#8226;version:  WSS 3.0
&#8226;source file: n/a
&#8226;mapped by: Sanjay Arora
&#8226;purpose:  Allows you to register additional JavaScript methods that should run in the PageLoad event
&#8226;example:
_spBodyOnLoadFunctionNames.Push('MyCustomFunctionName');
  GetFirstChildElement(e)
&#8226;version:  WSS 3.0
&#8226;source file: core.js
&#8226;mapped by:  Christophe
&#8226;purpose:  get the first "real" child of a DOM element. This function is useful for Firefox, which interprets a line break as a child element.
GetLastChildElement(e)
&#8226;version:  WSS 3.0
&#8226;source file: core.js
&#8226;mapped by:  Christophe
&#8226;purpose:  get the last "real" child of a DOM element. This function is useful for Firefox, which interprets a line break as a child element.
GetCBSelectedValues(frm)
&#8226;version:  WSS 3.0
&#8226;source file: core.js (ln 972)
&#8226;mapped by:  Paul Grenier
&#8226;purpose:  Accepts a form object, loops through all check box elements and returns the values of the checked boxes or false if none are checked.
&#8226;example:
html
  <input id="spUserSelCb_1131" type="checkbox" title="Paul Grenier"  value="131" name="spUserSelectionCheckBox_1"/>
  JavaScript
  var elm = document.getElementsByTagName("form")[0];GetCBSelectedValues(elm)
  Object returned: strList = "131,144,143,7,254,22..."
  GetSelectedValue (frmElem)
&#8226;version:  WSS 3.0
&#8226;source file: init.js (ln 1516)
&#8226;mapped by:  Paul Grenier
&#8226;purpose: takes a form element with a selectedIndex and returns the selected value or an empty string.
GetSelectedText(frmElem)
&#8226;version:  WSS 3.0
&#8226;source file: init.js (ln 1523)
&#8226;mapped by:  Paul Grenier
&#8226;purpose: takes a form element with a selectedIndex and returns the selected text or an empty string.
escapeProperly(str)
&#8226;version:  WSS 3.0
&#8226;source file: init.js (ln 168)
&#8226;mapped by:  Paul Grenier
&#8226;purpose: takes any string and returns a URL-encoded string.
&#8226;example:
escapeProperly("this is a test")
  "this%20is%20a%20test"
  unescapeProperly(str)
&#8226;version:  WSS 3.0
&#8226;source file: init.js (ln 855)
&#8226;mapped by:  Paul Grenier
&#8226;purpose: takes any URL-encoded string and returns a string.
&#8226;example:
unescapeProperly("this%20is%20a%20test")
  "this is a test"
  createNewDocumentWithProgID(strTemplate, strSaveLocation, strProgID, bXMLForm)
&#8226;version:  WSS 3.0
&#8226;source file: Core.js (ln 1123)
&#8226;mapped by:  John Vivian
&#8226;purpose: Generates a new document in a document library using the supplyed document template
&#8226;example:
createNewDocumentWithProgID('http:\u002f\u002fwssdev\u002fDocument Library\u002fForms\u002ftemplate.dotx', 'http:\u002f\u002fwssdev\u002fDocument Library', 'SharePoint.OpenDocuments', false)
  This will open Word with a new document using the template located at http:\\fwssdev\Document Library\Forms\template.dotx and word will save to the Document Library located at http:\\fwssdev\Document Library

  参考路径:http://ruudheemskerk.net/archive/2010/08/03/helpful-sharepoint-javascript-functions.aspx
  
  function STSScriptEncode(str)

This function can be used to encode javascript variable for usage in scripts.

Location
init.js

Parameters
str
    The string that has to be encoded.

Return value
The encoded string that can be used in scripts.

Example
var strAction = "STSNavigate('" + STSScriptEncode(currentItemUrl) + "')";
  
function STSScriptEncodeWithQuote(str)

This function can be used to encode and quote javascript variable for usage in scripts.

Location
init.js

Parameters
str
    The string that has to be encoded.

Return value
The encoded string that can be used in scripts, that is enclosed in quotes (").

Example
var strAction = 'STSNavigate(' + STSScriptEncodeWithQuote(currentItemUrl) + ')';
  
function STSHtmlEncode(str)

This function can be used to encode a string to html.

Location
init.js

Parameters
str
    The string that has to be encoded.

Return value
The string encoded to html.

Example
var html = STSHtmlEncode('htmlString');
  
function STSNavigate(url)

This function can be used to navigate to a given url.

Location
init.js

Parameters
url
    A string that contains the url to navigate to.

Example
STSNavigate('http://www.microsoft.com');
  
function STSPageUrlValidation(url)

This function can be used to validate an url whether it starts with "http" or with a slash '/'. The function raises an alert when the url is not valid.

Location
init.js

Parameters
url
    A string that contains the url to check

Return value
If the url is valid it will return the url that has been given as the parameter, if it is not valid it wil return an empty string.

Example
var url = PageUrlValidation('http://www.microsoft.com');
  
function GetUrlKeyValue(kenName, bNoDecode, url)

This function can be used to get a querystring parameter.

Location
init.js

Parameters
keyName
    A string that contains the name of the parameter.

bNoDecode
    A boolean that states whether the value has will not be encoded, this parameter is optional, default is false.

url
    A string that contains the url to fetch the querystring parameters from, this is optional, the window.location.href will be used if the parameter is null.

Return value
The value of the parameter, encoded if bNoDecode was false.

Example
var action = GetUrlKeyValue('action');
  
function GetSource(defaultSource)

This function can be used to get the source parameter from the querystring.

Location
init.js

Parameters
defaultSource
    A string that contains the default source, this parameter is optional.

Return value
If the source querystring parameter exists it will return the value of that parameter, otherwise if the defaultSource parameter was given it will return that. In any oter case it will return window.location.href.

Example
var source = GetSource();
  
function LoginAsAnother(url, bUseSource)

This function can be to change the current user.

Location
init.js

Parameters
url
    A string that contains url to go to after the login.

bUseSource
    A boolean that indicates that the source will be added to the url, otherwise the source will be the window.location.href. This parameter is optional, default is false.

Example
<a href="#">Log on as a different user</a>
  
function GoToPage(url)

This function can be used to navigate to an url, adding a source querystring parameter.

Location
init.js

Parameters
url
    A string that contains url to navigate to.

Example
<a href="#">Settings</a>

  function TrimSpaces(str)

This function can be to trim spaces on a string.

Location
init.js

Parameters
str
    A string that will be trimmed.

Return value
The trimmed string.

Example
var trimmed = TrimSpaces(" string with spaces "); // Returns "string with spaces".

  function TrimWhiteSpaces(str)

This function can be to trim whitespaces on a string, that is spaces, tabs and linebreaks (\t \n \r \f).

Location
init.js

Parameters
str
    A string that will be trimmed.

Return value
The trimmed string.

Example
var trimmed = TrimWhiteSpaces("\t\tstring with spaces\n");  // Returns "string with spaces".

  function escapeProperly(str)

This function takes a string and returns a URL-encoded string.

Location
init.js

Parameters
str
    A string that will be encoded.

Return value
The encoded string.

Example
var urlEncodedValue = escapeProperly("My Value"); // Returns "My%20Value".

  function unescapeProperly(str)

This function takes a URL-encoded string and returns an string.

Location
init.js

Parameters
str
    A string that will be decoded.

Return value
The string.

Example
var urlDecodedValue = unescapeProperly("My%20Value"); // Returns "My Value".
  
class JSRequest

The JSRequest object provides parsing of the querystring, you can easily use this object to get querystring variables, filenames and pathnames.

Location
init.js

Example
JSRequest.EnsureSetup();

// The current url in this example is http://localhost/pages/default.aspx?debug=true
var debug = JSRequest.QueryString["debug"]; // Returns 'true'.
var fileName = JSRequest.FileName; // Returns 'default.aspx'.
var pathName = JSRequest.PathName; // Returns '/pages/default.aspx'.

  array _spBodyOnLoadFunctionNames

This array allows you to register additional JavaScript methods that should run in the body onload event.

Location
core.js

Example
_spBodyOnLoadFunctionNames.push('functionName');

You can also pass arguments, for example an id. The next example shows an argument of type string.

_spBodyOnLoadFunctionNames.push('functionName("functionArgument")');

  variable L_Menu_BaseUrl

This variable contains the base URL of the current site or subsite.

Location
Inline

Example
document.location = L_Menu_BaseUrl + 'Lists/Tasks/AllItems.aspx';

  variable L_Menu_LCID

This variable contains the LCID setting of the current site.

Location
Inline

  variable L_Menu_SiteTheme

This variable contains the theme name of the current site.
  Location
Inline

  variable _spUserId

This variable contains the id of the current user.

Location
Inline

  Deferred loading

Be careful using the out of the box scripts from the core.js when it is loaded deferred. In that case, add your scripts to the JQuery on document.ready or via _spBodyOnLoadFunctionNames to be sure that the functions are present

  参考地址:http://sharepoint-insight.com/
  

DOM Management

  • byid(id)=Return element for the given id
  • newE(tag)=Create a new dom element of the given tag e.g. div etc.
  • wpf() =return ASP.net form object for the current web part page
  • GetEventSrcElement(e) =return source element for the given event object
  • GetEventKeyCode(e)=Return key code of the currently pressed key for the given object
  • GetInnerText(e)=Return inner html for the given object
  HTML Encoding and Decoding

  • escapeProperlyCoreCore(str, bAsUrl, bForFilterQuery, bForCallback)=Very useful function to perform any type of string escaping. Last three parameters are flags to perform deifferent type of escaping i.e.

    • bAsUrl =true, for url escaping
    • bForFilterQuery=true, for filter query escaping
    • bForCallback =true, for call back escaping

  • escapeProperly(str)=Escapes the given string to make it valid SharePoint compatible string. It internally calls escapeProperlyCoreCore to perform the actual escaping
  • escapeUrlForCallback(str)=Escapes the given string to make it valid url for call back
  • encodeScriptQuote(str)=Replace the apostrophe i.e. &#8216; to %27 in the given string
  • STSHtmlEncode(str) =Encodes the reserved characters to their respective HTML entities in the given string. For example &#8220;<div>&#8221; will become &lt;div&gt;
  • StAttrQuote(st) =Encodes the &#8220;&&#8221;, &#8220; &#8220; &#8221; and carriage return to their respective HTML entities in the given string.
  • STSScriptEncode(str) =Encodes the given string for use in script. It has the same functionality as SPEncode.ScriptEncode defined here
  • STSScriptEncodeWithQuote =Encodes the specified string so that characters in embedded HTML tags are displayed as text in the browser, and writes the string in quotation marks
  • escapeForSync(str)=Encodes the given string for syncing. Need further clarification.
  • Vutf8ToUnicode(rgBytes)= Converts the given utf8 string to unicode
  • unescapeProperly(str)=Unescapes the given escaped string
  Validations

  • PageUrlValidation(url) =Checks if the given string is a valid url or not.
  • IndexOfIllegalCharInUrlLeafName(strLeafName)=Return the index of character in the given string which is illegal to be used in url leaf name.
  • IndexOfIllegalCharInUrlPath(strPath)= Return the index of character in the given string which is illegal to be used in url leaf name.
  • UrlContainsIllegalStrings(strPath)=Returns true if the given string contains an illegal character which can not be used in a url. Otherwise, return false.
  • UrlLeafNameValidate(source, args)=Validates the url leaf name. Returns true if valid otherwise, false. Need further clarification.
  • UrlPathValidate (source, args) =Validates the url path. Returns true if valid otherwise, false. Need further clarification.
  • IsCheckBoxListSelected(checkboxlist) =Returns true, if the given checkbox is either null or at least one check box is checked in it.
  • IsAccessibilityFeatureEnabled()=Returns true, if the accessibility feature is enabled by checking the cookie called &#8220;WSS_AccessibilityFeature&#8221;
  Cookie Management

  • DeleteCookie(sName) =Deletes the given cookie by setting its expiry date to 01-Jan-1970
  • GetCookie(sName) =Returns the given cookie
  Navigation

  • navigateMailToLink(strUrl, strUrlNew)=Creates a mail to link for the given url
  • GetUrlFromWebUrlAndWebRelativeUrl(webUrl, webRelativeUrl)=Creates a url by combining webUrl and relative url. It takes care of checking null webUrl and slash character at the end.
  Syncing with other applications

  • GetStssyncAppNameForType(strType,strDefault)=Returns an string similar to &#8220;Connect to Outlook&#8221; etc. depending on the given type.
  • GetStssyncIconPath(strDefault, strPrefix) =Returns the path of icon image for the given syncing application type.
  • ExportHailStorm ( &#8230;.. )=Creates connection to Outlook. Check here for further details.
  
  
  SharePoint &#8211; Outlook Synchronization
  参考地址:
  http://abstractspaces.wordpress.com/2009/09/19/sharepoint-%E2%80%93-outlook-synchronization/
  
  stssync://sts/?ver=1.1&type=tasks&cmd=add-folder&base-url=http://moss:99/Test/CompanySite&list-url=/Lists/Project%20Tasks/&guid={5d0b44fe1-3041-43f9-8be6-c330c1444538}&site-name=CompanySite&list-name=Project? Tasks
  Where :

version :  The version of the application in the format x.y. For example, for Outlook 2003, the value of this parameter should be 1.0. For outlook 2007 version is 1.1. The values x and y must be composed of numbers only. x must not start with a zero, and y must be either zero or some other sequence of digits that does not start with a zero. Also x and y cannot be more than two digits each, or Outlook considers the URL to be malformed. A third-party client application may or may not use this parameter, but when the URL is constructed, the parameter must have a value &#8212; otherwise, the URL is considered malformed.

folder-type :  Can be calendar or contacts or task, depending on the type of SharePoint list being added to Outlook or to a third-party application. This parameter is case-insensitive.

command-name :  The command name that Outlook or the third-party application understands. Specify add-folder to add a folder to Outlook. More commands may be added to Outlook later.

sts-url :  The URL to the SharePoint site being added. Should not end in a / character.

the-guid :  The GUID that, when paired with the sts-url parameter, uniquely identifies a SharePoint list. Outlook expects this parameter to be in the following format: &#8220;{&#8220;+ 8 hexadecimal characters + &#8220;-&#8221; + 4 hexadecimal characters + &#8220;-&#8221; + 4 hexadecimal characters + &#8220;-&#8221; + 12 hexadecimal characters + &#8220;}&#8221;. If this parameter is in a different format, Outlook considers the URL malformed and returns an error.

site-friendly-name :  The display name of the site containing the list that is being added. Outlook uses this parameter to create the folder name.

list-friendly-name :  The display name of the list that is being added. Outlook uses this parameter to create the folder name.

list-url :  A string that is added to the sts-url parameter to create the full URL for the list. Should start with a / character.

uid :  Optional. A number greater than zero, with fewer than eight digits. Uniquely represents a user on the SharePoint site.
  Notes

  • Special character escaping: If any of the characters &#8220;&&#8221;, &#8220;\&#8221;, &#8220;[", "]&#8220;, or &#8220;|&#8221; is part of the value of the sts-url, site-friendly-name, list-friendly-name, or list-url parameter, it must be preceded by a &#8220;|&#8221; character. For example, a list-friendly-name of Dan [Wilson] &#8211; Business\Personal Contacts would become Dan |[Wilson|] &#8211; Business|\Personal Contacts.
  • The sts-url, site-friendly-name, list-friendly-name, and list-url parameters can contain Unicode characters. However, the Unicode characters must be enclosed in brackets &#8220;[ ]&#8221; and must be 4-digit hexadecimal character representations of the Unicode characters.

  • When you connect a Microsoft Windows SharePoint Services task list to Microsoft Office Outlook 2007, some columns may not appear in Outlook 2007. This is because you can synchronize a limited set of predefined properties by using the Connect to Outlook feature. However, you cannot connect custom SharePoint task list columns to Outlook 2007.

    All Outlook 2007 users see the same information when they view synchronized SharePoint task list items. This is true even if an Outlook field such as Categories does not appear in Internet Explorer when you view a SharePoint task list. Outlook synchronizes these properties to other Outlook users through the server that is running Windows SharePoint Services.  To view an Outlook 2007 field such as Categories in Internet Explorer, add that field as a column template. To add an Outlook 2007 field to the SharePoint task list, use the Add Site Columns command on the Settings menu in the SharePoint task list. Administrators can use this feature to make the appearance of the synchronized SharePoint task list more consistent with Outlook 2007 and can sync a limited set of predefined properties.
  To implement a third-party client that can make use of the stssync protocol to add and synchronize Events and Contacts lists that exist on a SharePoint site, you typically need to implement an ActiveX control called StssyncHandler and provide support for the stssync protocol. The third-party client typically needs to be able to decode the URL and synchronize the Contacts or Events list on the SharePoint site. You can use the Microsoft.SharePoint namespace or the Web services exposed by Windows SharePoint Services to perform this task. You also need to register the stssync protocol in the registry with the name of the executable file of your application. In Microsoft Windows operating environments with Microsoft Internet Explorer version 5.0 or later, you can use the sample provided below. Copy the following lines to a .reg file, and replace the &#8220;<Path to exe>&#8221; with the path to the executable file of the application that wants to synchronize events and contacts with Windows SharePoint Services. Then double-click the .reg file to register the stssync protocol on your computer.
  Windows Registry Editor Version 5.00
  [HKEY_CLASSES_ROOT\stssync]
  @=&#8221;URL:Add SharePoint Folder&#8221;
  &#8220;URL Protocol&#8221;=&#8221;"
  [HKEY_CLASSES_ROOT\stssync\shell]
  @=&#8221;open&#8221;
  [HKEY_CLASSES_ROOT\stssync\shell\open]
  @=&#8221;"
  [HKEY_CLASSES_ROOT\stssync\shell\open\command]
  @=&#8221;<Path to exe> \&#8221;%1\&#8221;"
  Example
  stssync://sts/?ver=1.0&type=calendar&cmd=add-folder&base-url=http%3A%2F%2Fspserver1&list-url=%2FLists%2FEvts%2FAllItems%2Easpx&guid=%7BAA7D945C%2DE5C3%2D4854%2DB631%2D10A98E711E2B%7D&site-name=Share|%7CPoint%20|%5BSite|%5D&list-name=Ev[00E900F1]ts
  This URL is for a list called &#8220;Events&#8221; on a site called &#8220;Share|Point [Site]&#8221; with site URL http://spserver1 and list URL http://spserver1/Lists/Evts/AllItems.aspx. Note the use of the vertical bar to escape the &#8220;|&#8221;, &#8220;[", and "]&#8221; characters, and the hexadecimal representation of the two Unicode characters in the list name
  
  
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-119384-1-1.html 上篇帖子: SharePoint 2007在仅有内容数据库的灾难性恢复 下篇帖子: SharePoint 2010 托管元数据Bug (跟邮件提醒功能相关.小bug,大问题)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表