Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
make ace work without applyAuthorStyles
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Jan 30, 2014
1 parent 26d5a89 commit c69b6f9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ace-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,28 @@
<div class="ajaxorg-ace" id="editor"></div>
</template>
<script>
(function(style) {
Polymer('ace-element', {
mode: 'javascript',
theme: 'monokai',
readonly: false,
value: null,
wrap: false,
// allow styling from the outside world!
applyAuthorStyles: true,
//applyAuthorStyles: true,
registerCallback: function(polymerElt) {
var selectors = [
'#ace_editor',
'#ace-tm'
];
var content = polymerElt.templateContent();
for (var i=0, l=selectors.length, s, n; (i<l) && (s=selectors[i]); i++) {
n = document.querySelector(s);
if (n) {
content.appendChild(cloneStyle(n));
}
}
},
// TODO(sorvell): to work in IE reliably, can only be
// created in enteredView. However, api that wants to access this.editor
// may be used before that. Instead of making each function bail if
Expand Down Expand Up @@ -71,6 +85,13 @@
},
themeChanged: function() {
this.editor.setTheme('ace/theme/' + this.theme);
// find style
this.onMutation(document.head, function() {
var style = document.querySelector('#ace-' + this.theme);
if (style) {
this.shadowRoot.appendChild(cloneStyle(style));
}
});
},
valueChanged: function() {
this.editorValue = this.value;
Expand Down Expand Up @@ -140,5 +161,13 @@
this.editor.focus();
}
});

// IE safe style clone
function cloneStyle(style) {
var s = document.createElement('style');
s.textContent = style.textContent;
return s;
}
})();
</script>
</polymer-element>

0 comments on commit c69b6f9

Please sign in to comment.