removed '=' file
110
=
|
@ -1,110 +0,0 @@
|
|||
angular.module('angular-input-stars', [])
|
||||
|
||||
.directive('inputStars', ['$rootScope', function ($rootScope) {
|
||||
|
||||
var directive = {
|
||||
|
||||
restrict: 'EA',
|
||||
replace: true,
|
||||
template: '<ul ng-class="listClass">' +
|
||||
'<li ng-touch="paintStars($index)" ng-mouseenter="paintStars($index, true)" ng-mouseleave="unpaintStars($index, false)" ng-repeat="item in items track by $index">' +
|
||||
'<i ng-class="getClass($index)" ng-click="setValue($index, $event)"></i>' +
|
||||
'</li>' +
|
||||
'</ul>',
|
||||
require: 'ngModel',
|
||||
scope: true,
|
||||
|
||||
link: link
|
||||
|
||||
};
|
||||
|
||||
return directive;
|
||||
|
||||
function link(scope, element, attrs, ngModelCtrl) {
|
||||
|
||||
scope.items = new Array(+attrs.max);
|
||||
|
||||
var emptyIcon = attrs.iconEmpty || 'fa-star-o';
|
||||
var iconHover = attrs.iconHover || 'angular-input-stars-hover';
|
||||
var fullIcon = attrs.iconFull || 'fa-star';
|
||||
var iconBase = attrs.iconBase || 'fa fa-fw';
|
||||
scope.listClass = attrs.listClass || 'angular-input-stars';
|
||||
scope.readonly = ! (attrs.readonly === undefined);
|
||||
|
||||
ngModelCtrl.$render = function () {
|
||||
|
||||
scope.last_value = ngModelCtrl.$viewValue || 0;
|
||||
|
||||
};
|
||||
|
||||
scope.getClass = function (index) {
|
||||
|
||||
return index >= scope.last_value ? iconBase + ' ' + emptyIcon : iconBase + ' ' + fullIcon + ' active ';
|
||||
|
||||
};
|
||||
|
||||
scope.unpaintStars = function ($index, hover) {
|
||||
|
||||
scope.paintStars(scope.last_value - 1, hover);
|
||||
|
||||
};
|
||||
|
||||
scope.paintStars = function ($index, hover) {
|
||||
|
||||
//ignore painting, if readonly
|
||||
if (scope.readonly) {
|
||||
return;
|
||||
}
|
||||
var items = element.find('li').find('i');
|
||||
|
||||
for (var index = 0; index < items.length; index++) {
|
||||
|
||||
var $star = angular.element(items[index]);
|
||||
|
||||
if ($index >= index) {
|
||||
|
||||
$star.removeClass(emptyIcon);
|
||||
$star.addClass(fullIcon);
|
||||
$star.addClass('active');
|
||||
$star.addClass(iconHover);
|
||||
|
||||
} else {
|
||||
|
||||
$star.removeClass(fullIcon);
|
||||
$star.removeClass('active');
|
||||
$star.removeClass(iconHover);
|
||||
$star.addClass(emptyIcon);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
!hover && items.removeClass(iconHover);
|
||||
|
||||
};
|
||||
|
||||
scope.setValue = function (index, e) {
|
||||
|
||||
//ignore painting
|
||||
if (scope.readonly) {
|
||||
return;
|
||||
}
|
||||
var star = e.target;
|
||||
|
||||
if (e.pageX < star.getBoundingClientRect().left + star.offsetWidth / 2) {
|
||||
scope.last_value = index + 1;
|
||||
} else {
|
||||
scope.last_value = index + 1;
|
||||
}
|
||||
|
||||
ngModelCtrl.$setViewValue(scope.last_value);
|
||||
|
||||
//Execute custom trigger function if there is one
|
||||
if(attrs.onStarClick){
|
||||
$rootScope.$eval(attrs.onStarClick);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}]);
|
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 243 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 320 KiB |
After Width: | Height: | Size: 287 KiB |
After Width: | Height: | Size: 283 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 377 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 393 KiB |
After Width: | Height: | Size: 415 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 372 KiB |
After Width: | Height: | Size: 414 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 380 KiB |
After Width: | Height: | Size: 464 KiB |