Skip to content

Removed jQuery dependency #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions angular.rangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@
// } else {
// angular.element('html').addClass('ngrs-no-touch');
// }
var filter = function(array, method) {
var filteredArray = [];
for (var i=0; i<array.length; i++) {
if (method(array[i])) {
filteredArray.push(array[i])
}
}
return filteredArray;
};

var findDivByClassName = function(element, className) {
return angular.element(filter(element.find('div'), function(el){
return angular.element(el).hasClass(className);
}));
};


return {
Expand All @@ -170,9 +185,10 @@
*/

var $slider = angular.element(element),
handles = [element.find('.ngrs-handle-min'), element.find('.ngrs-handle-max')],
values = [element.find('.ngrs-value-min'), element.find('.ngrs-value-max')],
join = element.find('.ngrs-join'),
$body = angular.element($document).find('body'),
handles = [findDivByClassName(element, 'ngrs-handle-min'), findDivByClassName(element, 'ngrs-handle-max')],
values = [findDivByClassName(element, 'ngrs-value-min'), findDivByClassName(element, 'ngrs-value-max')],
join = findDivByClassName(element, 'ngrs-join'),
pos = 'left',
posOpp = 'right',
orientation = 0,
Expand Down Expand Up @@ -279,7 +295,7 @@
// flag as true
scope.attachHandleValues = true;
// add class to runner
element.find('.ngrs-value-runner').addClass('ngrs-attached-handles');
findDivByClassName(element, 'ngrs-value-runner').addClass('ngrs-attached-handles');
} else {
scope.attachHandleValues = false;
}
Expand Down Expand Up @@ -504,7 +520,7 @@
}

// stop user accidentally selecting stuff
angular.element('body').bind('selectstart' + eventNamespace, function() {
$body.bind('selectstart' + eventNamespace, function() {
return false;
});

Expand All @@ -520,7 +536,7 @@
$slider.addClass('ngrs-focus ' + handleDownClass);

// add touch class for MS styling
angular.element('body').addClass('ngrs-touching');
$body.addClass('ngrs-touching');

// listen for mousemove / touchmove document events
$document.bind(moveEvent, function(e) {
Expand All @@ -546,9 +562,8 @@
movement = [
(previousClick[0] !== currentClick[0]), (previousClick[1] !== currentClick[1])
];

// propose a movement
proposal = originalPosition + ((currentClick[orientation] * 100) / (orientation ? $slider.height() : $slider.width()));
proposal = originalPosition + ((currentClick[orientation] * 100) / (orientation ? $slider[0].offsetHeight : $slider[0].offsetWidth));

// normalize so it can't move out of bounds
proposal = restrict(proposal);
Expand Down Expand Up @@ -617,7 +632,7 @@
$document.off(moveEvent);
$document.off(offEvent);

angular.element('body').removeClass('ngrs-touching');
$body.removeClass('ngrs-touching');

// cancel down flag
down = false;
Expand Down Expand Up @@ -660,7 +675,7 @@
$slider.off(eventNamespace);

// unbind from body
angular.element('body').off(eventNamespace);
$body.off(eventNamespace);

// unbind from document
$document.off(eventNamespace);
Expand Down
4 changes: 2 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ <h4>The HTML</h4>

</div>

<!-- we need jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<!-- we don't need jQuery anymore -->
<!-- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script> -->
<!-- and Angular, of course -->
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.js"></script>
<!-- and out directive code -->
Expand Down