parent
4fa785b175
commit
2c8dea244c
@ -1,4 +1,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
app/components
|
bower_components
|
||||||
components
|
|
||||||
.idea
|
.idea
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
angular.module('contenteditable', [])
|
|
||||||
.directive('contenteditable', ->
|
|
||||||
require: 'ngModel',
|
|
||||||
link: (scope, elmt, attrs, ngModel) ->
|
|
||||||
# view -> model
|
|
||||||
elmt.bind 'input', (e) ->
|
|
||||||
scope.$apply ->
|
|
||||||
html = elmt.html()
|
|
||||||
rerender = false
|
|
||||||
if attrs.stripBr && attrs.stripBr != "false"
|
|
||||||
html = html.replace /<br>$/, ''
|
|
||||||
if attrs.noLineBreaks && attrs.noLineBreaks != "false"
|
|
||||||
html2 = html.replace(/<div>/g, '').replace(/<br>/g, '').replace(/<\/div>/g, '')
|
|
||||||
if html2 != html
|
|
||||||
rerender = true
|
|
||||||
html = html2
|
|
||||||
ngModel.$setViewValue(html)
|
|
||||||
ngModel.$render() if rerender
|
|
||||||
if html == '' # the cursor if the contents is emty, so need to refocus
|
|
||||||
elmt.blur()
|
|
||||||
elmt.focus()
|
|
||||||
|
|
||||||
# model -> view
|
|
||||||
old_render = ngModel.$render # save for later
|
|
||||||
ngModel.$render = ->
|
|
||||||
old_render() if old_render?
|
|
||||||
elmt.html(ngModel.$viewValue || '')
|
|
||||||
# move cursor to the end
|
|
||||||
el = elmt.get(0)
|
|
||||||
range = document.createRange()
|
|
||||||
sel = window.getSelection()
|
|
||||||
if el.childNodes.length > 0
|
|
||||||
el2 = el.childNodes[el.childNodes.length - 1]
|
|
||||||
range.setStartAfter(el2)
|
|
||||||
else
|
|
||||||
range.setStartAfter(el)
|
|
||||||
range.collapse(true)
|
|
||||||
sel.removeAllRanges()
|
|
||||||
sel.addRange(range)
|
|
||||||
|
|
||||||
# select whole sub-span if it has contenteditable="false"
|
|
||||||
if attrs.selectNonEditable && attrs.selectNonEditable != "false"
|
|
||||||
elmt.click (e) ->
|
|
||||||
target = e.toElement
|
|
||||||
if target != @ && angular.element(target).attr('contenteditable') == 'false'
|
|
||||||
range = document.createRange()
|
|
||||||
sel = window.getSelection()
|
|
||||||
range.setStartBefore(target)
|
|
||||||
range.setEndAfter(target)
|
|
||||||
sel.removeAllRanges()
|
|
||||||
sel.addRange(range)
|
|
||||||
)
|
|
@ -1,52 +0,0 @@
|
|||||||
module.exports = (config) ->
|
|
||||||
toServe = for file in [
|
|
||||||
'components/bootstrap-css/css/bootstrap.css'
|
|
||||||
'components/jquery/jquery.js'
|
|
||||||
'components/angular-unstable/angular.js'
|
|
||||||
'components/angular-bootstrap/ui-bootstrap.js'
|
|
||||||
'components/angular-bootstrap/ui-bootstrap-tpls.js'
|
|
||||||
'angular-contenteditable.js'
|
|
||||||
'test/fixtures/simple.html'
|
|
||||||
'test/fixtures/typeahead1.html'
|
|
||||||
'test/fixtures/typeahead2.html'
|
|
||||||
'test/fixtures/typeahead3.html'
|
|
||||||
'test/fixtures/states.json'
|
|
||||||
'test/fixtures/img/ru.gif'
|
|
||||||
'test/fixtures/img/gb.gif'
|
|
||||||
'test/fixtures/img/us.gif'
|
|
||||||
]
|
|
||||||
pattern: file
|
|
||||||
watched: false
|
|
||||||
included: false
|
|
||||||
served: true
|
|
||||||
|
|
||||||
config.set
|
|
||||||
basePath: '..'
|
|
||||||
|
|
||||||
frameworks: ['ng-scenario']
|
|
||||||
|
|
||||||
preprocessors: '**/*.coffee': 'coffee'
|
|
||||||
|
|
||||||
files: [
|
|
||||||
'test/e2e/**/*.coffee'
|
|
||||||
].concat toServe
|
|
||||||
|
|
||||||
exclude: []
|
|
||||||
|
|
||||||
reporters: ['progress']
|
|
||||||
|
|
||||||
port: 9876
|
|
||||||
|
|
||||||
runnerPort: 9100
|
|
||||||
|
|
||||||
colors: true
|
|
||||||
|
|
||||||
logLevel: config.LOG_INFO
|
|
||||||
|
|
||||||
autoWatch: true
|
|
||||||
|
|
||||||
browsers: ['Chrome']
|
|
||||||
|
|
||||||
captureTimeout: 60000
|
|
||||||
|
|
||||||
singleRun: false
|
|
@ -0,0 +1,42 @@
|
|||||||
|
module.exports = (karma) ->
|
||||||
|
toServe = for file in [
|
||||||
|
'bower_components/**/*.css'
|
||||||
|
'bower_components/*/*.js'
|
||||||
|
'test/fixtures/**/*'
|
||||||
|
]
|
||||||
|
pattern: file
|
||||||
|
watched: false
|
||||||
|
included: false
|
||||||
|
served: true
|
||||||
|
|
||||||
|
karma.set
|
||||||
|
basePath: '..'
|
||||||
|
|
||||||
|
frameworks: ['ng-scenario']
|
||||||
|
|
||||||
|
preprocessors: '**/*.coffee': 'coffee'
|
||||||
|
|
||||||
|
files: [
|
||||||
|
'test/e2e/**/*.coffee'
|
||||||
|
'angular-contenteditable.js'
|
||||||
|
].concat toServe
|
||||||
|
|
||||||
|
exclude: []
|
||||||
|
|
||||||
|
reporters: ['progress']
|
||||||
|
|
||||||
|
port: 9876
|
||||||
|
|
||||||
|
runnerPort: 9100
|
||||||
|
|
||||||
|
colors: true
|
||||||
|
|
||||||
|
logLevel: karma.LOG_INFO
|
||||||
|
|
||||||
|
autoWatch: true
|
||||||
|
|
||||||
|
browsers: ['Chrome']
|
||||||
|
|
||||||
|
captureTimeout: 60000
|
||||||
|
|
||||||
|
singleRun: false
|
Reference in New Issue