Namespace: helpers

helpers

Methods

(static) abs2rel() → {string}

Get the relative (to the root) portion of an absolute url.
Parameters:
Type Description
string the absolute url
Source:
Returns:
- the relative url
Type
string
Example
var aurl = 'http://example.com/a/path/to.html';
var rurl = sputils.helpers.abs2rel(aurl);
rurl === '/a/path/to.html';

(static) clientContextForWeb(absoluteUrl) → {Promise.<SP.ClientContext>}

Get a promise for a client context that could be on another site/web. This client context is augmented to contain extra info in the `_info` property.
Parameters:
Name Type Description
absoluteUrl string the absolute url of the listitem, file or other asset.
Source:
Returns:
- the promise of a client context
Type
Promise.<SP.ClientContext>
Example
console.log(location);// => http://contoso.com/sub1
var fileUrl = 'http://contoso.com/sub21231/Shared Documents/file1.docx';
var cctxPromise = sputils.helpers.clientContext(fileUrl);
cctxPromise.then(function (cctx) {
  var webUrl = cctx._info.WebFullUrl;
  var web = cctx.get_web();
  var file = web.getFileByServerRelativeUrl(sputils.helpers.abs2rel(fileUrl));
  // ...
});

(static) downloadContent() → {nil}

Download a file using javascript Useful to implement Export functionality in Search. You can download as csv or text. The function triggers the download not the actual csv creation. Works with utf-8
Parameters:
Name Type Description
options. Array.<string>
Source:
Returns:
Type
nil
Example
var separator = ';';
downloadContent({
  type: 'text/csv;charset=utf-8',
  filename: 'results.csv',
  content: ['ASCII', separator,
     'Åbäcka sig', separator,
     'to się podoba: żźćąęłć',
     separator, 'Яшлӑхӑма туйаймарӑм'].join('')
});

(static) parseQueryString(optArg) → {Object}

Parameters:
Name Type Description
optArg Optional.<string> a query string, as in the form of "?k1=v1&k2=v2"
Source:
Returns:
an object representing the dictionary of the query string.
Type
Object
Example
console.log(location.search); // => '?a=1&b=some value'
var qsHash = parseQueryString(); // no argument, will use the current browsing context's location.search
// qsHash ~=~ {a:1, b: 'some value'};
parseQueryString('?a=1&b=some value'); // ~=~ qsHash

(static) withSharePointDependencies(deps) → {Promise.<Void>}

Returns a promise which resolves when all the specified dependencies are loaded. Takes a list of strings which correspond to SP JS dependencies. Each dependency is registered and loaded. Uses SP builtin dependency management to load a specific dependency.
Parameters:
Name Type Description
deps Array.<dep> An array containing hashes with the following keys: {file, namespace}
[ { file: string, namespace: string } ]
Source:
Returns:
- resolved when all deps are loaded.
Type
Promise.<Void>