Last active
December 21, 2015 20:39
-
-
Save baldwicc/6362607 to your computer and use it in GitHub Desktop.
PRD: Topframe Hacks for Bb Learn. Customises page titles, sets a frameset-wrapped url of current content page location in the address bar, and customises banner to open in same window.
This file contains hidden or 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
/* jshint strict: false */ | |
/* global Event, $$ */ | |
/** | |
* qut-pagetitles | |
* @author Christopher Baldwin [https://staff.qut.edu.au/details?id=baldwicc] | |
* @license Simplified BSD License | |
* @source [https://gist.github.com/baldwicc/6362607] | |
*/ | |
/* | |
Usage: | |
- set conf.opts with the features to use | |
- customise options under opts.params | |
*/ | |
Event.observe(document, 'dom:loaded', function () { | |
var conf = { | |
opts: { | |
use_history_api: true, | |
modify_banner: true, | |
custom_frameset_title: true, | |
}, | |
params: { | |
title: { | |
prefix: 'QUT Bb DEV2', | |
seperator: ' | ' | |
}, | |
history: { | |
frameset: '/webapps/portal/frameset.jsp?' | |
}, | |
banner: { | |
elem: $$('#topTabs .brandingImgWrap a')[0], | |
target: '', | |
onclick: function () { | |
parent.window.location.replace('/'); | |
} | |
} | |
} | |
}; | |
var parentdoc = window.parent.document; | |
/** | |
* @type {array} an array of frame or iframe elements | |
*/ | |
var theframes = (function () { | |
var iframes = parentdoc.getElementsByTagName('iframe'); | |
var frames = parentdoc.getElementsByTagName('frame'); | |
return iframes.length ? iframes : frames; | |
}()); | |
var getTabTabGroupId = function () { | |
try { | |
var activeTabLink = $$('#appTabList > tbody > tr > td.active > a') | |
.first() | |
.href; | |
var tabGroupId = activeTabLink.match(/(tab_tab_group_id=)(_[0-9]+_[0-9]+)/)[2] || ''; | |
return tabGroupId; | |
} catch (e) { | |
return ''; | |
} | |
}; | |
var init = function () { | |
var contentframe = window.parent.frames.content; | |
var frameset = parent.window; | |
if (contentframe){ | |
// detect load events on content frame element | |
Event.observe(contentframe.frameElement, 'load', function () { | |
// add page title | |
if (conf.opts.custom_frameset_title) { | |
frameset.document.title = [ | |
conf.params.title.prefix, | |
contentframe.courseTitle, | |
contentframe.document.title | |
].join(conf.params.title.seperator); | |
} | |
// modify banner | |
if (conf.opts.modify_banner) { | |
conf.params.banner.elem.writeAttribute({ | |
'target': conf.params.banner.target | |
}) | |
.observe('click', conf.params.banner.onclick); | |
} | |
// replace history | |
if (conf.opts.use_history_api && window.history && window.history.replaceState) { | |
var contentURL = contentframe.location; | |
var tabGroupId = getTabTabGroupId(); | |
var newpath = conf.params.history.frameset; | |
if (tabGroupId) { | |
newpath += 'tab_tab_group_id=' + tabGroupId + '&'; | |
} | |
newpath += 'url=' + encodeURIComponent(contentURL.pathname + contentURL.search + contentURL.hash); | |
frameset.history.replaceState({}, contentframe.document.title, newpath); | |
} | |
}); | |
} | |
}; | |
init(); | |
}); |
This file contains hidden or 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
<script type="text/javascript" id="qut-topframe-mods"> | |
/** | |
* JS Hack: qut-pagetitles | |
* @author Christopher Baldwin [https://staff.qut.edu.au/details?id=baldwicc] | |
* @source [https://gist.github.com/baldwicc/6362607] | |
*/ | |
Event.observe(document, "dom:loaded", function() { | |
var t = { | |
opts: { | |
use_history_api: !0, | |
modify_banner: !0, | |
custom_frameset_title: !0 | |
}, | |
params: { | |
title: { | |
prefix: "QUT Bb DEV2", | |
seperator: " | " | |
}, | |
history: { | |
frameset: "/webapps/portal/frameset.jsp?" | |
}, | |
banner: { | |
elem: $$("#topTabs .brandingImgWrap a")[0], | |
target: "", | |
onclick: function() { | |
parent.window.location.replace("/"); | |
} | |
} | |
} | |
}, e = window.parent.document, a = (function() { | |
var t = e.getElementsByTagName("iframe"), a = e.getElementsByTagName("frame"); | |
return t.length ? t : a; | |
}(), function() { | |
try { | |
var t = $$("#appTabList > tbody > tr > td.active > a").first().href, e = t.match(/(tab_tab_group_id=)(_[0-9]+_[0-9]+)/)[2] || ""; | |
return e; | |
} catch (a) { | |
return ""; | |
} | |
}), r = function() { | |
var e = window.parent.frames.content, r = parent.window; | |
e && Event.observe(e.frameElement, "load", function() { | |
if (t.opts.custom_frameset_title && (r.document.title = [ t.params.title.prefix, e.courseTitle, e.document.title ].join(t.params.title.seperator)), | |
t.opts.modify_banner && t.params.banner.elem.writeAttribute({ | |
target: t.params.banner.target | |
}).observe("click", t.params.banner.onclick), t.opts.use_history_api && window.history && window.history.replaceState) { | |
var n = e.location, o = a(), i = t.params.history.frameset; | |
o && (i += "tab_tab_group_id=" + o + "&"), i += "url=" + encodeURIComponent(n.pathname + n.search + n.hash), | |
r.history.replaceState({}, e.document.title, i); | |
} | |
}); | |
}; | |
r(); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment