Created
February 23, 2016 11:24
-
-
Save klinkby/5c626bfa51d81367db4f to your computer and use it in GitHub Desktop.
Client side browser to specific folder in data view web part
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
"use strict"; | |
///// | |
// Deserialize and serialize a query string | |
function QueryString(qs) { | |
var re = /([^&=]+)=([^&]*)/g, | |
m; | |
while (m = re.exec((qs || location.search).substring(1))) { // skip the question mark | |
this[decodeURIComponent(m[1])] = decodeURIComponent(m[2]); | |
} | |
return; | |
} | |
QueryString.prototype.toString = function () { | |
var ser = "?"; | |
for (var key in this) { | |
if (!this.propertyIsEnumerable(key)) continue; | |
ser += encodeURIComponent(key) + "=" + encodeURIComponent(this[key]) + "&"; | |
} | |
return 1 === ser.length ? "" : ser.substring(0, ser.length - 1); // skip the trialing ampersand | |
}; | |
///// | |
// Change the postback url and run ajax update of data view WP | |
function browseToFolder(docLibServerRelativeUrl) { | |
// <style> #ManualRefresh { display: none; } </style> | |
var mainForm = document.forms[0], | |
wpAjaxRefreshButton = document.getElementById("ManualRefresh"), | |
qs = new QueryString(location.search); | |
if (!wpAjaxRefreshButton) { | |
if (window.console) console.warn("Ajax refresh button not found on data view WP"); | |
return; | |
} | |
qs.RootFolder = docLibServerRelativeUrl; | |
mainForm.action = location.pathname + qs.toString(); | |
wpAjaxRefreshButton = wpAjaxRefreshButton.parentElement; // up from img to a | |
wpAjaxRefreshButton.click(); | |
} | |
function browseToAftId(aftId) { | |
if (!aftId) return; | |
var webUrl = window._spPageContextInfo.webServerRelativeUrl, | |
docLibServerRelativeUrl = (1 === webUrl.length ? "" : webUrl) + "/Shared Documents/" + aftId; | |
browseToFolder(docLibServerRelativeUrl); | |
} | |
browseToAftId("02190014"); | |
}()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment