forked from chairuosen/vue2-ace-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 1010454
Showing
2 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
var ace = require('brace'); | ||
|
||
require(['emmet/emmet'],function (data) { | ||
window.emmet = data.emmet; | ||
}); | ||
|
||
module.exports = { | ||
template:"<div :style=\"{height: height ? height+'px' : '100%',width: width ? width+'px' : '100%'}\"></div>", | ||
props:{ | ||
content:{ | ||
type:String, | ||
twoWay:true, | ||
required:true | ||
}, | ||
lang:String, | ||
theme:String, | ||
height:true, | ||
width:true | ||
}, | ||
data: function () { | ||
return { | ||
editor:null, | ||
contentBackup:"" | ||
} | ||
}, | ||
methods: {}, | ||
components: {}, | ||
watch:{ | ||
content:function (val) { | ||
if(this.contentBackup !== val) | ||
this.editor.setValue(val,1); | ||
} | ||
}, | ||
ready: function () { | ||
var vm = this; | ||
var lang = this.lang||'text'; | ||
var theme = this.theme||'chrome'; | ||
require('brace/mode/'+lang); | ||
require('brace/theme/'+theme); | ||
require('brace/ext/emmet'); | ||
|
||
var editor = vm.editor = ace.edit(this.$el); | ||
editor.$blockScrolling = Infinity; | ||
editor.setOption("enableEmmet", true); | ||
|
||
editor.getSession().setMode('ace/mode/'+lang); | ||
editor.setTheme('ace/theme/'+theme); | ||
|
||
editor.setValue(this.content,1); | ||
|
||
editor.on('change',function () { | ||
vm.content = editor.getValue(); | ||
vm.contentBackup = vm.content; | ||
}); | ||
|
||
} | ||
} |
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,23 @@ | ||
{ | ||
"name": "vue-ace-editor", | ||
"version": "1.0.0", | ||
"description": "A Vue's component based on ace/brace", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/chairuosen/vue-ace-editor.git" | ||
}, | ||
"author": "chairuosen", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/chairuosen/vue-ace-editor/issues" | ||
}, | ||
"homepage": "https://github.com/chairuosen/vue-ace-editor#readme", | ||
"dependencies": { | ||
"brace": "^0.8.0", | ||
"emmet": "git+https://github.com/cloud9ide/emmet-core.git" | ||
} | ||
} |