make this work with typeahead

fix-space-nbsp
Dmitri Akatov 11 years ago
parent 2f5e5d415c
commit 23a0204494

@ -6,6 +6,7 @@
, "devDependencies": , "devDependencies":
{ "angular-mocks": "~1.0.5" { "angular-mocks": "~1.0.5"
, "angular-scenario": "~1.0.5" , "angular-scenario": "~1.0.5"
, "angular-bootstrap": "~0.3.0"
, "expect": "~0.2.0" , "expect": "~0.2.0"
} }
} }

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en" ng-app="typeahead">
<head>
<meta charset="utf-8">
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="../components/angular/angular.js"></script>
<script src="../components/angular-bootstrap/ui-bootstrap.js"></script>
<script src="../components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="../dist/radians.js"></script>
<script>
angular.module('typeahead', ['ui.bootstrap', 'radians'])
.controller('TypeaheadCtrl', function ($scope) {
$scope.selected = undefined
$scope.states = ['<b>sweet home</b> Alabama', '<i>cold</i> Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']
})
</script>
</head>
<body>
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<pre>Model: {{selected| json}}</pre>
<div ng-model="selected" typeahead="state for state in states | filter:$viewValue" contenteditable>
</div>
<!-- <input type="text" ng-model="selected" typeahead="state for state in states | filter:$viewValue"> -->
</div>
</body>
</html>

@ -2,17 +2,22 @@ angular.module('radians.contenteditable', [])
.directive('contenteditable', -> .directive('contenteditable', ->
require: 'ngModel', require: 'ngModel',
link: (scope, elmt, attrs, ctrl) -> link: (scope, elmt, attrs, ctrl) ->
# view -> model old_render = ctrl.$render # save for later
view_to_model = -> view_to_model = ->
scope.$apply -> scope.$apply ->
ctrl.$setViewValue elmt.html() ctrl.$setViewValue elmt.html()
null
# view -> model
elmt.bind 'blur', view_to_model elmt.bind 'blur', view_to_model
elmt.bind 'input', view_to_model elmt.bind 'input', view_to_model
elmt.bind 'change', view_to_model elmt.bind 'change', view_to_model
# model -> view # model -> view
ctrl.$render = -> elmt.html ctrl.$viewValue ctrl.$render = ->
old_render() if old_render != null # old_render? leads to linted js
elmt.html ctrl.$viewValue
null
null null
) )