-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shimul Chowdhury
committed
Apr 10, 2019
1 parent
f9537fa
commit ebbc68b
Showing
5 changed files
with
129 additions
and
77 deletions.
There are no files selected for viewing
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
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
22 changes: 22 additions & 0 deletions
22
hypereditor/templates/hypereditor/edit_handlers/hyper_editor_field_panel.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% load wagtailadmin_tags static %} | ||
|
||
{% with 'hef_'|add:identifier as field_id %} | ||
{% with 'hei_'|add:identifier as iframe_id %} | ||
|
||
<fieldset style="margin-right:0px;width: 100%;max-width: 100%;"> | ||
|
||
<legend>{{ self.heading }}</legend> | ||
|
||
<ul class="fields"> | ||
<li id="{{ field_id }}" , style="display:none"> | ||
{% include "wagtailadmin/shared/field.html" with show_label=False show_help_text=False %} | ||
</li> | ||
</ul> | ||
|
||
{% include 'hypereditor/partials/editor_iframe.html' with field_id=field_id iframe_id=iframe_id %} | ||
|
||
</fieldset> | ||
|
||
{% endwith %} | ||
{% endwith %} | ||
|
73 changes: 73 additions & 0 deletions
73
hypereditor/templates/hypereditor/partials/editor_iframe.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<iframe name="editorIframe" src="#" frameborder="0" width="100%" marginheight="0" marginwidth="0" | ||
id="{{ iframe_id }}"></iframe> | ||
|
||
<script> | ||
(function () { | ||
var field_id = '{{ field_id }}' | ||
var iframe_id = '{{ iframe_id }}' | ||
|
||
function guid() { | ||
function s4() { | ||
return Math.floor((1 + Math.random()) * 0x10000) | ||
.toString(16) | ||
.substring(1); | ||
} | ||
|
||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); | ||
} | ||
|
||
// generate an unique id param | ||
var id = guid() | ||
|
||
// initialize iframe | ||
var iframe = document.querySelector('#' + iframe_id); | ||
iframe.src = '{% url 'hypereditor:editor' %}' + '?id=' + id | ||
|
||
// get iframe window object | ||
var iframeWindow = (iframe.contentWindow || iframe.contentDocument); | ||
|
||
function getHiddenEditor() { | ||
return document.querySelector('#' + field_id + ' #hyperHiddenField') | ||
} | ||
|
||
// get hidden textarea | ||
var hiddenEditor = getHiddenEditor() | ||
|
||
// polyfill window localtion origin | ||
if (!window.location.origin) { | ||
window.location.origin = window.location.protocol + "//" | ||
+ window.location.hostname | ||
+ (window.location.port ? ':' + window.location.port : ''); | ||
} | ||
|
||
function set_height() { | ||
var height = Math.max(iframe.contentWindow.document.body.scrollHeight, 500) | ||
iframe.height = height + "px" | ||
} | ||
|
||
iframe.onload = function () { | ||
|
||
if (hiddenEditor.value && hiddenEditor.value != '') { | ||
iframeWindow.postMessage({ | ||
id: id, | ||
state: hiddenEditor.value | ||
}, window.location.origin) | ||
} else { | ||
iframeWindow.postMessage({ | ||
id: id, | ||
state: '[]' | ||
}, window.location.origin) | ||
} | ||
|
||
window.addEventListener('message', function (e) { | ||
if (e.data && e.data.id == id) { | ||
getHiddenEditor().value = e.data.state | ||
set_height() | ||
} | ||
|
||
}, false); | ||
|
||
set_height() | ||
} | ||
})() | ||
</script> |
83 changes: 8 additions & 75 deletions
83
hypereditor/templates/hypereditor/widgets/hyper_widget.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,14 @@ | ||
{% load static %} | ||
{% with 'hef_'|add:identifier as field_id_str %} | ||
{% with 'hei_'|add:identifier as iframe_id_str %} | ||
<div id="{{ field_id_str }}"> | ||
<textarea style="display:none" name="{{ widget.name }}" class="no-widget-init" id="hyperHiddenField"> | ||
{% if widget.value %}{{ widget.value }}{% endif %}</textarea> | ||
|
||
{% with 'hef_'|add:identifier as field_id %} | ||
{% with 'hei_'|add:identifier as iframe_id %} | ||
|
||
<iframe name="editorIframe" src="#" frameborder="0" width="100%" marginheight="0" marginwidth="0" id="{{ iframe_id_str }}"></iframe> | ||
<div id="{{ field_id }}"> | ||
|
||
<script> | ||
(function () { | ||
var field_id = '{{ field_id_str }}' | ||
var iframe_id = '{{ iframe_id_str }}' | ||
<textarea style="display:none" name="{{ widget.name }}" class="no-widget-init" | ||
id="hyperHiddenField">{% if widget.value %}{{ widget.value }}{% endif %}</textarea> | ||
|
||
function guid() { | ||
function s4() { | ||
return Math.floor((1 + Math.random()) * 0x10000) | ||
.toString(16) | ||
.substring(1); | ||
} | ||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); | ||
} | ||
|
||
// generate an unique id param | ||
var id = guid() | ||
|
||
// initialize iframe | ||
var iframe = document.querySelector('#'+iframe_id); | ||
iframe.src = '{% url 'hypereditor:editor' %}' + '?id=' + id | ||
|
||
// get iframe window object | ||
var iframeWindow = (iframe.contentWindow || iframe.contentDocument); | ||
|
||
function getHiddenEditor() { | ||
return document.querySelector('#'+field_id + ' #hyperHiddenField') | ||
} | ||
// get hidden textarea | ||
var hiddenEditor = getHiddenEditor() | ||
|
||
// polyfill window localtion origin | ||
if (!window.location.origin) { | ||
window.location.origin = window.location.protocol + "//" | ||
+ window.location.hostname | ||
+ (window.location.port ? ':' + window.location.port : ''); | ||
} | ||
|
||
function set_height() { | ||
var height = Math.max(iframe.contentWindow.document.body.scrollHeight, 500) | ||
iframe.height= height + "px" | ||
} | ||
|
||
iframe.onload = function() { | ||
|
||
if (hiddenEditor.value && hiddenEditor.value != '') { | ||
iframeWindow.postMessage({ | ||
id: id, | ||
state: hiddenEditor.value | ||
}, window.location.origin) | ||
} else { | ||
iframeWindow.postMessage({ | ||
id: id, | ||
state: '[]' | ||
}, window.location.origin) | ||
} | ||
|
||
window.addEventListener('message',function(e) { | ||
if (e.data && e.data.id == id) { | ||
getHiddenEditor().value = e.data.state | ||
set_height() | ||
} | ||
|
||
},false); | ||
|
||
set_height() | ||
} | ||
})() | ||
</script> | ||
</div> | ||
{% endwith %} | ||
{% include 'hypereditor/partials/editor_iframe.html' with field_id=field_id iframe_id=iframe_id %} | ||
</div> | ||
{% endwith %} | ||
{% endwith %} |