var $ = require('jquery');
var settings = require('settings');


function getCookie() {
    match = document.cookie.match(/osf=(.*?)(;|$)/);
    return match ? match[1] : null;
}

function buildUrl(metadata, path, provider, file) {
    path = path || '/';
    var baseUrl = settings.WATERBUTLER_URL + (metadata ? 'data?': 'file?');

    if (file) {
        path += file.name;
    }

    return baseUrl + $.param({
        path: path,
        token: '',
        nid: nodeId,
        provider: provider,
        cookie: getCookie()
    });
}

function buildFromTreebeard(metadata, item, file) {
    return buildUrl(metadata, item.data.path, item.data.provider, file);
}

module.exports = {
    buildFileUrlFromPath: buildUrl.bind(this, false),
    buildFileUrl: buildFromTreebeard.bind(this, false),
    buildMetadataUrlFromPath: buildUrl.bind(this, true),
    buildMetadataUrl: buildFromTreebeard.bind(this, true),
};

@@ -20,16 +20,50 @@
 uery');%0A
+var $osf = require('osfHelpers');%0A
 var sett
@@ -203,24 +203,89 @@
  : null;%0A%7D%0A%0A
+function getViewOnly() %7B%0A  return $osf.urlParams().view_only;%0A%7D%0A%0A
 function bui
@@ -621,16 +621,49 @@
 Cookie()
+,%0A        viewOnly: getViewOnly()
 %0A    %7D);

Include view-only key in WaterButler URLs.