mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-01 20:14:55 +00:00
userbar embed code now separated into own file, with postmessage enabled to allow cross-frame coms to adapt frame height
This commit is contained in:
parent
cbe4ce2913
commit
82158a49db
4 changed files with 51 additions and 10 deletions
|
|
@ -1,7 +1,13 @@
|
|||
/* No jQuery to speed up loading */
|
||||
document.addEventListener('DOMContentLoaded', function(){
|
||||
var body = document.querySelectorAll('body')[0];
|
||||
var nav = document.querySelectorAll('nav')[0];
|
||||
var className = 'ready';
|
||||
var has_pm = window.postMessage;
|
||||
|
||||
if(has_pm){
|
||||
parent.postMessage("fh=" + nav.offsetHeight, '*');
|
||||
}
|
||||
|
||||
if (body.classList){
|
||||
body.classList.add(className);
|
||||
|
|
|
|||
36
wagtail/wagtailadmin/static/wagtailadmin/js/userbar_embed.js
Normal file
36
wagtail/wagtailadmin/static/wagtailadmin/js/userbar_embed.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
(function(w,d){
|
||||
var l, f, h, frame_height;
|
||||
|
||||
if(!w.wagtail) return;
|
||||
|
||||
if(w.postMessage){
|
||||
function callback(e){
|
||||
// Get the height from the passed data.
|
||||
var h = Number(e.data.replace( /.*fh=(\d+)(?:&|$)/, '$1' ) );
|
||||
if (!isNaN( h ) && h > 0 && h !== frame_height) {
|
||||
f.style.height = h + "px";
|
||||
}
|
||||
}
|
||||
|
||||
if (w.addEventListener) {
|
||||
w.addEventListener('message', callback, false);
|
||||
} else {
|
||||
w.attachEvent('onmessage', callback );
|
||||
}
|
||||
}
|
||||
|
||||
l = d.createElement('link');
|
||||
l.rel = 'stylesheet';
|
||||
l.href = w.wagtail.static_root + 'scss/userbar_embed.css';
|
||||
|
||||
f = d.createElement('iframe');
|
||||
f.id = 'wagtail-userbar';
|
||||
f.frameborder = '0';
|
||||
f.allowtransparency = 'true';
|
||||
f.scrolling = 'no';
|
||||
f.src = w.wagtail.userbar_src;
|
||||
|
||||
t = d.getElementsByTagName('title')[0];
|
||||
t.parentNode.insertBefore(l, t.nextSibling);
|
||||
d.body.appendChild(f);
|
||||
}(window,document));
|
||||
|
|
@ -19,7 +19,7 @@ nav{
|
|||
float:right;
|
||||
|
||||
/* moving menu only for browser that can support hover and transitions */
|
||||
.no-touch & {
|
||||
.no-touch .ready & {
|
||||
ul{
|
||||
height:0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
{% load static %}
|
||||
<!-- Wagtail user bar embed code -->
|
||||
<script type="text/javascript">
|
||||
(function(w,d){
|
||||
var l, f, h;
|
||||
l = d.createElement('link'); l.rel = 'stylesheet';
|
||||
l.href = '{% static "wagtailadmin/scss/userbar_embed.css" %}';
|
||||
f = d.createElement('iframe'); f.id = 'wagtail-userbar'; f.frameborder = '0'; f.allowtransparency = 'true'; f.scrolling = 'no';
|
||||
f.src = '{% if revision_id %}{% url "wagtailadmin_userbar_moderation" revision_id %}{% else %}{% url "wagtailadmin_userbar_frontend" page.self.id %}{% endif %}';
|
||||
t = d.getElementsByTagName('title')[0]; t.parentNode.insertBefore(l, t.nextSibling);
|
||||
d.body.appendChild(f);
|
||||
}(window,document));
|
||||
var wagtail = wagtail || {};
|
||||
wagtail.static_root = '{% static "wagtailadmin/" %}';
|
||||
wagtail.userbar_src = '{% if revision_id %}{% url "wagtailadmin_userbar_moderation" revision_id %}{% else %}{% url "wagtailadmin_userbar_frontend" page.self.id %}{% endif %}';
|
||||
(function(d) {
|
||||
var u = d.createElement('script'); u.type = 'text/javascript'; u.async = true;
|
||||
u.src = '{% static "wagtailadmin/js/userbar_embed.js" %}';
|
||||
var s = d.getElementsByTagName('script')[0]; s.parentNode.insertBefore(u, s);
|
||||
})(document);
|
||||
</script>
|
||||
<!-- end Wagtail user bar embed code -->
|
||||
Loading…
Reference in a new issue