material_raingular-ace 0.0.2.alpha → 0.0.3.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets/javascripts/code-editor.coffee +37 -10
- data/lib/material_raingular/ace/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 145c26761fe98f3ea59b6fc7081ad306eeb49692
|
4
|
+
data.tar.gz: df31cfc7bc874828d226147c9cf36b3388cd2760
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d2a7eb070b4598d6449c7417306055a05d442a68335e918946da21502801a692bb1e1c17e6348929d753c9faace79c7ccd0479dc95b5bc49d9a3e1c3a49ea1c
|
7
|
+
data.tar.gz: 87a98fd2e4a92fe29ea889363f13c17e73f783a94160d37d8f3ff5dbbb710980bf281040d09a598654aa5dba1404ab83b1df8d19c7c0703b69d53640387c0e4e
|
@@ -1,6 +1,32 @@
|
|
1
1
|
# //= require ace/theme-monokai
|
2
2
|
# //= require ace/mode-ruby
|
3
3
|
# In order to have digested assets function properly, theme and mode must be required up front
|
4
|
+
class EditorHeight
|
5
|
+
constructor: (scope,element,attributes)->
|
6
|
+
@scope = scope
|
7
|
+
@element = element
|
8
|
+
@attributes = attributes
|
9
|
+
|
10
|
+
minHeight: ->
|
11
|
+
heights = []
|
12
|
+
e = @element[0].parentElement.parentElement
|
13
|
+
while e
|
14
|
+
heights.push(e.offsetHeight) unless e.offsetHeight == 0
|
15
|
+
e = e.parentElement
|
16
|
+
|
17
|
+
height: ->
|
18
|
+
return @minHeight() + 'px' unless @attributes.editorSize
|
19
|
+
raw_equation = @attributes.editorSize.replace /[\+\-\/\*]/g, (operator)->
|
20
|
+
return " " + operator + " "
|
21
|
+
equation = []
|
22
|
+
for el in raw_equation.split(/\s+/)
|
23
|
+
unless el.match(/(^[\d+]?[.]?[\d+]$)|[\+\-\/\*]/)
|
24
|
+
method = 'getElement' + if el[0] == "#" then 'ById' else 'sByClass'
|
25
|
+
equation.push document[method](el[1..-1]).offsetHeight
|
26
|
+
else
|
27
|
+
equation.push(el)
|
28
|
+
return @scope.$eval(equation.join(' ')) + 'px'
|
29
|
+
|
4
30
|
angular.module('materialRaingularAce', [])
|
5
31
|
.directive 'codeEditor', ($timeout, factoryName, $injector)->
|
6
32
|
restrict: 'E'
|
@@ -9,23 +35,24 @@ angular.module('materialRaingularAce', [])
|
|
9
35
|
template: (element,attributes) ->
|
10
36
|
websocketHelper = ->
|
11
37
|
if typeof attributes.webSocket == 'undefined' then 'update' else 'model'
|
12
|
-
|
38
|
+
id = attributes['editorId'] || attributes.ngModel.replace('.','-') + "-code-editor"
|
39
|
+
'<span><div id="' + id + '"></div><input type="hidden" ng-' + websocketHelper + '="' + attributes.ngModel + '"</span>'
|
13
40
|
link: (scope, element, attributes, modelCtrl)->
|
14
|
-
|
41
|
+
id = attributes['editorId'] || attributes.ngModel.replace('.','-') + "-code-editor"
|
42
|
+
angular.ace = {} unless angular.ace
|
43
|
+
editor = ace.edit(id)
|
15
44
|
editor.setTheme("ace/theme/monokai")
|
16
45
|
editor.getSession().setMode("ace/mode/ruby")
|
17
46
|
editor.getSession().setTabSize(2)
|
18
47
|
editor.getSession().setUseSoftTabs(true)
|
19
48
|
editor.$blockScrolling = Infinity
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
while e
|
24
|
-
heights.push(e.offsetHeight) unless e.offsetHeight == 0
|
25
|
-
e = e.parentElement
|
49
|
+
angular.ace[id] = editor
|
50
|
+
span = angular.element(document.getElementById(id))
|
51
|
+
editorHeight = new EditorHeight(scope,element,attributes)
|
26
52
|
angular.element(window).on 'resize', (event)->
|
27
|
-
span.css('height',
|
28
|
-
|
53
|
+
span.css('height',editorHeight.height())
|
54
|
+
editor.resize()
|
55
|
+
span.css('fontSize', '14px').css('height',editorHeight.height())
|
29
56
|
scope.$watch attributes.ngModel, (newVal, oldVal) ->
|
30
57
|
unless newVal == editor.getValue()
|
31
58
|
if newVal && oldVal
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: material_raingular-ace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Moody
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|