コード例 #1
0
ファイル: item-step.js プロジェクト: brancusi/add-flour
  didInsertElement: function(){

    var editor = AceEditor.edit(this.$('.editor')[0]);

    editor.setValue('Add 1 tbsp of salt');
    editor.clearSelection();

    var session = editor.getSession();

    session.setUseWrapMode(true);

    editor.setOptions({
      maxLines:5,
      fontSize:18,
      showPrintMargin:false,
      showGutter:false,
      highlightActiveLine:false,
      // enableBasicAutocompletion: true,
      // enableSnippets: true,
      // enableLiveAutocompletion: true
    });

    this.set('editor', editor);
    this.set('session', session);

    this._createListeners();

    this._refreshTokens();
  },
コード例 #2
0
ファイル: xml_editor.js プロジェクト: kphongph/nodejs-cmuxml
 exports.edit = function(context) {
     var container = document.getElementById(context.element);
     //var container = $('#'+el);
     var editor = ace.edit(container);        
     editor.commands.addCommands([{
         name: "prettyprint",
         bindKey: {win:"Ctrl-P"},
         exec: function(editor) {
             editor.setValue(vkbeautify.xml(editor.getValue(),2)); 
             editor.clearSelection();         
         }
     },{
         name: "converttojson",
         bindKey: {win:"Ctrl-Y"},
         exec: function(editor,env) {
             $.ajax({
                 url: 'ajax/xml2json',
                 type: 'POST',            
                 data: JSON.stringify({ xml: editor.getValue()}),
                 contentType: "application/json; charset=utf-8",
                 dataType: "json",                        
                 success: function(data) {                    
                   context.convert(data);
                 }
             });
         }
     }]);
     
     editor.setFadeFoldWidgets(false);
     editor.getSession().setMode(new XMLmode());
     editor.getSession().setFoldStyle("markbegin");
     editor.setFontSize(14);
     return editor;
 };            
コード例 #3
0
ファイル: Saturn.js プロジェクト: erixyuan/Saturn
    require(['ace/ext/emmet'],function(a){
        aceEditor =  ace.edit(option.ACE_id);
        aceEditor.session.setValue($(option.textarea_id).val());

        aceEditor.session.setMode("ace/mode/html");
        aceEditor.setOption("enableEmmet", true);
        aceEditor.setTheme("ace/theme/"+(option.codeTheme == 1 ? 'monokai' : 'xcode'));
        aceEditor.setOption("fontSize", 12);
        aceEditor.setOption("highlightActiveLine", true);
        aceEditor.setOption("tabSize", '4');
        aceEditor.setOption("showGutter", true);
        aceEditor.setOption("showFoldWidgets", true);
        aceEditor.setOption("fadeFoldWidgets", true);
        aceEditor.setOption("printMargin", false);
        aceEditor.setOption("showPrintMargin", false);
        aceEditor.setOption("showInvisibles", true);
        aceEditor.setOption("hScrollBarAlwaysVisible", true);
        aceEditor.setOption("highlightGutterLine", true);
        aceEditor.setOption("wrap", true);
        aceEditor.setOption("hScrollBarAlwaysVisible", false);
        // 自动配对符号
        // aceEditor.setOption("behavioursEnabled", ture);

        aceEditor.on('change',function(){
            $(option.textarea_id).val(aceEditor.session.getValue());
        })
    })
コード例 #4
0
var join = function(id) {
    var editor = ace.edit(id);
    id = editors.push(editor) - 1;
    editor.otDoc = new OTDocument(editor.session, ui);
    
    editor.outgoing = [];
    editor.incoming = [];
    
    editor.otDoc.init({
        "userId": id,
        "clientId": id,
        "docId": id,
        "selections": {},
        "authAttribs": [],
        "contents": "",
        "starRevNums": [],
        "revNum": 0,
        "revisions": [
            {
                "id": 300,
                "contents": "",
                "operation": [],
                "revNum": 0,
                "deleted_at": null,
                "document_id": 6
            }
        ]
    });
    return editor;
};
コード例 #5
0
ファイル: index.js プロジェクト: mancobian/webide-old
this.init = function(editorId) {
  if (typeof(element) == "string") {
    element = document.getElementById(element);
  }

  this.editor = Ace.edit(editorId);
  this.editor.setTheme(require('ace/theme/textmate'));
  this.editor.setKeyboardHandler(require('ace/keyboard/vim').handler);
  this.editor.focus();
  return this.editor;
};
コード例 #6
0
ファイル: FDEditor.Ace.js プロジェクト: anushbmx/FlightDeck
	initialize: function(wrapper, options) {
		this.parent(wrapper, options);
		this.editor = ace.edit(this.element);
		this.editor.getSession().setUseWorker(false);
		this.spinner = new Spinner(this.element.getElement('.ace_scroller'), {
			maskBorder: false
		});
		var that = this;
		
		['blur', 'focus'].each(function(ev) {
			that.editor.on(ev, function(){
				that.fireEvent(ev);
			});
		});
	},
コード例 #7
0
ファイル: editor.js プロジェクト: nteg/HTML5
            _.defer(function () {
                try {
                    debug("Initializing Ace editor on div: #" + _this.elementId);
                    _this.$el.hide();
                    _this.aceEditor = window.editor = ace.edit(_this.elementId);

                    if (_this.model.get("filePath")) {
                        _this.loadFile();
                    } else {
                        _this.aceEditor.setValue(_this.helpContent);
                    }
                    
                    _this.aceEditor.clearSelection();
                    _this.aceEditor.gotoLine(1);
                    _this.setTheme();
                    _this.aceEditor.getSession().selection.on("changeCursor", function (e) {
                        if (_this.isCursorChangeHandlerActive) {
                            _this.setLastCursorPosition();
                        }
                    });
                    _this.aceEditor.commands.addCommand({
                        name: "saveFile",
                        bindKey: {win: 'Ctrl-S',  mac: 'Command-S'},
                        exec: function(editor) {
                            var filePath = _this.model.get("filePath"),
                                contents = _this.aceEditor.getValue();
                                
                            shell.saveFile(filePath, contents, function (res){
                                if (res.success) {
                                    debug("File saved: " + filePath);
                                    animate.saveSuccessful(_this.$el);
                                } else {
                                    debug("Could not save file to disk: " + filePath);
                                    animate.saveFailure(_this.$el);
                                }
                            });
                        },
                        readOnly: true // false if this command should not apply in readOnly mode
                    });

                    _this.$el.fadeIn();
                    _this.trigger("initialized");
                } catch (err) {
                    debug(err.message, err.stack);
                }
            });
コード例 #8
0
ファイル: cell.js プロジェクト: jiggliemon/peg.io
  ,setupEditor: function () {
    var self = this
    if ( self.__editorSetup ) {
      return self.editor 
    }

    var editor = self.editor = Editor.edit(document.createElement('pre'))
    self.addEvent('after:toElement', function () {
      var editorWrapper = self.bound('editor')
      if ( editorWrapper ) {
        editorWrapper.appendChild(editor.container)
      }
    })

    editor.setValue(self.getText())
    self.__editorSetup = true
    return editor
  }
コード例 #9
0
 }).click(function(){
     var c = counter++;
     var e = document.createElement("div");
     var _e = document.createElement("div");
     var ta = document.createElement("textarea");
     $(e).attr("id","editor_"+c).addClass("maineditor");
     $(_e).addClass("_maineditor");
     $(ta).addClass("text_part");
     $("#contentArea").append(e).append(_e).append(ta);
     var edi = editors["editor_"+c] = ace.edit("editor_"+c);
     docs["editor_"+c] = edi.getSession().getDocument();
     var modeType = $(this).html().toString();
     edi.getSession().setMode(new modes[modeType]());
     langs.push(modeType);
     intervals["editor_"+c] = setInterval(function(){
         resize(e,_e);
     },1000);
     
 });
コード例 #10
0
ファイル: editor.js プロジェクト: cs-education/sysbuild
    initAce(editorDivId) {
        this.editorDivId = editorDivId;
        this.aceEditor = ace.edit(editorDivId);

        // Fix for the following Ace warning:
        // "Automatically scrolling cursor into view after selection change this will be disabled
        // in the next version set editor.$blockScrolling = Infinity to disable this message"
        this.aceEditor.$blockScrolling = Infinity;

        this.setAceMode('c_cpp');
        this.aceEditor.getSession().setTabSize(4);
        this.aceEditor.getSession().setUseSoftTabs(false);

        this.setAceTheme(this.prefs.theme());
        this.prefs.theme.subscribe((newTheme) => { this.setAceTheme(newTheme); });

        this.setAceFontSize(this.prefs.fontSize() + 'px');
        this.prefs.fontSize.subscribe((newFontSize) => { this.setAceFontSize(newFontSize + 'px'); });

        this.setAceHighlightActiveLine(this.prefs.highlightLine());
        this.prefs.highlightLine.subscribe((newVal) => { this.setAceHighlightActiveLine(newVal); });

        this.setAceShowInvisbles(this.prefs.showInvisibles());
        this.prefs.showInvisibles.subscribe((newVal) => { this.setAceShowInvisbles(newVal); });

        this.setAceAnnotations(this.annotations());
        this.annotations.subscribe((newVal) => { this.setAceAnnotations(newVal); });

        this.keyboardShortcuts.forEach((shortcutArgs) => this.addKeyboardCommand(...shortcutArgs));

        ace.require(['ace/ext/modelist'], (modelist) => {
            this.modelist = modelist;
        }).bind(this);

        // TODO Disabling auto indenting until it can be fixed (removes annotations and indents non C files)
        // this.enableAutoIndentTimer();
    }
コード例 #11
0
define(function(require, exports, module) {
	require("ace/lib/fixoldbrowsers");
	require("ace/config").init();
	var env = {};
    
    var ace = require("ace/ace");
	var dom = require("ace/lib/dom");
	var net = require("ace/lib/net");

	var event = require("ace/lib/event");
	var theme = require("ace/theme/textmate");
	var EditSession = require("ace/edit_session").EditSession;
	var UndoManager = require("ace/undomanager").UndoManager;

	var vim = require("ace/keyboard/vim").handler;
	var emacs = require("ace/keyboard/emacs").handler;
	var HashHandler = require("ace/keyboard/hash_handler").HashHandler;

	var Renderer = require("ace/virtual_renderer").VirtualRenderer;
	var Editor = require("ace/editor").Editor;
	var MultiSelect = require("ace/multi_select").MultiSelect;
    console.log("editor start");

    var modeMap = {
        'javascript' : 'ace/mode/javascript',
        'css'        : 'ace/mode/css',
        'java'       : 'ace/mode/java',
        'perl'       : 'ace/mode/perl',
        'php'        : 'ace/mode/php',
        'html'       : 'ace/mode/html',
        'ruby'       : 'ace/mode/ruby',
        'python'     : 'ace/mode/python',
        'xml'        : 'ace/mode/xml'
    };
    var modes = {};
    modes.javascript = require("ace/mode/javascript").Mode;
    modes.css = require("ace/mode/css").Mode;
    modes.java = require("ace/mode/java").Mode;
    modes.perl = require("ace/mode/perl").Mode;
    modes.php = require("ace/mode/php").Mode;
    modes.html = require("ace/mode/html").Mode;
    modes.ruby = require("ace/mode/ruby").Mode;
    modes.python = require("ace/mode/python").Mode;
    modes.xml = require("ace/mode/xml").Mode;

    var counter = 0;

    var editors = {},
        docs = {},
        intervals = {},
        langs=[];

    $(".ace_print_margin").css("visibility","hidden");
     


    require("libs/jquery/jquery-min");
    var obj = $("#maineditor");

    
    $("input").focus(function(){
        $(this).css({"border-color":"#aaa","background-color":"#F7F7F7"});
    });
    $("input").blur(function(){
        $(this).css({"border-color":"#ccc","background-color":"white"});
    });

    $("#fortext").click(function(){
        var p = editor.getSession().getSelection().getCursor();
        
        doc.insert(p,"$text$ ");
        editor.focus();
        var w = {};
        w.row = p.row;
        w.column = p.column+8;
        doc.insert(w," $/text$");
    
    });

  
    //for codeBtn behavior
    $("#codeBtn").hover(function(){
        $("#modeSelection").css("display","block");
        $(this).css({"border":"1px solid #aaa","background":"#f7f7f7","border-radius":"5px"});
    },function(){
        $("#modeSelection").css("display","none");
        $(this).css({"border":"none","background":"none","border-radius":"none"});

    });

    // for modeBtn behavior
    $(".modeBtn").hover(function(){
        $(this).css("color","#666");
    },function(){
        $(this).css("color","#999");
    }).click(function(){
        var c = counter++;
        var e = document.createElement("div");
        var _e = document.createElement("div");
        var ta = document.createElement("textarea");
        $(e).attr("id","editor_"+c).addClass("maineditor");
        $(_e).addClass("_maineditor");
        $(ta).addClass("text_part");
        $("#contentArea").append(e).append(_e).append(ta);
        var edi = editors["editor_"+c] = ace.edit("editor_"+c);
        docs["editor_"+c] = edi.getSession().getDocument();
        var modeType = $(this).html().toString();
        edi.getSession().setMode(new modes[modeType]());
        langs.push(modeType);
        intervals["editor_"+c] = setInterval(function(){
            resize(e,_e);
        },1000);
        
    });

    // resize the editor to make all content visible
    function resize(obj,_obj){
            var id = $(obj).attr("id");
            var HEIGHT = 17;
            var len = docs[id].getLength();
            var hei = len*HEIGHT+20<200?200:len*HEIGHT+20;
            $(obj).height(hei);
            $(_obj).height(hei);
            editors[id].resize();
    }
    

    // when srcoll , make sure that code button is visible
    window.onscroll = function(){
        console.log(document.body.scrollTop);
        if(document.body.scrollTop >= 400){
            var l = $("#editor").offset().left+$("#editor").width();
            $("#codeBtn").css("position","fixed").css("left",l);

        }
        if(document.body.scrollTop < 400){
            $("#codeBtn").css('position','absolute').css('left','auto');
        }
    }

    // for edit page , if maineditor is already existed ,
    // render them
   if($(".maineditor")[0]){
        console.log("maineditor existed");
        var es = $(".maineditor");
        var len = $(".maineditor").len;
        counter = len;
        for(var i=0;i<len;i++){
            var modeType = $(es[i]).attr("mode");
            var editor = editors["editor_"+i] = ace.edit(es[i]);
            docs["editor_"+i] = edi.getSession().getDocument();
            editor.getSession().setMode(new modes[modeType]());
        }
   }

    // for submit
    var form = $("form");
    form.submit(function(){
        for(var va in intervals){
            clearInterval(intervals[va]);
        }
    	var code = $(".ace_text-layer");
        var cs = [] ;
        for(var i=0;i<counter;i++){
            cs.push($(code[i]).html());
        }
        var codes = cs.join("$code$");

        var lines = [];
        for(var va in docs){
            var len = docs[va].getLength();
            lines.push(docs[va].getAllLines().join("\n")+"$length$"+len);
        }
        var lines = lines.join("$line$");
       
        var text = $(".text_part");
        var texts = [];
        for(var i=0;i<counter+1;i++){
            texts.push($(text[i]).val());
        }
        texts = texts.join("$text$");

        langs = langs.join("$lang$");

        var ta = $("#detail_content");
    	ta.html([texts,codes].join("$part$"));
        var _ta = $("#simple_content");
        _ta.html([lines,langs].join("$part$"));
        
        console.log(ta.html());
        console.log(_ta.html());
    	$("#contentArea").remove();
    }); 

     
});