typeahead specific filters shouldn't be here

fix-space-nbsp
Dmitri Akatov 11 years ago
parent 45a9b82f3f
commit 69fe66c663

@ -1,14 +1,4 @@
(function() {
var escapeRegexp, noImg;
escapeRegexp = function(str) {
return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
};
noImg = function(str) {
return str.replace(/<img[^>]*>/g, '');
};
angular.module('contenteditable', []).directive('contenteditable', function() {
return {
require: 'ngModel',
@ -41,22 +31,6 @@
};
}
};
}).filter('typeaheadHighlight', function() {
return function(matchItem, query) {
return matchItem;
};
}).filter('ignoreImg', function() {
return function(items, query) {
var item, _i, _len, _results;
_results = [];
for (_i = 0, _len = items.length; _i < _len; _i++) {
item = items[_i];
if (noImg(item).match(new RegExp(escapeRegexp(noImg(query)), 'gi'))) {
_results.push(item);
}
}
return _results;
};
});
}).call(this);

@ -1,11 +1,3 @@
# utility functions to escape a query
# @param str the string to escape
escapeRegexp = (str) -> str.replace /([.?*+^$[\]\\(){}|-])/g, "\\$1"
# removes all img tags
# @param str a string possibly containing img tags
noImg = (str) -> str.replace /<img[^>]*>/g, ''
angular.module('contenteditable', [])
.directive('contenteditable', ->
require: 'ngModel',
@ -34,13 +26,3 @@ angular.module('contenteditable', [])
sel.removeAllRanges()
sel.addRange(range)
)
.filter('typeaheadHighlight', ->
# don't highlight anything!
(matchItem, query) -> matchItem
)
.filter('ignoreImg', ->
# when matching query against the items, ignore all img tags
(items, query) ->
item for item in items \
when noImg(item).match(new RegExp(escapeRegexp(noImg(query)), 'gi'))
)

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" ng-app="typeahead">
<html lang="en" ng-app="typeahead1">
<head>
<meta charset="utf-8">
<link href="../../components/bootstrap-css/css/bootstrap.css" rel="stylesheet">
@ -9,19 +9,18 @@
<script src="../../components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="../../lib/angular-contenteditable.js"></script>
<script>
angular.module('typeahead', ['ui.bootstrap', 'contenteditable'])
.controller('TypeaheadCtrl', function ($scope) {
angular.module('typeahead1', ['ui.bootstrap', 'contenteditable'])
.controller('Typeahead1Ctrl', 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">
<div class='container-fluid' ng-controller="Typeahead1Ctrl">
<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>

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" ng-app="typeahead">
<html lang="en" ng-app="typeahead2">
<head>
<meta charset="utf-8">
<link href="../../components/bootstrap-css/css/bootstrap.css" rel="stylesheet">
@ -9,8 +9,8 @@
<script src="../../components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="../../lib/angular-contenteditable.js"></script>
<script>
angular.module('typeahead', ['ui.bootstrap', 'contenteditable'])
.controller('TypeaheadCtrl', function ($scope) {
angular.module('typeahead2', ['ui.bootstrap', 'contenteditable'])
.controller('Typeahead2Ctrl', function ($scope) {
$scope.selected = undefined
$scope.states =
[ 'Russia <img src="img/ru.gif">'
@ -18,10 +18,30 @@ angular.module('typeahead', ['ui.bootstrap', 'contenteditable'])
, 'UK <img src="img/gb.gif">'
]
})
</script>
.filter('ignoreImg', function(){
var escapeRegexp = function(str) {
return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1")
}
var noImg = function (str) {
return str.replace(/<img[^>]*>/g, '')
}
return function(items, query) {
var ret = []
items.forEach(function(item){
if (noImg(item).match(new RegExp(escapeRegexp(noImg(query)), 'gi')))
ret.push(item)
})
return ret
}
})
// override typeahead's Highlight filter - don't highlight anything
.filter('typeaheadHighlight', function() {
return function(matchItem, query){return matchItem}
})
</script>
</head>
<body>
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<div class='container-fluid' ng-controller="Typeahead2Ctrl">
<pre>Model: {{ selected | json }}</pre>
<div ng-model="selected" typeahead="state for state in states | ignoreImg:$viewValue" contenteditable>
</div>

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" ng-app="typeahead">
<html lang="en" ng-app="typeahead3">
<head>
<meta charset="utf-8">
<link href="../../components/bootstrap-css/css/bootstrap.css" rel="stylesheet">
@ -9,8 +9,8 @@
<script src="../../components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="../../lib/angular-contenteditable.js"></script>
<script>
angular.module('typeahead', ['ui.bootstrap', 'contenteditable'])
.controller('TypeaheadCtrl', function($scope, $http, limitToFilter, ignoreImgFilter) {
angular.module('typeahead3', ['ui.bootstrap', 'contenteditable'])
.controller('Typeahead3Ctrl', function($scope, $http, limitToFilter, ignoreImgFilter) {
$scope.selected = ""
$scope.states = function(query){
return $http.get("states.json").then(function(response){
@ -18,11 +18,31 @@ angular.module('typeahead', ['ui.bootstrap', 'contenteditable'])
return limitToFilter(ignoreImgFilter(response.data, query), 2)
})
}
})
.filter('ignoreImg', function(){
var escapeRegexp = function(str) {
return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1")
}
var noImg = function (str) {
return str.replace(/<img[^>]*>/g, '')
}
return function(items, query) {
var ret = []
items.forEach(function(item){
if (noImg(item).match(new RegExp(escapeRegexp(noImg(query)), 'gi')))
ret.push(item)
})
return ret
}
})
// override typeahead's Highlight filter - don't highlight anything
.filter('typeaheadHighlight', function() {
return function(matchItem, query){return matchItem}
})
</script>
</head>
<body>
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<div class='container-fluid' ng-controller="Typeahead3Ctrl">
<pre>Model: {{ selected | json }}</pre>
<div ng-model="selected" typeahead="state for state in states($viewValue)" contenteditable="true" style="width:400px; height: 20px;"></div>
</div>