Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // example: registerScriptLink('LoQutus.BreadCrumb', '~sitecollection/siteassets/js/breadcrumb.js', 'Adds a breadcrumb navigation across the site collection');
- // example: removeScriptLink('LoQutus.BreadCrumb', null, null, true);
- function onError(sender, args) {
- console.log('Error: ' + args.get_message());
- }
- function registerScriptLink(id, url, description) {
- var ctx = SP.ClientContext.get_current(),
- site = ctx.get_site(),
- userActions = site.get_userCustomActions();
- ctx.load(userActions);
- ctx.executeQueryAsync(
- function () {
- var userActionsEnumerator = userActions.getEnumerator(),
- userAction,
- found;
- while (userActionsEnumerator.moveNext() && !found) {
- userAction = userActionsEnumerator.get_current();
- if (userAction.get_title() === id) {
- found = true;
- }
- }
- if (!found) {
- console.log('Creating new UserCustomAction');
- userAction = userActions.add();
- }
- userAction.set_title(id);
- userAction.set_sequence(2);
- userAction.set_location('ScriptLink');
- userAction.set_scriptSrc(url);
- userAction.set_description(description);
- userAction.update();
- ctx.executeQueryAsync(
- function () {
- console.log('UserCustomAction has been saved');
- },
- onError
- );
- },
- onError
- );
- }
- function removeScriptLink(id) {
- var ctx = SP.ClientContext.get_current(),
- site = ctx.get_site(),
- userActions = site.get_userCustomActions();
- ctx.load(userActions);
- ctx.executeQueryAsync(
- function () {
- var userActionsEnumerator = userActions.getEnumerator(),
- userAction,
- found;
- while (userActionsEnumerator.moveNext() && !found) {
- userAction = userActionsEnumerator.get_current();
- if (userAction.get_title() === id) {
- found = true;
- }
- }
- if (found) {
- userAction.deleteObject();
- ctx.executeQueryAsync(
- function () {
- console.log('UserCustomAction has been deleted');
- },
- onError
- );
- } else {
- console.log('UserCustomAction not found');
- }
- },
- onError
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement