-
Notifications
You must be signed in to change notification settings - Fork 6
ShareCoffee.Commons
ShareCoffee.Commons provides serveral useful helpers that can make your SharePoint-App-Developer life easier.
There isn't a perfect way how to receive the AppWebUrl. _spPageContext
info object is only available in SharePoint-Hosted samples. Therefore ShareCoffee's implementation offers a little bit more.
It looks for the AppWebUrl in
-
_spPageContextInfo
(if persent) -
SPAppWebUrl
parameter in the QueryString - it executes a custom method that can be injected to define where it should load the url from
It's evaluating the sources in the following order
- your injected method
_spPageContextInfo
- QueryString
// use ShareCoffee's default implementation
// writes an error to the console if nothing found.
var appWebUrl = ShareCoffee.Commons.getAppWebUrl();
// use your custom implementation
ShareCoffee.Commons.loadAppWebUrlFrom = function(){
// load from cookie or database ...
return "https://my-app-web.sharepoint.com/";
};
var appWebUrl = ShareCoffee.Commons.getAppWebUrl();
Returns the combination of ShareCoffee.Commons.getAppWebUrl() + "/_api/"
var apiRoot = ShareCoffee.Commons.getApiRootUrl()
The method is going to load the HostWebUrl from the QueryString or by invoking your custom method
-
SPHostUrl
parameter in the QueryString - it executes a custom method that can be injected to define where it should load the url from
It's evaluating the sources in the following order
- your injected method
- QueryString
// use ShareCoffee's default implementation
// writes an error to the console if nothing found.
var hostWebUrl = ShareCoffee.Commons.getHostWebUrl();
// use your custom implementation
ShareCoffee.Commons.loadHostWebUrlFrom = function(){
// load from cookie or database ...
return "https://myhostweb.sharepoint.com/";
};
var hostWebUrl = ShareCoffee.Commons.getHostWebUrl();
In order to perform write operations by using SharePoint APIs, you've to pass the FormDigest-Value. The getFormDigest
method is going to return the required value.
var formDigestValue = ShareCoffee.Commons.getFormDigest();
This method returns the entire QueryString currently appended to the URL.
var queryString = ShareCoffee.Commons.getQueryString();
This method reutrns a single value from the entire QueryString by its Name. if the Name isn't present in the current QueryString it will return an empty string.
var hostWebUrl = ShareCoffee.Commons.getQueryStringParameter('SPHostUrl');