- init: function(element, template) {
- this.element = $(element);
- this.template = template || this.template;
- this.element.html(render_template(this.template, {}));
+ init: function(element, model, parent, template) {
+ this._super(element, model, template);
+ this.parent = parent;
+ this.buttonToolbar = new ButtonToolbarView(
+ $('.xmlview-toolbar', this.element),
+ this.model.toolbarButtonsModel, parent);
+
+ this.hotkeys = [];
+ var self = this;
+
+ $('.xmlview-toolbar', this.element).bind('resize.xmlview', this.resized.bind(this));
+
+ // scroll to the given position (if availble)
+ this.scrollCallback = this.scrollOnRequest.bind(this);
+ $(document).bind('xml-scroll-request', this.scrollCallback);
+
+ this.parent.freeze('Ładowanie edytora...');
+ this.editor = new CodeMirror($('.xmlview', this.element).get(0), {
+ parserfile: 'parsexml.js',
+ path: "/static/js/lib/codemirror/",
+ stylesheet: "/static/css/xmlcolors.css",
+ parserConfig: {
+ useHTMLKludges: false
+ },
+ textWrapping: true,
+ tabMode: 'spaces',
+ indentUnit: 0,
+ onChange: this.editorDataChanged.bind(this),
+ initCallback: this.editorDidLoad.bind(this)
+ });
+ },
+
+ resized: function(event) {
+ var height = this.element.height() - $('.xmlview-toolbar', this.element).outerHeight();
+ $('.xmlview', this.element).height(height);
+ },
+
+ reload: function() {
+ this.model.load(true);
+ },
+
+ editorDidLoad: function(editor) {
+ $(editor.frame).css({
+ width: '100%',
+ height: '100%'
+ });
+ this.model
+ .addObserver(this, 'data', this.modelDataChanged.bind(this))
+ .addObserver(this, 'state', this.modelStateChanged.bind(this))
+ .load();