/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/js/ace/ext-static_highlight.js

  • Committer: galaxyAbstractor
  • Date: 2013-04-10 15:49:32 UTC
  • mto: (19.1.5 lenasys)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: galaxyabstractor@gmail.com-20130410154932-4vizlzk0ar5gykvi
* Added an simple admin panel to the codeviewer-cmssy stuff
* Redesigned a bit like the mockups - still stuff to come
* Implemented the codeviewer + admin panel again using the Framework CodeIgniter instead 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Distributed under the BSD license:
 
3
 *
 
4
 * Copyright (c) 2010, Ajax.org B.V.
 
5
 * All rights reserved.
 
6
 * 
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions are met:
 
9
 *     * Redistributions of source code must retain the above copyright
 
10
 *       notice, this list of conditions and the following disclaimer.
 
11
 *     * Redistributions in binary form must reproduce the above copyright
 
12
 *       notice, this list of conditions and the following disclaimer in the
 
13
 *       documentation and/or other materials provided with the distribution.
 
14
 *     * Neither the name of Ajax.org B.V. nor the
 
15
 *       names of its contributors may be used to endorse or promote products
 
16
 *       derived from this software without specific prior written permission.
 
17
 * 
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
19
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
21
 * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
 
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
 *
 
29
 * ***** END LICENSE BLOCK ***** */
 
30
 
 
31
define('ace/ext/static_highlight', ['require', 'exports', 'module' , 'ace/edit_session', 'ace/layer/text'], function(require, exports, module) {
 
32
 
 
33
 
 
34
var EditSession = require("../edit_session").EditSession;
 
35
var TextLayer = require("../layer/text").Text;
 
36
var baseStyles = ".ace_editor {\
 
37
font-family: 'Monaco', 'Menlo', 'Droid Sans Mono', 'Courier New', monospace;\
 
38
font-size: 12px;\
 
39
}\
 
40
.ace_editor .ace_gutter { \
 
41
width: 25px !important;\
 
42
display: block;\
 
43
float: left;\
 
44
text-align: right; \
 
45
padding: 0 3px 0 0; \
 
46
margin-right: 3px;\
 
47
}\
 
48
.ace_line { clear: both; }\
 
49
*.ace_gutter-cell {\
 
50
-moz-user-select: -moz-none;\
 
51
-khtml-user-select: none;\
 
52
-webkit-user-select: none;\
 
53
user-select: none;\
 
54
}";
 
55
 
 
56
exports.render = function(input, mode, theme, lineStart, disableGutter) {
 
57
    lineStart = parseInt(lineStart || 1, 10);
 
58
    
 
59
    var session = new EditSession("");
 
60
    session.setMode(mode);
 
61
    session.setUseWorker(false);
 
62
    
 
63
    var textLayer = new TextLayer(document.createElement("div"));
 
64
    textLayer.setSession(session);
 
65
    textLayer.config = {
 
66
        characterWidth: 10,
 
67
        lineHeight: 20
 
68
    };
 
69
    
 
70
    session.setValue(input);
 
71
            
 
72
    var stringBuilder = [];
 
73
    var length =  session.getLength();
 
74
 
 
75
    for(var ix = 0; ix < length; ix++) {
 
76
        stringBuilder.push("<div class='ace_line'>");
 
77
        if (!disableGutter)
 
78
            stringBuilder.push("<span class='ace_gutter ace_gutter-cell' unselectable='on'>" + (ix + lineStart) + "</span>");
 
79
        textLayer.$renderLine(stringBuilder, ix, true, false);
 
80
        stringBuilder.push("</div>");
 
81
    }
 
82
    var html = "<div class=':cssClass'>\
 
83
        <div class='ace_editor ace_scroller ace_text-layer'>\
 
84
            :code\
 
85
        </div>\
 
86
    </div>".replace(/:cssClass/, theme.cssClass).replace(/:code/, stringBuilder.join(""));
 
87
        
 
88
    textLayer.destroy();
 
89
            
 
90
    return {
 
91
        css: baseStyles + theme.cssText,
 
92
        html: html
 
93
    };
 
94
};
 
95
 
 
96
});