Upgrade to 3.1 step 2 - js
This commit is contained in:
@@ -0,0 +1,400 @@
|
||||
/**
|
||||
* Ajax Autocomplete for jQuery, version 1.1.3
|
||||
* (c) 2010 Tomas Kirda
|
||||
*
|
||||
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
|
||||
* For details, see the web site: http://www.devbridge.com/projects/autocomplete/jquery/
|
||||
*
|
||||
* Last Review: 04/19/2010
|
||||
*/
|
||||
|
||||
/*jslint onevar: true, evil: true, nomen: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
|
||||
/*global window: true, document: true, clearInterval: true, setInterval: true, jQuery: true */
|
||||
|
||||
(function($) {
|
||||
|
||||
var reEscape = new RegExp('(\\' + ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'].join('|\\') + ')', 'g');
|
||||
|
||||
function fnFormatResult(value, data, currentValue) {
|
||||
if (currentValue === 'and' || currentValue === '&' || currentValue === 'n\'') {
|
||||
var pattern = '(and|\&|n\')';
|
||||
} else {
|
||||
var pattern = '(' + currentValue.replace(reEscape, '\\$1') + ')';
|
||||
}
|
||||
return value.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');
|
||||
}
|
||||
|
||||
function Autocomplete(el, options) {
|
||||
this.el = $(el);
|
||||
this.el.attr('autocomplete', 'off');
|
||||
this.suggestions = [];
|
||||
this.data = [];
|
||||
this.badQueries = [];
|
||||
this.selectedIndex = -1;
|
||||
this.currentValue = this.el.val();
|
||||
this.intervalId = 0;
|
||||
this.cachedResponse = [];
|
||||
this.onChangeInterval = null;
|
||||
this.ignoreValueChange = false;
|
||||
this.serviceUrl = options.serviceUrl;
|
||||
this.isLocal = false;
|
||||
this.options = {
|
||||
autoSubmit: false,
|
||||
minChars: 1,
|
||||
maxHeight: 300,
|
||||
deferRequestBy: 0,
|
||||
width: 0,
|
||||
highlight: true,
|
||||
params: {},
|
||||
fnFormatResult: fnFormatResult,
|
||||
delimiter: null,
|
||||
zIndex: 9999
|
||||
};
|
||||
this.initialize();
|
||||
this.setOptions(options);
|
||||
}
|
||||
|
||||
$.fn.bh_autocomplete = function(options) {
|
||||
return new Autocomplete(this.get(0)||$('<input />'), options);
|
||||
};
|
||||
|
||||
|
||||
Autocomplete.prototype = {
|
||||
|
||||
killerFn: null,
|
||||
|
||||
initialize: function() {
|
||||
|
||||
var me, uid, autocompleteElId;
|
||||
me = this;
|
||||
uid = Math.floor(Math.random()*0x100000).toString(16);
|
||||
autocompleteElId = 'Autocomplete_' + uid;
|
||||
|
||||
this.killerFn = function(e) {
|
||||
if ($(e.target).parents('.autocomplete').size() === 0) {
|
||||
me.killSuggestions();
|
||||
me.disableKillerFn();
|
||||
}
|
||||
};
|
||||
|
||||
if (!this.options.width) { this.options.width = this.el.width(); }
|
||||
this.mainContainerId = 'AutocompleteContainter_' + uid;
|
||||
|
||||
$('<div class="autocomplete-container" id="' + this.mainContainerId + '" style="position:absolute;z-index:9999;"><div class="autocomplete-w1"><div class="autocomplete" id="' + autocompleteElId + '" style="display:none; width:300px;"></div></div></div>').appendTo('body');
|
||||
|
||||
this.container = $('#' + autocompleteElId);
|
||||
this.fixPosition();
|
||||
if (window.opera) {
|
||||
this.el.keypress(function(e) { me.onKeyPress(e); });
|
||||
} else {
|
||||
this.el.keydown(function(e) { me.onKeyPress(e); });
|
||||
}
|
||||
this.el.keyup(function(e) { me.onKeyUp(e); });
|
||||
this.el.blur(function() { me.enableKillerFn(); });
|
||||
this.el.focus(function() { me.fixPosition(); });
|
||||
},
|
||||
|
||||
setOptions: function(options){
|
||||
var o = this.options;
|
||||
$.extend(o, options);
|
||||
if(o.lookup){
|
||||
this.isLocal = true;
|
||||
if($.isArray(o.lookup)){ o.lookup = { suggestions:o.lookup, data:[] }; }
|
||||
}
|
||||
$('#'+this.mainContainerId).css({ zIndex:o.zIndex });
|
||||
this.container.css({ maxHeight: o.maxHeight + 'px', width:o.width });
|
||||
},
|
||||
|
||||
clearCache: function(){
|
||||
this.cachedResponse = [];
|
||||
this.badQueries = [];
|
||||
},
|
||||
|
||||
disable: function(){
|
||||
this.disabled = true;
|
||||
},
|
||||
|
||||
enable: function(){
|
||||
this.disabled = false;
|
||||
},
|
||||
|
||||
fixPosition: function() {
|
||||
var offset = this.el.offset();
|
||||
$('#' + this.mainContainerId).css({ top: (offset.top + this.el.innerHeight()) + 'px', left: offset.left + 'px' });
|
||||
},
|
||||
|
||||
enableKillerFn: function() {
|
||||
var me = this;
|
||||
$(document).bind('click', me.killerFn);
|
||||
},
|
||||
|
||||
disableKillerFn: function() {
|
||||
var me = this;
|
||||
$(document).unbind('click', me.killerFn);
|
||||
},
|
||||
|
||||
killSuggestions: function() {
|
||||
var me = this;
|
||||
this.stopKillSuggestions();
|
||||
this.intervalId = window.setInterval(function() { me.hide(); me.stopKillSuggestions(); }, 300);
|
||||
},
|
||||
|
||||
stopKillSuggestions: function() {
|
||||
window.clearInterval(this.intervalId);
|
||||
},
|
||||
|
||||
onKeyPress: function(e) {
|
||||
if (this.disabled || !this.enabled) { return; }
|
||||
// return will exit the function
|
||||
// and event will not be prevented
|
||||
switch (e.keyCode) {
|
||||
case 27: //KEY_ESC:
|
||||
this.el.val(this.currentValue);
|
||||
this.hide();
|
||||
break;
|
||||
case 9: //KEY_TAB:
|
||||
case 13: //KEY_RETURN:
|
||||
if (this.selectedIndex === -1) {
|
||||
this.hide();
|
||||
return;
|
||||
}
|
||||
this.select(this.selectedIndex);
|
||||
if(e.keyCode === 9){ return; }
|
||||
break;
|
||||
case 38: //KEY_UP:
|
||||
this.moveUp();
|
||||
break;
|
||||
case 40: //KEY_DOWN:
|
||||
this.moveDown();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
e.stopImmediatePropagation();
|
||||
e.preventDefault();
|
||||
},
|
||||
|
||||
onKeyUp: function(e) {
|
||||
if(this.disabled){ return; }
|
||||
switch (e.keyCode) {
|
||||
case 38: //KEY_UP:
|
||||
case 40: //KEY_DOWN:
|
||||
return;
|
||||
}
|
||||
clearInterval(this.onChangeInterval);
|
||||
if (this.currentValue !== this.el.val()) {
|
||||
if (this.options.deferRequestBy > 0) {
|
||||
// Defer lookup in case when value changes very quickly:
|
||||
var me = this;
|
||||
this.onChangeInterval = setInterval(function() { me.onValueChange(); }, this.options.deferRequestBy);
|
||||
} else {
|
||||
this.onValueChange();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onValueChange: function() {
|
||||
clearInterval(this.onChangeInterval);
|
||||
this.currentValue = this.el.val();
|
||||
var q = this.getQuery(this.currentValue);
|
||||
this.selectedIndex = -1;
|
||||
if (this.ignoreValueChange) {
|
||||
this.ignoreValueChange = false;
|
||||
return;
|
||||
}
|
||||
if (q === '' || q.length < this.options.minChars) {
|
||||
this.hide();
|
||||
} else {
|
||||
this.getSuggestions(q);
|
||||
}
|
||||
},
|
||||
|
||||
getQuery: function(val) {
|
||||
var d, arr;
|
||||
d = this.options.delimiter;
|
||||
if (!d) { return $.trim(val); }
|
||||
arr = val.split(d);
|
||||
return $.trim(arr[arr.length - 1]);
|
||||
},
|
||||
|
||||
getSuggestionsLocal: function(q) {
|
||||
var ret, arr, len, val, i;
|
||||
arr = this.options.lookup;
|
||||
len = arr.suggestions.length;
|
||||
ret = { suggestions:[], data:[] };
|
||||
q = q.toLowerCase();
|
||||
for(i=0; i< len; i++){
|
||||
val = arr.suggestions[i];
|
||||
if(val.toLowerCase().indexOf(q) === 0){
|
||||
ret.suggestions.push(val);
|
||||
ret.data.push(arr.data[i]);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
},
|
||||
|
||||
getSuggestions: function(q) {
|
||||
var cr, me;
|
||||
cr = this.isLocal ? this.getSuggestionsLocal(q) : this.cachedResponse[q];
|
||||
if (cr && $.isArray(cr.suggestions)) {
|
||||
this.suggestions = cr.suggestions;
|
||||
this.data = cr.data;
|
||||
this.suggest();
|
||||
} else if (!this.isBadQuery(q)) {
|
||||
me = this;
|
||||
me.options.params.query = q;
|
||||
$.get(this.serviceUrl, me.options.params, function(txt) { me.processResponse(txt); }, 'text');
|
||||
}
|
||||
},
|
||||
|
||||
isBadQuery: function(q) {
|
||||
var i = this.badQueries.length;
|
||||
while (i--) {
|
||||
if (q.indexOf(this.badQueries[i]) === 0) { return true; }
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.enabled = false;
|
||||
this.selectedIndex = -1;
|
||||
this.container.hide();
|
||||
},
|
||||
|
||||
suggest: function() {
|
||||
if (this.suggestions.length === 0) {
|
||||
this.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
var me, len, div, f, v, i, s, mOver, mClick;
|
||||
me = this;
|
||||
len = this.suggestions.length;
|
||||
f = this.options.fnFormatResult;
|
||||
v = this.getQuery(this.currentValue);
|
||||
mOver = function(xi) { return function() { me.activate(xi); }; };
|
||||
mClick = function(xi) { return function() { me.select(xi); }; };
|
||||
this.container.hide().empty();
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
s = this.suggestions[i];
|
||||
div = $((me.selectedIndex === i ? '<div class="selected"' : '<div') + ' title="' + s + '">' + f(s, this.data[i], v) + '</div>');
|
||||
div.mouseover(mOver(i));
|
||||
div.click(mClick(i));
|
||||
this.container.append(div);
|
||||
}
|
||||
this.enabled = true;
|
||||
that = this;
|
||||
$('.pulldown').animate({height: 250}, 'fast', function(){
|
||||
that.container.show();
|
||||
_beathaven.adjustSizes()
|
||||
_beathaven.redrawScrollbar()
|
||||
});
|
||||
},
|
||||
|
||||
processResponse: function(text) {
|
||||
var response;
|
||||
try {
|
||||
response = eval('(' + text + ')');
|
||||
} catch (err) { return; }
|
||||
if (!$.isArray(response.data)) { response.data = []; }
|
||||
if(!this.options.noCache){
|
||||
this.cachedResponse[response.query] = response;
|
||||
if (response.suggestions.length === 0) { this.badQueries.push(response.query); }
|
||||
}
|
||||
if (response.query === this.getQuery(this.currentValue)) {
|
||||
this.suggestions = response.suggestions;
|
||||
this.data = response.data;
|
||||
this.suggest();
|
||||
}
|
||||
},
|
||||
|
||||
activate: function(index) {
|
||||
var divs, activeItem;
|
||||
divs = this.container.children();
|
||||
// Clear previous selection:
|
||||
if (this.selectedIndex !== -1 && divs.length > this.selectedIndex) {
|
||||
$(divs.get(this.selectedIndex)).removeClass();
|
||||
}
|
||||
this.selectedIndex = index;
|
||||
if (this.selectedIndex !== -1 && divs.length > this.selectedIndex) {
|
||||
activeItem = divs.get(this.selectedIndex);
|
||||
$(activeItem).addClass('selected');
|
||||
}
|
||||
return activeItem;
|
||||
},
|
||||
|
||||
deactivate: function(div, index) {
|
||||
div.className = '';
|
||||
if (this.selectedIndex === index) { this.selectedIndex = -1; }
|
||||
},
|
||||
|
||||
select: function(i) {
|
||||
var selectedValue, f;
|
||||
selectedValue = this.suggestions[i];
|
||||
if (selectedValue) {
|
||||
this.el.val(selectedValue);
|
||||
if (this.options.autoSubmit) {
|
||||
f = this.el.parents('form');
|
||||
if (f.length > 0) { f.get(0).submit(); }
|
||||
}
|
||||
this.ignoreValueChange = true;
|
||||
this.hide();
|
||||
this.onSelect(i);
|
||||
}
|
||||
},
|
||||
|
||||
moveUp: function() {
|
||||
if (this.selectedIndex === -1) { return; }
|
||||
if (this.selectedIndex === 0) {
|
||||
this.container.children().get(0).className = '';
|
||||
this.selectedIndex = -1;
|
||||
this.el.val(this.currentValue);
|
||||
return;
|
||||
}
|
||||
this.adjustScroll(this.selectedIndex - 1);
|
||||
},
|
||||
|
||||
moveDown: function() {
|
||||
if (this.selectedIndex === (this.suggestions.length - 1)) { return; }
|
||||
this.adjustScroll(this.selectedIndex + 1);
|
||||
},
|
||||
|
||||
adjustScroll: function(i) {
|
||||
var activeItem, offsetTop, upperBound, lowerBound;
|
||||
activeItem = this.activate(i);
|
||||
offsetTop = activeItem.offsetTop;
|
||||
upperBound = this.container.scrollTop();
|
||||
lowerBound = upperBound + this.options.maxHeight - 25;
|
||||
if (offsetTop < upperBound) {
|
||||
this.container.scrollTop(offsetTop);
|
||||
} else if (offsetTop > lowerBound) {
|
||||
this.container.scrollTop(offsetTop - this.options.maxHeight + 25);
|
||||
}
|
||||
this.el.val(this.getValue(this.suggestions[i]));
|
||||
},
|
||||
|
||||
onSelect: function(i) {
|
||||
var me, fn, s, d;
|
||||
me = this;
|
||||
fn = me.options.onSelect;
|
||||
s = me.suggestions[i];
|
||||
d = me.data[i];
|
||||
me.el.val(me.getValue(s));
|
||||
if ($.isFunction(fn)) { fn(s, d, me.el); }
|
||||
},
|
||||
|
||||
getValue: function(value){
|
||||
var del, currVal, arr, me;
|
||||
me = this;
|
||||
del = me.options.delimiter;
|
||||
if (!del) { return value; }
|
||||
currVal = me.currentValue;
|
||||
arr = currVal.split(del);
|
||||
if (arr.length === 1) { return value; }
|
||||
return currVal.substr(0, currVal.length - arr[arr.length - 1].length) + value;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}(jQuery));
|
||||
+2028
File diff suppressed because it is too large
Load Diff
+660
@@ -0,0 +1,660 @@
|
||||
/*jslint eqeqeq: true, regexp: true */
|
||||
/*global document, window, setInterval, clearInterval, handler, jQuery */
|
||||
|
||||
/*
|
||||
* Scrollbar - a jQuery plugin for custom scrollbars
|
||||
*
|
||||
* @author Thomas Duerr, me@thomd.net
|
||||
* @date 03.2010
|
||||
* @requires jquery v1.4.2
|
||||
* @version 0.3
|
||||
*
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* Append scrollbar to an arbitrary container with overflowed content:
|
||||
*
|
||||
* $('selector').scrollbar();
|
||||
*
|
||||
*
|
||||
* Append scrollbar without arrows on top/bottom:
|
||||
*
|
||||
* $('selector').scrollbar({
|
||||
* arrows: false
|
||||
* });
|
||||
*
|
||||
*
|
||||
*
|
||||
* A vertical scrollbar is based on the following box model:
|
||||
*
|
||||
* +----------------------------------+
|
||||
* | <----------------------------- content container
|
||||
* | +-----------------+ +------+ |
|
||||
* | | | | <-------------- handle arrow up
|
||||
* | | | | | |
|
||||
* | | | +------+ |
|
||||
* | | | | +--+ | |
|
||||
* | | | | | | | |
|
||||
* | | | | | <-------------- handle
|
||||
* | | | | | | | |
|
||||
* | | | | | | | |
|
||||
* | | | | | | | |
|
||||
* | | | | +--+ | |
|
||||
* | | | | | |
|
||||
* | | | | <-------------- handle container
|
||||
* | | | | | |
|
||||
* | | <----------------------------- pane
|
||||
* | | | | | |
|
||||
* | | | | | |
|
||||
* | | | +------+ |
|
||||
* | | | | | |
|
||||
* | | | | <-------------- handle arrow down
|
||||
* | +-----------------+ +------+ |
|
||||
* | |
|
||||
* +----------------------------------+
|
||||
*
|
||||
*
|
||||
*/
|
||||
(function($, document){
|
||||
|
||||
$.fn.scrollbar = function(opts){
|
||||
|
||||
// Extend default options
|
||||
var options = $.extend({}, $.fn.scrollbar.defaults, opts);
|
||||
|
||||
|
||||
//
|
||||
// append scrollbar to selected overflowed containers and return jquery object for chainability
|
||||
//
|
||||
return this.each(function(){
|
||||
|
||||
var container = $(this)
|
||||
|
||||
// properties
|
||||
, props = {
|
||||
arrows: options.arrows
|
||||
};
|
||||
|
||||
// set container height explicitly if given by an option
|
||||
if(options.containerHeight != 'auto'){
|
||||
container.height(options.containerHeight);
|
||||
}
|
||||
|
||||
// save container height in properties
|
||||
props.containerHeight = container.height();
|
||||
|
||||
// save content height in properties
|
||||
props.contentHeight = $.fn.scrollbar.contentHeight(container);
|
||||
|
||||
// if the content height is lower than the container height, do nothing and return.
|
||||
if(props.contentHeight <= props.containerHeight){
|
||||
return true;
|
||||
}
|
||||
|
||||
// create a new scrollbar object
|
||||
var scrollbar = new $.fn.scrollbar.Scrollbar(container, props, options);
|
||||
|
||||
// build HTML, initialize Handle and append Events
|
||||
scrollbar.buildHtml().initHandle().appendEvents();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
// # default options
|
||||
//
|
||||
//
|
||||
$.fn.scrollbar.defaults = {
|
||||
|
||||
// ### containerHeight `Number` or `'auto'`
|
||||
//
|
||||
// height of content container. If set to `'auto'`, the naturally rendered height is used
|
||||
containerHeight: 'auto',
|
||||
|
||||
arrows: true, // render up- and down-arrows
|
||||
handleHeight: 'auto', // height of handle [px || 'auto']. If set to 'auto', the height will be calculated proportionally to the container-content height.
|
||||
handleMinHeight: 30, // min-height of handle [px]. This property will only be used if handleHeight is set to 'auto'
|
||||
|
||||
scrollSpeed: 50, // speed of handle while mousedown on arrows [milli sec]
|
||||
scrollStep: 20, // handle increment between two mousedowns on arrows [px]
|
||||
|
||||
scrollSpeedArrows: 40, // speed of handle while mousedown within the handle container [milli sec]
|
||||
scrollStepArrows: 3 // handle increment between two mousedowns within the handle container [px]
|
||||
};
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Scrollbar constructor
|
||||
//
|
||||
$.fn.scrollbar.Scrollbar = function(container, props, options){
|
||||
|
||||
// set object properties
|
||||
this.container = container;
|
||||
this.props = props;
|
||||
this.opts = options;
|
||||
this.mouse = {};
|
||||
|
||||
// disable arrows via class attribute 'no-arrows' on a container
|
||||
this.props.arrows = this.container.hasClass('no-arrows') ? false : this.props.arrows;
|
||||
};
|
||||
|
||||
//
|
||||
// Scrollbar methods
|
||||
//
|
||||
$.fn.scrollbar.Scrollbar.prototype = {
|
||||
|
||||
//
|
||||
// build DOM nodes for pane and scroll-handle
|
||||
//
|
||||
// from:
|
||||
//
|
||||
// <div class="foo"> --> arbitrary element with a fixed height or a max-height lower that its containing elements
|
||||
// [...]
|
||||
// </div>
|
||||
//
|
||||
// to:
|
||||
//
|
||||
// <div class="foo"> --> this.container
|
||||
// <div class="scrollbar-pane"> --> this.pane
|
||||
// [...]
|
||||
// </div>
|
||||
// <div class="scrollbar-handle-container"> --> this.handleContainer
|
||||
// <div class="scrollbar-handle"></div> --> this.handle
|
||||
// </div>
|
||||
// <div class="scrollbar-handle-up"></div> --> this.handleArrows
|
||||
// <div class="scrollbar-handle-down"></div> --> this.handleArrows
|
||||
// </div>
|
||||
//
|
||||
//
|
||||
// TODO: use detach-transform-attach or DOMfragment
|
||||
//
|
||||
buildHtml: function(){
|
||||
|
||||
// build new DOM nodes
|
||||
this.container.children().wrapAll('<div class="scrollbar-pane"/>');
|
||||
this.container.append('<div class="scrollbar-handle-container"><div class="scrollbar-handle"/></div>');
|
||||
if(this.props.arrows){
|
||||
this.container.append('<div class="scrollbar-handle-up"/>').append('<div class="scrollbar-handle-down"/>');
|
||||
}
|
||||
|
||||
// save height of container to re-set it after some DOM manipulations
|
||||
var height = this.container.height();
|
||||
|
||||
// set scrollbar-object properties
|
||||
this.pane = this.container.find('.scrollbar-pane');
|
||||
this.handle = this.container.find('.scrollbar-handle');
|
||||
this.handleContainer = this.container.find('.scrollbar-handle-container');
|
||||
this.handleArrows = this.container.find('.scrollbar-handle-up, .scrollbar-handle-down');
|
||||
this.handleArrowUp = this.container.find('.scrollbar-handle-up');
|
||||
this.handleArrowDown = this.container.find('.scrollbar-handle-down');
|
||||
this.pane_last_top = 0;
|
||||
|
||||
// set some default CSS attributes (may be overwritten by CSS definitions in an external CSS file)
|
||||
this.pane.defaultCss({
|
||||
'top': 0,
|
||||
'left': 0
|
||||
});
|
||||
this.handleContainer.defaultCss({
|
||||
'right': 0
|
||||
});
|
||||
this.handle.defaultCss({
|
||||
'top': 0,
|
||||
'right': 0
|
||||
});
|
||||
this.handleArrows.defaultCss({
|
||||
'right': 0
|
||||
});
|
||||
this.handleArrowUp.defaultCss({
|
||||
'top': 0
|
||||
});
|
||||
this.handleArrowDown.defaultCss({
|
||||
'bottom': 0
|
||||
});
|
||||
|
||||
// set some necessary CSS attributes (can NOT be overwritten by CSS definitions)
|
||||
this.container.css({
|
||||
'position': this.container.css('position') === 'absolute' ? 'absolute' : 'relative',
|
||||
'overflow': 'hidden',
|
||||
'height': height
|
||||
});
|
||||
this.pane.css({
|
||||
'position': 'absolute',
|
||||
'overflow': 'visible',
|
||||
'height': 'auto'
|
||||
});
|
||||
this.handleContainer.css({
|
||||
'position': 'absolute',
|
||||
'top': this.handleArrowUp.outerHeight(true),
|
||||
'height': (this.props.containerHeight - (this.container.outerHeight(true) - this.container.height()) - this.handleArrowUp.outerHeight(true) - this.handleArrowDown.outerHeight(true)) + 'px'
|
||||
});
|
||||
this.handle.css({
|
||||
'position': 'absolute',
|
||||
'cursor': 'pointer'
|
||||
});
|
||||
this.handleArrows.css({
|
||||
'position': 'absolute',
|
||||
'cursor': 'pointer'
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// calculate positions and dimensions of handle and arrow-handles
|
||||
//
|
||||
initHandle: function(){
|
||||
this.props.handleContainerHeight = this.handleContainer.height();
|
||||
this.props.contentHeight = this.pane.height();
|
||||
|
||||
// height of handle
|
||||
this.props.handleHeight = this.opts.handleHeight == 'auto' ? Math.max(Math.ceil(this.props.containerHeight * this.props.handleContainerHeight / this.props.contentHeight), this.opts.handleMinHeight) : this.opts.handleHeight;
|
||||
this.handle.height(this.props.handleHeight);
|
||||
|
||||
// if handle has a border (always be aware of the css box-model), we need to correct the handle height.
|
||||
this.handle.height(2 * this.handle.height() - this.handle.outerHeight(true));
|
||||
|
||||
// min- and max-range for handle
|
||||
this.props.handleTop = {
|
||||
min: 0,
|
||||
max: (this.props.handleContainerHeight - this.props.handleHeight)
|
||||
};
|
||||
|
||||
// ratio of handle-container-height to content-container-height (to calculate position of content related to position of handle)
|
||||
this.props.handleContentRatio = (this.props.contentHeight - this.props.containerHeight) / (this.props.handleContainerHeight - this.props.handleHeight);
|
||||
|
||||
// initial position of handle at top
|
||||
this.handle.top = 0;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// append events on handle and handle-container
|
||||
//
|
||||
appendEvents: function(){
|
||||
|
||||
// append drag-drop event on scrollbar-handle
|
||||
this.handle.bind('mousedown.handle', $.proxy(this, 'startOfHandleMove'));
|
||||
|
||||
// append mousedown event on handle-container
|
||||
this.handleContainer.bind('mousedown.handle', $.proxy(this, 'onHandleContainerMousedown'));
|
||||
|
||||
// append hover event on handle-container
|
||||
this.handleContainer.bind('mouseenter.container mouseleave.container', $.proxy(this, 'onHandleContainerHover'));
|
||||
|
||||
// append click event on scrollbar-up- and scrollbar-down-handles
|
||||
this.handleArrows.bind('mousedown.arrows', $.proxy(this, 'onArrowsMousedown'));
|
||||
|
||||
// append mousewheel event on content container
|
||||
this.container.bind('mousewheel.container', $.proxy(this, 'onMouseWheel'));
|
||||
|
||||
// append hover event on content container
|
||||
this.container.bind('mouseenter.container mouseleave.container', $.proxy(this, 'onContentHover'));
|
||||
|
||||
// do not bubble down click events into content container
|
||||
this.handle.bind('click.scrollbar', this.preventClickBubbling);
|
||||
this.handleContainer.bind('click.scrollbar', this.preventClickBubbling);
|
||||
this.handleArrows.bind('click.scrollbar', this.preventClickBubbling);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// get mouse position helper
|
||||
//
|
||||
mousePosition: function(ev) {
|
||||
return ev.pageY || (ev.clientY + (document.documentElement.scrollTop || document.body.scrollTop)) || 0;
|
||||
},
|
||||
|
||||
|
||||
|
||||
// ---------- event handler ---------------------------------------------------------------
|
||||
|
||||
//
|
||||
// start moving of handle
|
||||
//
|
||||
startOfHandleMove: function(ev){
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
// set start position of mouse
|
||||
this.mouse.start = this.mousePosition(ev);
|
||||
|
||||
// set start position of handle
|
||||
this.handle.start = this.handle.top;
|
||||
|
||||
// bind mousemove- and mouseout-event on document (binding it to document allows having a mousepointer outside handle while moving)
|
||||
$(document).bind('mousemove.handle', $.proxy(this, 'onHandleMove')).bind('mouseup.handle', $.proxy(this, 'endOfHandleMove'));
|
||||
|
||||
// add class for visual change while moving handle
|
||||
this.handle.addClass('move');
|
||||
this.handleContainer.addClass('move');
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// on moving of handle
|
||||
//
|
||||
onHandleMove: function(ev){
|
||||
ev.preventDefault();
|
||||
|
||||
// calculate distance since last fireing of this handler
|
||||
var distance = this.mousePosition(ev) - this.mouse.start;
|
||||
|
||||
// calculate new handle position
|
||||
this.handle.top = this.handle.start + distance;
|
||||
|
||||
// update positions
|
||||
this.setHandlePosition();
|
||||
this.setContentPosition();
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// end moving of handle
|
||||
//
|
||||
endOfHandleMove: function(ev){
|
||||
|
||||
// remove handle events (which were attached in the startOfHandleMove-method)
|
||||
$(document).unbind('.handle');
|
||||
|
||||
// remove class for visual change
|
||||
this.handle.removeClass('move');
|
||||
this.handleContainer.removeClass('move');
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// set position of handle
|
||||
//
|
||||
setHandlePosition: function(){
|
||||
|
||||
// stay within range [handleTop.min, handleTop.max]
|
||||
this.handle.top = (this.handle.top > this.props.handleTop.max) ? this.props.handleTop.max : this.handle.top;
|
||||
this.handle.top = (this.handle.top < this.props.handleTop.min) ? this.props.handleTop.min : this.handle.top;
|
||||
|
||||
this.handle[0].style.top = this.handle.top + 'px';
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// set position of content
|
||||
//
|
||||
setContentPosition: function(){
|
||||
|
||||
// derive position of content from position of handle
|
||||
this.pane.top = -1 * this.props.handleContentRatio * this.handle.top;
|
||||
|
||||
// var distance = Math.round(Math.abs(this.pane_last_top - this.pane.top));
|
||||
// $(this.pane[0]).stop().animate({top: this.pane.top}, 10 * distance / Math.sqrt(distance));
|
||||
|
||||
this.pane[0].style.top = this.pane.top + 'px';
|
||||
this.pane_last_top = this.pane.top;
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// mouse wheel movement
|
||||
//
|
||||
onMouseWheel: function(ev, delta){
|
||||
|
||||
// calculate new handle position
|
||||
this.handle.top -= delta*15; // awfull fix
|
||||
|
||||
this.setHandlePosition();
|
||||
this.setContentPosition();
|
||||
|
||||
// prevent default scrolling of the entire document if handle is within [min, max]-range
|
||||
if(this.handle.top > this.props.handleTop.min && this.handle.top < this.props.handleTop.max){
|
||||
ev.preventDefault();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// append click handler on handle-container (outside of handle itself) to click up and down the handle
|
||||
//
|
||||
onHandleContainerMousedown: function(ev){
|
||||
ev.preventDefault();
|
||||
|
||||
// do nothing if clicked on handle
|
||||
if(!$(ev.target).hasClass('scrollbar-handle-container')){
|
||||
return false;
|
||||
}
|
||||
|
||||
// determine direction for handle movement (clicked above or below the handler?)
|
||||
this.handle.direction = (this.handle.offset().top < this.mousePosition(ev)) ? 1 : -1;
|
||||
|
||||
// set incremental step of handle
|
||||
this.handle.step = this.opts.scrollStep;
|
||||
|
||||
// stop handle movement on mouseup
|
||||
var that = this;
|
||||
$(document).bind('mouseup.handlecontainer', function(){
|
||||
clearInterval(timer);
|
||||
that.handle.unbind('mouseenter.handlecontainer');
|
||||
$(document).unbind('mouseup.handlecontainer');
|
||||
});
|
||||
|
||||
// stop handle movement when mouse is over handle
|
||||
//
|
||||
// TODO: this event is fired by Firefox only. Damn!
|
||||
// Right now, I do not know any workaround for this. Mayby I should solve this by collision-calculation of mousepointer and handle
|
||||
this.handle.bind('mouseenter.handlecontainer', function(){
|
||||
clearInterval(timer);
|
||||
});
|
||||
|
||||
// repeat handle movement while mousedown
|
||||
var timer = setInterval($.proxy(this.moveHandle, this), this.opts.scrollSpeed);
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// append mousedown handler on handle-arrows
|
||||
//
|
||||
onArrowsMousedown: function(ev){
|
||||
ev.preventDefault();
|
||||
|
||||
// determine direction for handle movement
|
||||
this.handle.direction = $(ev.target).hasClass('scrollbar-handle-up') ? -1 : 1;
|
||||
|
||||
// set incremental step of handle
|
||||
this.handle.step = this.opts.scrollStepArrows;
|
||||
|
||||
// add class for visual change while moving handle
|
||||
$(ev.target).addClass('move');
|
||||
|
||||
// repeat handle movement while mousedown
|
||||
var timer = setInterval($.proxy(this.moveHandle, this), this.opts.scrollSpeedArrows);
|
||||
|
||||
// stop handle movement on mouseup
|
||||
$(document).one('mouseup.arrows', function(){
|
||||
clearInterval(timer);
|
||||
$(ev.target).removeClass('move');
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// move handle by a distinct step while click on arrows or handle-container
|
||||
//
|
||||
moveHandle: function(){
|
||||
this.handle.top = (this.handle.direction === 1) ? Math.min(this.handle.top + this.handle.step, this.props.handleTop.max) : Math.max(this.handle.top - this.handle.step, this.props.handleTop.min);
|
||||
this.handle[0].style.top = this.handle.top + 'px';
|
||||
|
||||
this.setContentPosition();
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// add class attribute on content while interacting with content
|
||||
//
|
||||
onContentHover: function(ev){
|
||||
if(ev.type === 'mouseenter'){
|
||||
this.container.addClass('hover');
|
||||
this.handleContainer.addClass('hover');
|
||||
} else {
|
||||
this.container.removeClass('hover');
|
||||
this.handleContainer.removeClass('hover');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// add class attribute on handle-container while hovering it
|
||||
//
|
||||
onHandleContainerHover: function(ev){
|
||||
if(ev.type === 'mouseenter'){
|
||||
this.handleArrows.addClass('hover');
|
||||
} else {
|
||||
this.handleArrows.removeClass('hover');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// do not bubble down to avoid triggering click events attached within the container
|
||||
//
|
||||
preventClickBubbling: function(ev){
|
||||
ev.stopPropagation();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// ----- helpers ------------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// determine content height
|
||||
//
|
||||
$.fn.scrollbar.contentHeight = function(elem){
|
||||
|
||||
// clone and wrap content temporarily and meassure content height within the original context.
|
||||
// wrapper container need to have an overflow set to 'hidden' to respect margin collapsing
|
||||
|
||||
|
||||
// TODO: analyse anlternative which does not require an additional container. a clone may also allow to meassure a non visible element.
|
||||
/*
|
||||
var clone = elem.clone().wrapInner('<div/>').find(':first-child');
|
||||
elem.append(clone);
|
||||
var height = clone.css({overflow:'hidden'}).height();
|
||||
clone.remove();
|
||||
|
||||
return height;
|
||||
*/
|
||||
var content = elem.wrapInner('<div/>');
|
||||
var height = elem.find(':first').css({overflow:'hidden'}).height();
|
||||
|
||||
return height;
|
||||
|
||||
// FIXME: manipulating the DOM is not the resposibility of $.fn.scrollbar.contentHeight()
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// ----- default css ---------------------------------------------------------------------
|
||||
//
|
||||
$.fn.defaultCss = function(styles){
|
||||
|
||||
// 'not-defined'-values
|
||||
var notdef = {
|
||||
'right': 'auto',
|
||||
'left': 'auto',
|
||||
'top': 'auto',
|
||||
'bottom': 'auto',
|
||||
'position': 'static'
|
||||
};
|
||||
|
||||
// loop through all style definitions and check for a definition already set by css.
|
||||
// if no definition is found, apply the default css definition
|
||||
return this.each(function(){
|
||||
var elem = $(this);
|
||||
for(var style in styles){
|
||||
if(elem.css(style) === notdef[style]){
|
||||
elem.css(style, styles[style]);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// ----- mousewheel event ---------------------------------------------------------------------
|
||||
// based on jquery.mousewheel.js from Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
|
||||
//
|
||||
$.event.special.mousewheel = {
|
||||
|
||||
setup: function(){
|
||||
if (this.addEventListener){
|
||||
this.addEventListener('mousewheel', $.fn.scrollbar.mouseWheelHandler, false);
|
||||
this.addEventListener('DOMMouseScroll', $.fn.scrollbar.mouseWheelHandler, false);
|
||||
} else {
|
||||
this.onmousewheel = $.fn.scrollbar.mouseWheelHandler;
|
||||
}
|
||||
},
|
||||
|
||||
teardown: function(){
|
||||
if (this.removeEventListener){
|
||||
this.removeEventListener('mousewheel', $.fn.scrollbar.mouseWheelHandler, false);
|
||||
this.removeEventListener('DOMMouseScroll', $.fn.scrollbar.mouseWheelHandler, false);
|
||||
} else {
|
||||
this.onmousewheel = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$.fn.extend({
|
||||
mousewheel: function(fn){
|
||||
return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
|
||||
},
|
||||
|
||||
unmousewheel: function(fn){
|
||||
return this.unbind("mousewheel", fn);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$.fn.scrollbar.mouseWheelHandler = function(event) {
|
||||
var orgEvent = event || window.event,
|
||||
args = [].slice.call(arguments, 1),
|
||||
delta = 0,
|
||||
returnValue = true,
|
||||
deltaX = 0,
|
||||
deltaY = 0;
|
||||
|
||||
event = $.event.fix(orgEvent);
|
||||
event.type = "mousewheel";
|
||||
|
||||
// Old school scrollwheel delta
|
||||
if(event.wheelDelta){
|
||||
delta = event.wheelDelta / 120;
|
||||
}
|
||||
if(event.detail){
|
||||
delta = -event.detail / 3;
|
||||
}
|
||||
|
||||
// Gecko
|
||||
if(orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS){
|
||||
deltaY = 0;
|
||||
deltaX = -1 * delta;
|
||||
}
|
||||
|
||||
// Webkit
|
||||
if(orgEvent.wheelDeltaY !== undefined){
|
||||
deltaY = orgEvent.wheelDeltaY / 120;
|
||||
}
|
||||
if(orgEvent.wheelDeltaX !== undefined){
|
||||
deltaX = -1 * orgEvent.wheelDeltaX / 120;
|
||||
}
|
||||
|
||||
// Add event and delta to the front of the arguments
|
||||
args.unshift(event, delta, deltaX, deltaY);
|
||||
|
||||
return $.event.handle.apply(this, args);
|
||||
};
|
||||
|
||||
})(jQuery, document); // inject global jQuery object
|
||||
Reference in New Issue
Block a user