我对这个问题的前两个答案都投了赞成票。我承认我有点忘记了这个问题,直到有人对此进行了一些活动。
我们最终结合了上述技术。我能够按照建议找到全局样式表。我最终做的是复制该样式表中的所有样式并创建一个以 *_SystemSytles.css* 为后缀的新表。我创建了第二张表并在其后缀为 *_Custom.css*。然后在原始表中我放置了两个导入,首先导入系统样式,然后导入自定义样式。
对于某些报告,我们有一个自定义对象,该对象带有自己的样式(和 JavaScript)。这使用了与第二个问题类似的技术。
但是,为了在整个 Cognos 站点中导入 JavaScript 以供一般使用,我必须做的事情很困难。
在核心 webcontent 文件夹中,我创建了一个js文件夹,其中包含 jQuery 和我们的自定义 JavaScript 文件。然后在一系列 JavaScript 文件中,我包含了类似于以下的代码:
/************************
JQUERY UTIL INCLUDE
************************/
function loadjscssfile(filename, filetype, id) {
if (filetype == "js") { //if filename is a external JavaScript file
var fileref = document.createElement('script')
fileref.setAttribute("type", "text/javascript")
fileref.setAttribute("src", filename)
if (id)
fileref.setAttribute("OurCompanyNameAsAnID", id)
}
else if (filetype == "css") { //if filename is an external CSS file
var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref != "undefined") {
var headTag = document.head || document.getElementsByTagName('head')[0];
headTag.appendChild(fileref);
}
}
function _PortalLoadJS() {
if (!window._PortalScriptsLoaded) {
var pathParams = [];
var path = location.href;
(function () {
var e,
r = /([^/]+)[/]?/g,
p = path;
while (e = r.exec(p)) {
pathParams.push(e[1]);
}
})();
var baseURL = location.protocol + '//';
for(var i = 1; i < pathParams.length; i++) {
if(pathParams[i] == 'cgi-bin')
break;
baseURL += pathParams[i] + '/';
}
loadjscssfile(baseURL + "js/jquery-1.6.1.min.js", "js");
loadjscssfile(baseURL + "js/Custom.js?pageType=COGNOS_CONNECTION", "js", "SumTotalUtil");
window._PortalScriptsLoaded = true;
}
}
if(!window.$CustomGlobal) {
window.$CustomGlobal= function(func) {
if (!window.$A) {
if (!window.__CustomExecStack) {
window.__CustomExecStack= new Array();
}
window.__CustomExecStack.push(func);
}
else
$A._executeCustomItem(func);
}
}
try {
// Catch cases where $(document).ready() is called after the
// browser event has already occurred.
if (document.readyState === "complete") {
// Handle it asynchronously to allow scripts the opportunity to delay ready
setTimeout(_PortalLoadJS, 10);
}
// Mozilla, Opera and webkit nightlies currently support this event
if (document.addEventListener) {
// Use the handy event callback
document.addEventListener("DOMContentLoaded", function() { _PortalLoadJS(); }, false);
// A fallback to window.onload, that will always work
window.addEventListener("load", _PortalLoadJS, false);
// If IE event model is used
} else if (document.attachEvent) {
// ensure firing before onload,
// maybe late but safe also for iframes
document.attachEvent("onreadystatechange", function() { _PortalLoadJS(); });
// A fallback to window.onload, that will always work
window.attachEvent("onload", _PortalLoadJS);
}
}
catch (ex) { }
$A 项目是我在加载 Custom.js 文件时创建的项目。
以下是我包含此代码的文件列表(在 JavaScript 的不同端):
- 网页内容\icd\bux\js\bux\bux.core.js
- 网页内容\ps\portal\js\cc.js
- 网页内容\rv\CCognosViewer.js
- 网页内容\rv\GUtil.js
- webcontent\rv\viewer.standalone.core.js
这些文件应涵盖 Cognos Connection、Report Viewer 和 Dashboards 区域。如果发现更多,请告诉我,我可以更新此列表。
链接到 Custom.js 文件时,我在 Custom.js 文件获取的外部资源上放置了一个查询字符串:pageType=COGNOS_CONNECTION。这允许我为 Cognos Connection、Report Viewer 或 Dashboards 执行特定的加载代码。
下面是 Custom.js 类中初始化 $A 对象的代码:
function _CustomUtilInit() {
try {
if (!window.$j) {
window.setTimeout(_CustomUtilInit, 1);
return;
}
var jScriptTags = $j('SCRIPT[' + Analytics.SCRIPT_ATTR_NAME + '= ' + Analytics.SCRIPT_ATTR_VALUE + ']');
jScriptTags.each( function(i, scriptElem) {
var tag = $j(scriptElem);
if(tag.attr(Analytics.LOADED_SCRIPT_KEY))
return;
var scriptURL = new URI(tag.attr('src'));
var analyticsPageType = scriptURL.getQueryStringValue(Analytics.PAGE_TYPE_QUERY_KEY, Analytics.PageType.REPORT_VIEWER);
if(!window.$A) {
window.$A = new Analytics();
}
window.$A.init(analyticsPageType);
tag.attr(Analytics.LOADED_SCRIPT_KEY, 'true');
});
} catch (e) {
}
}
_CustomUtilInit();
当然,这需要在前面提到的每个 JavaScript 文件中的 Custom.js 文件之前包含 jQuery 库。
URI 类是我在 Internet 上找到的并针对我们的使用进行了调整。如果您对自定义 JavaScript 加载有任何疑问,请发表评论,我会尽力详细说明。