mirror of
https://github.com/discourse/discourse.git
synced 2025-09-08 12:06:51 +08:00
Use {{aceEditor}}
helper to display the ace editor
This commit is contained in:
parent
0601bb6d74
commit
fe3ac50aae
11 changed files with 50 additions and 74 deletions
14
app/assets/javascripts/admin/helpers/admin_helpers.js
Normal file
14
app/assets/javascripts/admin/helpers/admin_helpers.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/**
|
||||||
|
Inserts a rich code editor
|
||||||
|
|
||||||
|
@method aceEditor
|
||||||
|
@for Handlebars
|
||||||
|
**/
|
||||||
|
Ember.Handlebars.registerHelper('aceEditor', function(options) {
|
||||||
|
var hash = options.hash,
|
||||||
|
types = options.hashTypes;
|
||||||
|
|
||||||
|
Discourse.Utilities.normalizeHash(hash, types);
|
||||||
|
|
||||||
|
return Ember.Handlebars.helpers.view.call(this, Discourse.AceEditorView, options);
|
||||||
|
});
|
|
@ -26,10 +26,10 @@
|
||||||
{{#with selectedItem}}
|
{{#with selectedItem}}
|
||||||
{{textField class="style-name" value=name}}
|
{{textField class="style-name" value=name}}
|
||||||
{{#if view.headerActive}}
|
{{#if view.headerActive}}
|
||||||
{{view Discourse.AceEditorView contentBinding="header" mode="html"}}
|
{{aceEditor content=header mode="html"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if view.stylesheetActive}}
|
{{#if view.stylesheetActive}}
|
||||||
{{view Discourse.AceEditorView contentBinding="stylesheet" mode="css"}}
|
{{aceEditor content=stylesheet mode="css"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/with}}
|
{{/with}}
|
||||||
<br>
|
<br>
|
||||||
|
|
|
@ -91,7 +91,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{{#unless loading}}
|
{{#unless loading}}
|
||||||
{{ render 'admin_report_trust_levels' users_by_trust_level }}
|
{{ render 'admin/templates/reports/trust_levels_report' users_by_trust_level tagName="tbody" }}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -162,14 +162,14 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{{#unless loading}}
|
{{#unless loading}}
|
||||||
{{ render 'admin_report_visits' visits }}
|
{{ render 'admin/templates/reports/per_day_counts_report' visits tagName="tbody"}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="dashboard-right">
|
<div class="dashboard-right">
|
||||||
{{ render admin_github_commits githubCommits }}
|
{{ render 'admin/templates/commits' githubCommits }}
|
||||||
|
|
||||||
<div class="dashboard-stats">
|
<div class="dashboard-stats">
|
||||||
<table class="table table-condensed table-hover">
|
<table class="table table-condensed table-hover">
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if html}}
|
{{#if html}}
|
||||||
{{view Discourse.AceEditorView contentBinding="model.content" mode="html"}}
|
{{aceEditor content=model.content mode="html"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if css}}
|
{{#if css}}
|
||||||
{{view Discourse.AceEditorView contentBinding="model.content" mode="css"}}
|
{{aceEditor content=model.content mode="css"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,31 +34,25 @@ Discourse.AceEditorView = Discourse.View.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
var initAce,
|
|
||||||
_this = this;
|
|
||||||
|
|
||||||
initAce = function() {
|
var aceEditorView = this;
|
||||||
_this.editor = ace.edit(_this.$('.ace')[0]);
|
|
||||||
_this.editor.setTheme("ace/theme/chrome");
|
var initAce = function() {
|
||||||
_this.editor.setShowPrintMargin(false);
|
aceEditorView.editor = ace.edit(aceEditorView.$('.ace')[0]);
|
||||||
_this.editor.getSession().setMode("ace/mode/" + (_this.get('mode')));
|
aceEditorView.editor.setTheme("ace/theme/chrome");
|
||||||
return _this.editor.on("change", function(e) {
|
aceEditorView.editor.setShowPrintMargin(false);
|
||||||
/* amending stuff as you type seems a bit out of scope for now - can revisit after launch
|
aceEditorView.editor.getSession().setMode("ace/mode/" + (aceEditorView.get('mode')));
|
||||||
changes = @get('changes')
|
aceEditorView.editor.on("change", function(e) {
|
||||||
unless changes
|
aceEditorView.skipContentChangeEvent = true;
|
||||||
changes = []
|
aceEditorView.set('content', aceEditorView.editor.getSession().getValue());
|
||||||
@set('changes', changes)
|
aceEditorView.skipContentChangeEvent = false;
|
||||||
changes.push e.data
|
|
||||||
*/
|
|
||||||
_this.skipContentChangeEvent = true;
|
|
||||||
_this.set('content', _this.editor.getSession().getValue());
|
|
||||||
_this.skipContentChangeEvent = false;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (window.ace) {
|
if (window.ace) {
|
||||||
return initAce();
|
initAce();
|
||||||
} else {
|
} else {
|
||||||
return $LAB.script('http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js').wait(initAce);
|
$LAB.script('http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js').wait(initAce);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
/**
|
|
||||||
A view for showing commits to the discourse repo.
|
|
||||||
|
|
||||||
@class AdminGithubCommitsView
|
|
||||||
@extends Discourse.View
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
Discourse.AdminGithubCommitsView = Discourse.View.extend({
|
|
||||||
templateName: 'admin/templates/commits'
|
|
||||||
});
|
|
|
@ -1,4 +0,0 @@
|
||||||
Discourse.AdminGroupsView = Discourse.View.extend({
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
/**
|
|
||||||
The view that displays the number of users at each trust level
|
|
||||||
on the admin dashboard.
|
|
||||||
|
|
||||||
@class AdminReportTrustLevelsView
|
|
||||||
@extends Discourse.View
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
Discourse.AdminReportTrustLevelsView = Discourse.View.extend({
|
|
||||||
templateName: 'admin/templates/reports/trust_levels_report',
|
|
||||||
tagName: 'tbody'
|
|
||||||
});
|
|
|
@ -1,4 +0,0 @@
|
||||||
Discourse.AdminReportVisitsView = Discourse.View.extend({
|
|
||||||
templateName: 'admin/templates/reports/per_day_counts_report',
|
|
||||||
tagName: 'tbody'
|
|
||||||
});
|
|
|
@ -17,6 +17,18 @@ Discourse.Utilities = {
|
||||||
return size;
|
return size;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Allows us to supply bindings without "binding" to a helper.
|
||||||
|
**/
|
||||||
|
normalizeHash: function(hash, hashTypes) {
|
||||||
|
for (var prop in hash) {
|
||||||
|
if (hashTypes[prop] === 'ID') {
|
||||||
|
hash[prop + 'Binding'] = hash[prop];
|
||||||
|
delete hash[prop];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
categoryUrlId: function(category) {
|
categoryUrlId: function(category) {
|
||||||
if (!category) return "";
|
if (!category) return "";
|
||||||
var id = Em.get(category, 'id');
|
var id = Em.get(category, 'id');
|
||||||
|
|
|
@ -1,15 +1,3 @@
|
||||||
/**
|
|
||||||
Allows us to supply bindings without "binding" to a helper.
|
|
||||||
**/
|
|
||||||
function normalizeHash(hash, hashTypes) {
|
|
||||||
for (var prop in hash) {
|
|
||||||
if (hashTypes[prop] === 'ID') {
|
|
||||||
hash[prop + 'Binding'] = hash[prop];
|
|
||||||
delete hash[prop];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Breaks up a long string
|
Breaks up a long string
|
||||||
|
|
||||||
|
@ -78,7 +66,7 @@ Ember.Handlebars.registerHelper('textField', function(options) {
|
||||||
var hash = options.hash,
|
var hash = options.hash,
|
||||||
types = options.hashTypes;
|
types = options.hashTypes;
|
||||||
|
|
||||||
normalizeHash(hash, types);
|
Discourse.Utilities.normalizeHash(hash, types);
|
||||||
|
|
||||||
return Ember.Handlebars.helpers.view.call(this, Discourse.TextField, options);
|
return Ember.Handlebars.helpers.view.call(this, Discourse.TextField, options);
|
||||||
});
|
});
|
||||||
|
@ -93,7 +81,7 @@ Ember.Handlebars.registerHelper('inputTip', function(options) {
|
||||||
var hash = options.hash,
|
var hash = options.hash,
|
||||||
types = options.hashTypes;
|
types = options.hashTypes;
|
||||||
|
|
||||||
normalizeHash(hash, types);
|
Discourse.Utilities.normalizeHash(hash, types);
|
||||||
|
|
||||||
return Ember.Handlebars.helpers.view.call(this, Discourse.InputTipView, options);
|
return Ember.Handlebars.helpers.view.call(this, Discourse.InputTipView, options);
|
||||||
});
|
});
|
||||||
|
@ -108,7 +96,7 @@ Ember.Handlebars.registerHelper('popupInputTip', function(options) {
|
||||||
var hash = options.hash,
|
var hash = options.hash,
|
||||||
types = options.hashTypes;
|
types = options.hashTypes;
|
||||||
|
|
||||||
normalizeHash(hash, types);
|
Discourse.Utilities.normalizeHash(hash, types);
|
||||||
|
|
||||||
return Ember.Handlebars.helpers.view.call(this, Discourse.PopupInputTipView, options);
|
return Ember.Handlebars.helpers.view.call(this, Discourse.PopupInputTipView, options);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue