(function( $ ) {
/**
* jQuery.fn.dependsOn
* @version 1.0.1
* @date September 22, 2010
* @since 1.0.0, September 19, 2010
* @package jquery-sparkle {@link http://www.balupton/projects/jquery-sparkle}
* @author Benjamin "balupton" Lupton {@link http://www.balupton.com}
* @copyright (c) 2010 Benjamin Arthur Lupton {@link http://www.balupton.com}
* @license Attribution-ShareAlike 2.5 Generic {@link http://creativecommons.org/licenses/by-sa/2.5/
*/
$.fn.dependsOn = function(attribute){
if ((attribute === null) || (typeof attribute === 'undefined')) var attribute = 'depends_on';
this.each(function(){
var $target = $(this),
depends = $target.attr(attribute).split("="),
$source = $("*[name='"+depends[0]+"']:not(:hidden)"),
source = $source.attr('id') || $source.attr('name'),
value = depends[1];
// Add Data
var dependsOnStatus = $target.data('dependsOnStatus')||{};
dependsOnStatus[source] = false;
$target.data('dependsOnStatus',dependsOnStatus);
// Add Event
$source.change(function(){
var pass = false;
var $source = $(this); // so $source won't be a group for radios
// Determine
if ( (value === null) || (typeof value === 'undefined') ) {
// We don't have a value
if ( $source.is(':checkbox,:radio') ) {
pass = $source.is(':selected:enabled,:checked:enabled');
}
else {
pass = Boolean($source.val());
}
}
else {
// We do have a value
if ( $source.is(':checkbox,:radio') ) {
pass = $source.is(':selected:enabled,:checked:enabled') && ($source.val() == value);
}
else {
pass = $source.val() == value;
}
}
// Update
var dependsOnStatus = $target.data('dependsOnStatus')||{};
dependsOnStatus[source] = pass;
$target.data('dependsOnStatus',dependsOnStatus);
// Determine
var passAll = true;
$.each(dependsOnStatus, function(i,v){
if ( !v ) {
passAll = false;
return false; // break
}
});
// console.log(dependsOnStatus);
// Adjust
if ( !passAll ) {
$target.attr('disabled','disabled').addClass('disabled');
$target.parent('label').addClass('disabled');
}
else {
$target.removeAttr('disabled').removeClass('disabled');
$target.parent('label').removeClass('disabled');
}
}).trigger('change');
// Chain
return this;
});
};
})(jQuery);
/**
* AJAX Upload
* Project page - http://valums.com/ajax-upload/
* Copyright (c) 2008 Andris Valums, http://valums.com
* Licensed under the MIT license (http://valums.com/mit-license/)
*/
(function(){
var d = document, w = window;
/**
* Get element by id
*/
function get(element){
if (typeof element == "string")
element = d.getElementById(element);
return element;
}
/**
* Attaches event to a dom element
*/
function addEvent(el, type, fn){
if (w.addEventListener){
el.addEventListener(type, fn, false);
} else if (w.attachEvent){
var f = function(){
fn.call(el, w.event);
};
el.attachEvent('on' + type, f)
}
}
/**
* Creates and returns element from html chunk
*/
var toElement = function(){
var div = d.createElement('div');
return function(html){
div.innerHTML = html;
var el = div.childNodes[0];
div.removeChild(el);
return el;
}
}();
function hasClass(ele,cls){
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
if (!hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,' ');
}
// getOffset function copied from jQuery lib (http://jquery.com/)
if (document.documentElement["getBoundingClientRect"]){
// Get Offset using getBoundingClientRect
// http://ejohn.org/blog/getboundingclientrect-is-awesome/
var getOffset = function(el){
var box = el.getBoundingClientRect(),
doc = el.ownerDocument,
body = doc.body,
docElem = doc.documentElement,
// for ie
clientTop = docElem.clientTop || body.clientTop || 0,
clientLeft = docElem.clientLeft || body.clientLeft || 0,
// In Internet Explorer 7 getBoundingClientRect property is treated as physical,
// while others are logical. Make all logical, like in IE8.
zoom = 1;
if (body.getBoundingClientRect) {
var bound = body.getBoundingClientRect();
zoom = (bound.right - bound.left)/body.clientWidth;
}
if (zoom > 1){
clientTop = 0;
clientLeft = 0;
}
var top = box.top/zoom + (window.pageYOffset || docElem && docElem.scrollTop/zoom || body.scrollTop/zoom) - clientTop,
left = box.left/zoom + (window.pageXOffset|| docElem && docElem.scrollLeft/zoom || body.scrollLeft/zoom) - clientLeft;
return {
top: top,
left: left
};
}
} else {
// Get offset adding all offsets
var getOffset = function(el){
if (w.jQuery){
return jQuery(el).offset();
}
var top = 0, left = 0;
do {
top += el.offsetTop || 0;
left += el.offsetLeft || 0;
}
while (el = el.offsetParent);
return {
left: left,
top: top
};
}
}
function getBox(el){
var left, right, top, bottom;
var offset = getOffset(el);
left = offset.left;
top = offset.top;
right = left + el.offsetWidth;
bottom = top + el.offsetHeight;
return {
left: left,
right: right,
top: top,
bottom: bottom
};
}
/**
* Crossbrowser mouse coordinates
*/
function getMouseCoords(e){
// pageX/Y is not supported in IE
// http://www.quirksmode.org/dom/w3c_cssom.html
if (!e.pageX && e.clientX){
// In Internet Explorer 7 some properties (mouse coordinates) are treated as physical,
// while others are logical (offset).
var zoom = 1;
var body = document.body;
if (body.getBoundingClientRect) {
var bound = body.getBoundingClientRect();
zoom = (bound.right - bound.left)/body.clientWidth;
}
return {
x: e.clientX / zoom + d.body.scrollLeft + d.documentElement.scrollLeft,
y: e.clientY / zoom + d.body.scrollTop + d.documentElement.scrollTop
};
}
return {
x: e.pageX,
y: e.pageY
};
}
/**
* Function generates unique id
*/
var getUID = function(){
var id = 0;
return function(){
return 'ValumsAjaxUpload' + id++;
}
}();
function fileFromPath(file){
return file.replace(/.*(\/|\\)/, "");
}
function getExt(file){
return (/[.]/.exec(file)) ? /[^.]+$/.exec(file.toLowerCase()) : '';
}
/**
* Cross-browser way to get xhr object
*/
var getXhr = function(){
var xhr;
return function(){
if (xhr) return xhr;
if (typeof XMLHttpRequest !== 'undefined') {
xhr = new XMLHttpRequest();
} else {
var v = [
"Microsoft.XmlHttp",
"MSXML2.XmlHttp.5.0",
"MSXML2.XmlHttp.4.0",
"MSXML2.XmlHttp.3.0",
"MSXML2.XmlHttp.2.0"
];
for (var i=0; i < v.length; i++){
try {
xhr = new ActiveXObject(v[i]);
break;
} catch (e){}
}
}
return xhr;
}
}();
// Please use AjaxUpload , Ajax_upload will be removed in the next version
Ajax_upload = AjaxUpload = function(button, options){
if (button.jquery){
// jquery object was passed
button = button[0];
} else if (typeof button == "string" && /^#.*/.test(button)){
button = button.slice(1);
}
button = get(button);
this._input = null;
this._button = button;
this._disabled = false;
this._submitting = false;
// Variable changes to true if the button was clicked
// 3 seconds ago (requred to fix Safari on Mac error)
this._justClicked = false;
this._parentDialog = d.body;
if (window.jQuery && jQuery.ui && jQuery.ui.dialog){
var parentDialog = jQuery(this._button).parents('.ui-dialog');
if (parentDialog.length){
this._parentDialog = parentDialog[0];
}
}
this._settings = {
// Location of the server-side upload script
action: 'upload.php',
// File upload name
name: 'userfile',
// Additional data to send
data: {},
// Submit file as soon as it's selected
autoSubmit: true,
// The type of data that you're expecting back from the server.
// Html and xml are detected automatically.
// Only useful when you are using json data as a response.
// Set to "json" in that case.
responseType: false,
// Location of the server-side script that fixes Safari
// hanging problem returning "Connection: close" header
closeConnection: '',
// Class applied to button when mouse is hovered
hoverClass: 'hover',
// When user selects a file, useful with autoSubmit disabled
onChange: function(file, extension){},
// Callback to fire before file is uploaded
// You can return false to cancel upload
onSubmit: function(file, extension){},
// Fired when file upload is completed
// WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
onComplete: function(file, response) {}
};
// Merge the users options with our defaults
for (var i in options) {
this._settings[i] = options[i];
}
this._createInput();
this._rerouteClicks();
}
// assigning methods to our class
AjaxUpload.prototype = {
setData : function(data){
this._settings.data = data;
},
disable : function(){
this._disabled = true;
},
enable : function(){
this._disabled = false;
},
// removes instance
destroy : function(){
if(this._input){
if(this._input.parentNode){
this._input.parentNode.removeChild(this._input);
}
this._input = null;
}
},
/**
* Creates invisible file input above the button
*/
_createInput : function(){
var self = this;
var input = d.createElement("input");
input.setAttribute('type', 'file');
input.setAttribute('name', this._settings.name);
var styles = {
'position' : 'absolute'
,'margin': '-5px 0 0 -175px'
,'padding': 0
,'width': '220px'
,'height': '30px'
,'fontSize': '14px'
,'opacity': 0
,'cursor': 'pointer'
,'display' : 'none'
,'zIndex' : 2147483583 //Max zIndex supported by Opera 9.0-9.2x
// Strange, I expected 2147483647
// Doesn't work in IE :(
//,'direction' : 'ltr'
};
for (var i in styles){
input.style[i] = styles[i];
}
// Make sure that element opacity exists
// (IE uses filter instead)
if ( ! (input.style.opacity === "0")){
input.style.filter = "alpha(opacity=0)";
}
this._parentDialog.appendChild(input);
addEvent(input, 'change', function(){
// get filename from input
var file = fileFromPath(this.value);
if(self._settings.onChange.call(self, file, getExt(file)) == false ){
return;
}
// Submit form when value is changed
if (self._settings.autoSubmit){
self.submit();
}
});
// Fixing problem with Safari
// The problem is that if you leave input before the file select dialog opens
// it does not upload the file.
// As dialog opens slowly (it is a sheet dialog which takes some time to open)
// there is some time while you can leave the button.
// So we should not change display to none immediately
addEvent(input, 'click', function(){
self.justClicked = true;
setTimeout(function(){
// we will wait 3 seconds for dialog to open
self.justClicked = false;
}, 2500);
});
this._input = input;
},
_rerouteClicks : function (){
var self = this;
// IE displays 'access denied' error when using this method
// other browsers just ignore click()
// addEvent(this._button, 'click', function(e){
// self._input.click();
// });
var box, dialogOffset = {top:0, left:0}, over = false;
addEvent(self._button, 'mouseover', function(e){
if (!self._input || over) return;
over = true;
box = getBox(self._button);
if (self._parentDialog != d.body){
dialogOffset = getOffset(self._parentDialog);
}
});
// We can't use mouseout on the button,
// because invisible input is over it
addEvent(document, 'mousemove', function(e){
var input = self._input;
if (!input || !over) return;
if (self._disabled){
removeClass(self._button, self._settings.hoverClass);
input.style.display = 'none';
return;
}
var c = getMouseCoords(e);
if ((c.x >= box.left) && (c.x <= box.right) &&
(c.y >= box.top) && (c.y <= box.bottom)){
input.style.top = c.y - dialogOffset.top + 'px';
input.style.left = c.x - dialogOffset.left + 'px';
input.style.display = 'block';
addClass(self._button, self._settings.hoverClass);
} else {
// mouse left the button
over = false;
var check = setInterval(function(){
// if input was just clicked do not hide it
// to prevent safari bug
if (self.justClicked){
return;
}
if ( !over ){
input.style.display = 'none';
}
clearInterval(check);
}, 25);
removeClass(self._button, self._settings.hoverClass);
}
});
},
/**
* Creates iframe with unique name
*/
_createIframe : function(){
// unique name
// We cannot use getTime, because it sometimes return
// same value in safari :(
var id = getUID();
// Remove ie6 "This page contains both secure and nonsecure items" prompt
// http://tinyurl.com/77w9wh
var iframe = toElement('');
iframe.id = id;
iframe.style.display = 'none';
d.body.appendChild(iframe);
return iframe;
},
/**
* Upload file without refreshing the page
*/
submit : function(){
var self = this, settings = this._settings;
if (this._input.value === ''){
// there is no file
return;
}
// get filename from input
var file = fileFromPath(this._input.value);
// execute user event
if (! (settings.onSubmit.call(this, file, getExt(file)) == false)) {
// Create new iframe for this submission
var iframe = this._createIframe();
// Do not submit if user function returns false
var form = this._createForm(iframe);
form.appendChild(this._input);
// A pretty little hack to make uploads not hang in Safari. Just call this
// immediately before the upload is submitted. This does an Ajax call to
// the server, which returns an empty document with the "Connection: close"
// header, telling Safari to close the active connection.
// http://blog.airbladesoftware.com/2007/8/17/note-to-self-prevent-uploads-hanging-in-safari
if (settings.closeConnection && /AppleWebKit|MSIE/.test(navigator.userAgent)){
var xhr = getXhr();
// Open synhronous connection
xhr.open('GET', settings.closeConnection, false);
xhr.send('');
}
form.submit();
d.body.removeChild(form);
form = null;
this._input = null;
// create new input
this._createInput();
var toDeleteFlag = false;
addEvent(iframe, 'load', function(e){
if (// For Safari
iframe.src == "javascript:'%3Chtml%3E%3C/html%3E';" ||
// For FF, IE
iframe.src == "javascript:'';"){
// First time around, do not delete.
if( toDeleteFlag ){
// Fix busy state in FF3
setTimeout( function() {
d.body.removeChild(iframe);
}, 0);
}
return;
}
var doc = iframe.contentDocument ? iframe.contentDocument : frames[iframe.id].document;
// fixing Opera 9.26
if (doc.readyState && doc.readyState != 'complete'){
// Opera fires load event multiple times
// Even when the DOM is not ready yet
// this fix should not affect other browsers
return;
}
// fixing Opera 9.64
if (doc.body && doc.body.innerHTML == "false"){
// In Opera 9.64 event was fired second time
// when body.innerHTML changed from false
// to server response approx. after 1 sec
return;
}
var response;
if (doc.XMLDocument){
// response is a xml document IE property
response = doc.XMLDocument;
} else if (doc.body){
// response is html document or plain text
response = doc.body.innerHTML;
if (settings.responseType && settings.responseType.toLowerCase() == 'json'){
// If the document was sent as 'application/javascript' or
// 'text/javascript', then the browser wraps the text in a
// tag and performs html encoding on the contents. In this case,
// we need to pull the original text content from the text node's
// nodeValue property to retrieve the unmangled content.
// Note that IE6 only understands text/html
if (doc.body.firstChild && doc.body.firstChild.nodeName.toUpperCase() == 'PRE'){
response = doc.body.firstChild.firstChild.nodeValue;
}
if (response) {
response = window["eval"]("(" + response + ")");
} else {
response = {};
}
}
} else {
// response is a xml document
var response = doc;
}
settings.onComplete.call(self, file, response);
// Reload blank page, so that reloading main page
// does not re-submit the post. Also, remember to
// delete the frame
toDeleteFlag = true;
// Fix IE mixed content issue
iframe.src = "javascript:'';";
});
} else {
// clear input to allow user to select same file
// Doesn't work in IE6
// this._input.value = '';
d.body.removeChild(this._input);
this._input = null;
// create new input
this._createInput();
}
},
/**
* Creates form, that will be submitted to iframe
*/
_createForm : function(iframe){
var settings = this._settings;
// method, enctype must be specified here
// because changing this attr on the fly is not allowed in IE 6/7
var form = toElement('');
form.style.display = 'none';
form.action = settings.action;
form.target = iframe.name;
d.body.appendChild(form);
// Create hidden input element for each data key
for (var prop in settings.data){
var el = d.createElement("input");
el.type = 'hidden';
el.name = prop;
el.value = settings.data[prop];
form.appendChild(el);
}
return form;
}
};
})();
/**
*
* Color picker
* Author: Stefan Petre www.eyecon.ro
*
* Dual licensed under the MIT and GPL licenses
*
*/
(function ($) {
var ColorPicker = function () {
var
ids = {},
inAction,
charMin = 65,
visible,
tpl = '',
defaults = {
eventName: 'click',
onShow: function () {},
onBeforeShow: function(){},
onHide: function () {},
onChange: function () {},
onSubmit: function () {},
color: 'ff0000',
livePreview: true,
flat: false
},
fillRGBFields = function (hsb, cal) {
var rgb = HSBToRGB(hsb);
$(cal).data('colorpicker').fields
.eq(1).val(rgb.r).end()
.eq(2).val(rgb.g).end()
.eq(3).val(rgb.b).end();
},
fillHSBFields = function (hsb, cal) {
$(cal).data('colorpicker').fields
.eq(4).val(hsb.h).end()
.eq(5).val(hsb.s).end()
.eq(6).val(hsb.b).end();
},
fillHexFields = function (hsb, cal) {
$(cal).data('colorpicker').fields
.eq(0).val(HSBToHex(hsb)).end();
},
setSelector = function (hsb, cal) {
$(cal).data('colorpicker').selector.css('backgroundColor', '#' + HSBToHex({h: hsb.h, s: 100, b: 100}));
$(cal).data('colorpicker').selectorIndic.css({
left: parseInt(150 * hsb.s/100, 10),
top: parseInt(150 * (100-hsb.b)/100, 10)
});
},
setHue = function (hsb, cal) {
$(cal).data('colorpicker').hue.css('top', parseInt(150 - 150 * hsb.h/360, 10));
},
setCurrentColor = function (hsb, cal) {
$(cal).data('colorpicker').currentColor.css('backgroundColor', '#' + HSBToHex(hsb));
},
setNewColor = function (hsb, cal) {
$(cal).data('colorpicker').newColor.css('backgroundColor', '#' + HSBToHex(hsb));
},
keyDown = function (ev) {
var pressedKey = ev.charCode || ev.keyCode || -1;
if ((pressedKey > charMin && pressedKey <= 90) || pressedKey == 32) {
return false;
}
var cal = $(this).parent().parent();
if (cal.data('colorpicker').livePreview === true) {
change.apply(this);
}
},
change = function (ev) {
var cal = $(this).parent().parent(), col;
if (this.parentNode.className.indexOf('_hex') > 0) {
cal.data('colorpicker').color = col = HexToHSB(fixHex(this.value));
} else if (this.parentNode.className.indexOf('_hsb') > 0) {
cal.data('colorpicker').color = col = fixHSB({
h: parseInt(cal.data('colorpicker').fields.eq(4).val(), 10),
s: parseInt(cal.data('colorpicker').fields.eq(5).val(), 10),
b: parseInt(cal.data('colorpicker').fields.eq(6).val(), 10)
});
} else {
cal.data('colorpicker').color = col = RGBToHSB(fixRGB({
r: parseInt(cal.data('colorpicker').fields.eq(1).val(), 10),
g: parseInt(cal.data('colorpicker').fields.eq(2).val(), 10),
b: parseInt(cal.data('colorpicker').fields.eq(3).val(), 10)
}));
}
if (ev) {
fillRGBFields(col, cal.get(0));
fillHexFields(col, cal.get(0));
fillHSBFields(col, cal.get(0));
}
setSelector(col, cal.get(0));
setHue(col, cal.get(0));
setNewColor(col, cal.get(0));
cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el]);
},
blur = function (ev) {
var cal = $(this).parent().parent();
cal.data('colorpicker').fields.parent().removeClass('colorpicker_focus');
},
focus = function () {
charMin = this.parentNode.className.indexOf('_hex') > 0 ? 70 : 65;
$(this).parent().parent().data('colorpicker').fields.parent().removeClass('colorpicker_focus');
$(this).parent().addClass('colorpicker_focus');
},
downIncrement = function (ev) {
var field = $(this).parent().find('input').focus();
var current = {
el: $(this).parent().addClass('colorpicker_slider'),
max: this.parentNode.className.indexOf('_hsb_h') > 0 ? 360 : (this.parentNode.className.indexOf('_hsb') > 0 ? 100 : 255),
y: ev.pageY,
field: field,
val: parseInt(field.val(), 10),
preview: $(this).parent().parent().data('colorpicker').livePreview
};
$(document).bind('mouseup', current, upIncrement);
$(document).bind('mousemove', current, moveIncrement);
},
moveIncrement = function (ev) {
ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val + ev.pageY - ev.data.y, 10))));
if (ev.data.preview) {
change.apply(ev.data.field.get(0), [true]);
}
return false;
},
upIncrement = function (ev) {
change.apply(ev.data.field.get(0), [true]);
ev.data.el.removeClass('colorpicker_slider').find('input').focus();
$(document).unbind('mouseup', upIncrement);
$(document).unbind('mousemove', moveIncrement);
return false;
},
downHue = function (ev) {
var current = {
cal: $(this).parent(),
y: $(this).offset().top
};
current.preview = current.cal.data('colorpicker').livePreview;
$(document).bind('mouseup', current, upHue);
$(document).bind('mousemove', current, moveHue);
},
moveHue = function (ev) {
change.apply(
ev.data.cal.data('colorpicker')
.fields
.eq(4)
.val(parseInt(360*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.y))))/150, 10))
.get(0),
[ev.data.preview]
);
return false;
},
upHue = function (ev) {
fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
$(document).unbind('mouseup', upHue);
$(document).unbind('mousemove', moveHue);
return false;
},
downSelector = function (ev) {
var current = {
cal: $(this).parent(),
pos: $(this).offset()
};
current.preview = current.cal.data('colorpicker').livePreview;
$(document).bind('mouseup', current, upSelector);
$(document).bind('mousemove', current, moveSelector);
},
moveSelector = function (ev) {
change.apply(
ev.data.cal.data('colorpicker')
.fields
.eq(6)
.val(parseInt(100*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.pos.top))))/150, 10))
.end()
.eq(5)
.val(parseInt(100*(Math.max(0,Math.min(150,(ev.pageX - ev.data.pos.left))))/150, 10))
.get(0),
[ev.data.preview]
);
return false;
},
upSelector = function (ev) {
fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
$(document).unbind('mouseup', upSelector);
$(document).unbind('mousemove', moveSelector);
return false;
},
enterSubmit = function (ev) {
$(this).addClass('colorpicker_focus');
},
leaveSubmit = function (ev) {
$(this).removeClass('colorpicker_focus');
},
clickSubmit = function (ev) {
var cal = $(this).parent();
var col = cal.data('colorpicker').color;
cal.data('colorpicker').origColor = col;
setCurrentColor(col, cal.get(0));
cal.data('colorpicker').onSubmit(col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el);
},
show = function (ev) {
var cal = $('#' + $(this).data('colorpickerId'));
cal.data('colorpicker').onBeforeShow.apply(this, [cal.get(0)]);
var pos = $(this).offset();
var viewPort = getViewport();
var top = pos.top + this.offsetHeight;
var left = pos.left;
if (top + 176 > viewPort.t + viewPort.h) {
top -= this.offsetHeight + 176;
}
if (left + 356 > viewPort.l + viewPort.w) {
left -= 356;
}
cal.css({left: left + 'px', top: top + 'px'});
if (cal.data('colorpicker').onShow.apply(this, [cal.get(0)]) != false) {
cal.show();
}
$(document).bind('mousedown', {cal: cal}, hide);
return false;
},
hide = function (ev) {
if (!isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0))) {
if (ev.data.cal.data('colorpicker').onHide.apply(this, [ev.data.cal.get(0)]) != false) {
ev.data.cal.hide();
}
$(document).unbind('mousedown', hide);
}
},
isChildOf = function(parentEl, el, container) {
if (parentEl == el) {
return true;
}
if (parentEl.contains) {
return parentEl.contains(el);
}
if ( parentEl.compareDocumentPosition ) {
return !!(parentEl.compareDocumentPosition(el) & 16);
}
var prEl = el.parentNode;
while(prEl && prEl != container) {
if (prEl == parentEl)
return true;
prEl = prEl.parentNode;
}
return false;
},
getViewport = function () {
var m = document.compatMode == 'CSS1Compat';
return {
l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
t : window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop),
w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth),
h : window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight)
};
},
fixHSB = function (hsb) {
return {
h: Math.min(360, Math.max(0, hsb.h)),
s: Math.min(100, Math.max(0, hsb.s)),
b: Math.min(100, Math.max(0, hsb.b))
};
},
fixRGB = function (rgb) {
return {
r: Math.min(255, Math.max(0, rgb.r)),
g: Math.min(255, Math.max(0, rgb.g)),
b: Math.min(255, Math.max(0, rgb.b))
};
},
fixHex = function (hex) {
var len = 6 - hex.length;
if (len > 0) {
var o = [];
for (var i=0; i -1) ? hex.substring(1) : hex), 16);
return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
},
HexToHSB = function (hex) {
return RGBToHSB(HexToRGB(hex));
},
RGBToHSB = function (rgb) {
var hsb = {
h: 0,
s: 0,
b: 0
};
var min = Math.min(rgb.r, rgb.g, rgb.b);
var max = Math.max(rgb.r, rgb.g, rgb.b);
var delta = max - min;
hsb.b = max;
if (max != 0) {
}
hsb.s = max != 0 ? 255 * delta / max : 0;
if (hsb.s != 0) {
if (rgb.r == max) {
hsb.h = (rgb.g - rgb.b) / delta;
} else if (rgb.g == max) {
hsb.h = 2 + (rgb.b - rgb.r) / delta;
} else {
hsb.h = 4 + (rgb.r - rgb.g) / delta;
}
} else {
hsb.h = -1;
}
hsb.h *= 60;
if (hsb.h < 0) {
hsb.h += 360;
}
hsb.s *= 100/255;
hsb.b *= 100/255;
return hsb;
},
HSBToRGB = function (hsb) {
var rgb = {};
var h = Math.round(hsb.h);
var s = Math.round(hsb.s*255/100);
var v = Math.round(hsb.b*255/100);
if(s == 0) {
rgb.r = rgb.g = rgb.b = v;
} else {
var t1 = v;
var t2 = (255-s)*v/255;
var t3 = (t1-t2)*(h%60)/60;
if(h==360) h = 0;
if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
else {rgb.r=0; rgb.g=0; rgb.b=0}
}
return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
},
RGBToHex = function (rgb) {
var hex = [
rgb.r.toString(16),
rgb.g.toString(16),
rgb.b.toString(16)
];
$.each(hex, function (nr, val) {
if (val.length == 1) {
hex[nr] = '0' + val;
}
});
return hex.join('');
},
HSBToHex = function (hsb) {
return RGBToHex(HSBToRGB(hsb));
},
restoreOriginal = function () {
var cal = $(this).parent();
var col = cal.data('colorpicker').origColor;
cal.data('colorpicker').color = col;
fillRGBFields(col, cal.get(0));
fillHexFields(col, cal.get(0));
fillHSBFields(col, cal.get(0));
setSelector(col, cal.get(0));
setHue(col, cal.get(0));
setNewColor(col, cal.get(0));
};
return {
init: function (opt) {
opt = $.extend({}, defaults, opt||{});
if (typeof opt.color == 'string') {
opt.color = HexToHSB(opt.color);
} else if (opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined) {
opt.color = RGBToHSB(opt.color);
} else if (opt.color.h != undefined && opt.color.s != undefined && opt.color.b != undefined) {
opt.color = fixHSB(opt.color);
} else {
return this;
}
return this.each(function () {
if (!$(this).data('colorpickerId')) {
var options = $.extend({}, opt);
options.origColor = opt.color;
var id = 'collorpicker_' + parseInt(Math.random() * 1000);
$(this).data('colorpickerId', id);
var cal = $(tpl).attr('id', id);
if (options.flat) {
cal.appendTo(this).show();
} else {
cal.appendTo(document.body);
}
options.fields = cal
.find('input')
.bind('keyup', keyDown)
.bind('change', change)
.bind('blur', blur)
.bind('focus', focus);
cal
.find('span').bind('mousedown', downIncrement).end()
.find('>div.colorpicker_current_color').bind('click', restoreOriginal);
options.selector = cal.find('div.colorpicker_color').bind('mousedown', downSelector);
options.selectorIndic = options.selector.find('div div');
options.el = this;
options.hue = cal.find('div.colorpicker_hue div');
cal.find('div.colorpicker_hue').bind('mousedown', downHue);
options.newColor = cal.find('div.colorpicker_new_color');
options.currentColor = cal.find('div.colorpicker_current_color');
cal.data('colorpicker', options);
cal.find('div.colorpicker_submit')
.bind('mouseenter', enterSubmit)
.bind('mouseleave', leaveSubmit)
.bind('click', clickSubmit);
fillRGBFields(options.color, cal.get(0));
fillHSBFields(options.color, cal.get(0));
fillHexFields(options.color, cal.get(0));
setHue(options.color, cal.get(0));
setSelector(options.color, cal.get(0));
setCurrentColor(options.color, cal.get(0));
setNewColor(options.color, cal.get(0));
if (options.flat) {
cal.css({
position: 'relative',
display: 'block'
});
} else {
$(this).bind(options.eventName, show);
}
}
});
},
showPicker: function() {
return this.each( function () {
if ($(this).data('colorpickerId')) {
show.apply(this);
}
});
},
hidePicker: function() {
return this.each( function () {
if ($(this).data('colorpickerId')) {
$('#' + $(this).data('colorpickerId')).hide();
}
});
},
setColor: function(col) {
if (typeof col == 'string') {
col = HexToHSB(col);
} else if (col.r != undefined && col.g != undefined && col.b != undefined) {
col = RGBToHSB(col);
} else if (col.h != undefined && col.s != undefined && col.b != undefined) {
col = fixHSB(col);
} else {
return this;
}
return this.each(function(){
if ($(this).data('colorpickerId')) {
var cal = $('#' + $(this).data('colorpickerId'));
cal.data('colorpicker').color = col;
cal.data('colorpicker').origColor = col;
fillRGBFields(col, cal.get(0));
fillHSBFields(col, cal.get(0));
fillHexFields(col, cal.get(0));
setHue(col, cal.get(0));
setSelector(col, cal.get(0));
setCurrentColor(col, cal.get(0));
setNewColor(col, cal.get(0));
}
});
}
};
}();
$.fn.extend({
ColorPicker: ColorPicker.init,
ColorPickerHide: ColorPicker.hidePicker,
ColorPickerShow: ColorPicker.showPicker,
ColorPickerSetColor: ColorPicker.setColor
});
})(jQuery);
// jQuery Slider Plugin
// Egor Khmelev - http://blog.egorkhmelev.com/ - hmelyoff@gmail.com
(function(){
// Simple Inheritance
Function.prototype.inheritFrom = function(BaseClass, oOverride){
var Inheritance = function() {};
Inheritance.prototype = BaseClass.prototype;
this.prototype = new Inheritance();
this.prototype.constructor = this;
this.prototype.baseConstructor = BaseClass;
this.prototype.superClass = BaseClass.prototype;
if(oOverride){
for(var i in oOverride) {
this.prototype[i] = oOverride[i];
}
}
};
// Format numbers
Number.prototype.jSliderNice=function(iRoundBase){
var re=/^(-)?(\d+)([\.,](\d+))?$/;
var iNum=Number(this);
var sNum=String(iNum);
var aMatches;
var sDecPart='';
var sTSeparator=' ';
if((aMatches = sNum.match(re))){
var sIntPart=aMatches[2];
var iDecPart=(aMatches[4]) ? Number('0.'+aMatches[4]) : 0;
if(iDecPart){
var iRF=Math.pow(10, (iRoundBase) ? iRoundBase : 2);
iDecPart=Math.round(iDecPart*iRF);
sNewDecPart=String(iDecPart);
sDecPart = sNewDecPart;
if(sNewDecPart.length < iRoundBase){
var iDiff = iRoundBase-sNewDecPart.length;
for (var i=0; i < iDiff; i++) {
sDecPart = "0" + sDecPart;
};
}
sDecPart = "," + sDecPart;
} else {
if(iRoundBase && iRoundBase != 0){
for (var i=0; i < iRoundBase; i++) {
sDecPart += "0";
};
sDecPart = "," + sDecPart;
}
}
var sResult;
if(Number(sIntPart) < 1000){
sResult = sIntPart+sDecPart;
}else{
var sNewNum='';
var i;
for(i=1; i*3)[^\t]*)'/g, "$1\r")
.replace(/\t=(.*?)%>/g, "',$1,'")
.split("\t").join("');")
.split("%>").join("p.push('")
.split("\r").join("\\'")
+ "');}return p.join('');");
// Provide some basic currying to the user
return data ? fn( data ) : fn;
};
})();
// Draggable Class
// Egor Khmelev - http://blog.egorkhmelev.com/
(function( $ ){
this.Draggable = function(){
this._init.apply( this, arguments );
};
Draggable.prototype = {
// Methods for re-init in child class
oninit: function(){},
events: function(){},
onmousedown: function(){
this.ptr.css({ position: "absolute" });
},
onmousemove: function( evt, x, y ){
this.ptr.css({ left: x, top: y });
},
onmouseup: function(){},
isDefault: {
drag: false,
clicked: false,
toclick: true,
mouseup: false
},
_init: function(){
if( arguments.length > 0 ){
this.ptr = $(arguments[0]);
this.outer = $(".draggable-outer");
this.is = {};
$.extend( this.is, this.isDefault );
var _offset = this.ptr.offset();
this.d = {
left: _offset.left,
top: _offset.top,
width: this.ptr.width(),
height: this.ptr.height()
};
this.oninit.apply( this, arguments );
this._events();
}
},
_getPageCoords: function( event ){
if( event.targetTouches && event.targetTouches[0] ){
return { x: event.targetTouches[0].pageX, y: event.targetTouches[0].pageY };
} else
return { x: event.pageX, y: event.pageY };
},
_bindEvent: function( ptr, eventType, handler ){
var self = this;
if( this.supportTouches_ )
ptr.get(0).addEventListener( this.events_[ eventType ], handler, false );
else
ptr.bind( this.events_[ eventType ], handler );
},
_events: function(){
var self = this;
this.supportTouches_ = ( $.browser.webkit && navigator.userAgent.indexOf("Mobile") != -1 );
this.events_ = {
"click": this.supportTouches_ ? "touchstart" : "click",
"down": this.supportTouches_ ? "touchstart" : "mousedown",
"move": this.supportTouches_ ? "touchmove" : "mousemove",
"up" : this.supportTouches_ ? "touchend" : "mouseup"
};
this._bindEvent( $( document ), "move", function( event ){
if( self.is.drag ){
event.stopPropagation();
event.preventDefault();
self._mousemove( event );
}
});
this._bindEvent( $( document ), "down", function( event ){
if( self.is.drag ){
event.stopPropagation();
event.preventDefault();
}
});
this._bindEvent( $( document ), "up", function( event ){
self._mouseup( event );
});
this._bindEvent( this.ptr, "down", function( event ){
self._mousedown( event );
return false;
});
this._bindEvent( this.ptr, "up", function( event ){
self._mouseup( event );
});
this.ptr.find("a")
.click(function(){
self.is.clicked = true;
if( !self.is.toclick ){
self.is.toclick = true;
return false;
}
})
.mousedown(function( event ){
self._mousedown( event );
return false;
});
this.events();
},
_mousedown: function( evt ){
this.is.drag = true;
this.is.clicked = false;
this.is.mouseup = false;
var _offset = this.ptr.offset();
var coords = this._getPageCoords( evt );
this.cx = coords.x - _offset.left;
this.cy = coords.y - _offset.top;
$.extend(this.d, {
left: _offset.left,
top: _offset.top,
width: this.ptr.width(),
height: this.ptr.height()
});
if( this.outer && this.outer.get(0) ){
this.outer.css({ height: Math.max(this.outer.height(), $(document.body).height()), overflow: "hidden" });
}
this.onmousedown( evt );
},
_mousemove: function( evt ){
this.is.toclick = false;
var coords = this._getPageCoords( evt );
this.onmousemove( evt, coords.x - this.cx, coords.y - this.cy );
},
_mouseup: function( evt ){
var oThis = this;
if( this.is.drag ){
this.is.drag = false;
if( this.outer && this.outer.get(0) ){
if( $.browser.mozilla ){
this.outer.css({ overflow: "hidden" });
} else {
this.outer.css({ overflow: "visible" });
}
if( $.browser.msie && $.browser.version == '6.0' ){
this.outer.css({ height: "100%" });
} else {
this.outer.css({ height: "auto" });
}
}
this.onmouseup( evt );
}
}
};
})( jQuery );
// jQuery Slider (Safari)
// Egor Khmelev - http://blog.egorkhmelev.com/
(function( $ ) {
$.slider = function( node, settings ){
var jNode = $(node);
if( !jNode.data( "jslider" ) )
jNode.data( "jslider", new jSlider( node, settings ) );
return jNode.data( "jslider" );
};
$.fn.slider = function( action, opt_value ){
var returnValue, args = arguments;
function isDef( val ){
return val !== undefined;
};
function isDefAndNotNull( val ){
return val != null;
};
this.each(function(){
var self = $.slider( this, action );
// do actions
if( typeof action == "string" ){
switch( action ){
case "value":
if( isDef( args[ 1 ] ) && isDef( args[ 2 ] ) ){
var pointers = self.getPointers();
if( isDefAndNotNull( pointers[0] ) && isDefAndNotNull( args[1] ) ){
pointers[0].set( args[ 1 ] );
pointers[0].setIndexOver();
}
if( isDefAndNotNull( pointers[1] ) && isDefAndNotNull( args[2] ) ){
pointers[1].set( args[ 2 ] );
pointers[1].setIndexOver();
}
}
else if( isDef( args[ 1 ] ) ){
var pointers = self.getPointers();
if( isDefAndNotNull( pointers[0] ) && isDefAndNotNull( args[1] ) ){
pointers[0].set( args[ 1 ] );
pointers[0].setIndexOver();
}
}
else
returnValue = self.getValue();
break;
case "prc":
if( isDef( args[ 1 ] ) && isDef( args[ 2 ] ) ){
var pointers = self.getPointers();
if( isDefAndNotNull( pointers[0] ) && isDefAndNotNull( args[1] ) ){
pointers[0]._set( args[ 1 ] );
pointers[0].setIndexOver();
}
if( isDefAndNotNull( pointers[1] ) && isDefAndNotNull( args[2] ) ){
pointers[1]._set( args[ 2 ] );
pointers[1].setIndexOver();
}
}
else if( isDef( args[ 1 ] ) ){
var pointers = self.getPointers();
if( isDefAndNotNull( pointers[0] ) && isDefAndNotNull( args[1] ) ){
pointers[0]._set( args[ 1 ] );
pointers[0].setIndexOver();
}
}
else
returnValue = self.getPrcValue();
break;
case "calculatedValue":
var value = self.getValue().split(";");
returnValue = "";
for (var i=0; i < value.length; i++) {
returnValue += (i > 0 ? ";" : "") + self.nice( value[i] );
};
break;
case "skin":
self.setSkin( args[1] );
break;
};
}
// return actual object
else if( !action && !opt_value ){
if( !jSliderIsArray( returnValue ) )
returnValue = [];
returnValue.push( slider );
}
});
// flatten array just with one slider
if( jSliderIsArray( returnValue ) && returnValue.length == 1 )
returnValue = returnValue[ 0 ];
return returnValue || this;
};
var OPTIONS = {
settings: {
from: 1,
to: 10,
step: 1,
smooth: true,
limits: true,
round: 0,
value: "5;7",
dimension: ""
},
className: "jslider",
selector: ".jslider-",
template: jSliderTmpl(
'' +
'| ' +
' ' +
'' +
'' +
' ' +
' ' +
' ' +
'<%=settings.from%> ' +
'<%=settings.to%><%=settings.dimension%> ' +
'<%=settings.dimension%> ' +
'<%=settings.dimension%> ' +
'<%=scale%> '+
' |
' +
''
)
};
this.jSlider = function(){
return this.init.apply( this, arguments );
};
jSlider.prototype = {
init: function( node, settings ){
this.settings = $.extend(true, {}, OPTIONS.settings, settings ? settings : {});
// obj.sliderHandler = this;
this.inputNode = $( node ).hide();
this.settings.interval = this.settings.to-this.settings.from;
this.settings.value = this.inputNode.attr("value");
if( this.settings.calculate && $.isFunction( this.settings.calculate ) )
this.nice = this.settings.calculate;
if( this.settings.onstatechange && $.isFunction( this.settings.onstatechange ) )
this.onstatechange = this.settings.onstatechange;
this.is = {
init: false
};
this.o = {};
this.create();
},
onstatechange: function(){},
create: function(){
var $this = this;
this.domNode = $( OPTIONS.template({
className: OPTIONS.className,
settings: {
from: this.nice( this.settings.from ),
to: this.nice( this.settings.to ),
dimension: this.settings.dimension
},
scale: this.generateScale()
}) );
this.inputNode.after( this.domNode );
this.drawScale();
// set skin class
if( this.settings.skin && this.settings.skin.length > 0 )
this.setSkin( this.settings.skin );
this.sizes = {
domWidth: this.domNode.width(),
domOffset: this.domNode.offset()
};
// find some objects
$.extend(this.o, {
pointers: {},
labels: {
0: {
o: this.domNode.find(OPTIONS.selector + "value").not(OPTIONS.selector + "value-to")
},
1: {
o: this.domNode.find(OPTIONS.selector + "value").filter(OPTIONS.selector + "value-to")
}
},
limits: {
0: this.domNode.find(OPTIONS.selector + "label").not(OPTIONS.selector + "label-to"),
1: this.domNode.find(OPTIONS.selector + "label").filter(OPTIONS.selector + "label-to")
}
});
$.extend(this.o.labels[0], {
value: this.o.labels[0].o.find("span")
});
$.extend(this.o.labels[1], {
value: this.o.labels[1].o.find("span")
});
if( !$this.settings.value.split(";")[1] ){
this.settings.single = true;
this.domNode.addDependClass("single");
}
if( !$this.settings.limits )
this.domNode.addDependClass("limitless");
this.domNode.find(OPTIONS.selector + "pointer").each(function( i ){
var value = $this.settings.value.split(";")[i];
if( value ){
$this.o.pointers[i] = new jSliderPointer( this, i, $this );
var prev = $this.settings.value.split(";")[i-1];
if( prev && new Number(value) < new Number(prev) ) value = prev;
value = value < $this.settings.from ? $this.settings.from : value;
value = value > $this.settings.to ? $this.settings.to : value;
$this.o.pointers[i].set( value, true );
}
});
this.o.value = this.domNode.find(".v");
this.is.init = true;
$.each(this.o.pointers, function(i){
$this.redraw(this);
});
(function(self){
$(window).resize(function(){
self.onresize();
});
})(this);
},
setSkin: function( skin ){
if( this.skin_ )
this.domNode.removeDependClass( this.skin_, "_" );
this.domNode.addDependClass( this.skin_ = skin, "_" );
},
setPointersIndex: function( i ){
$.each(this.getPointers(), function(i){
this.index( i );
});
},
getPointers: function(){
return this.o.pointers;
},
generateScale: function(){
if( this.settings.scale && this.settings.scale.length > 0 ){
var str = "";
var s = this.settings.scale;
//var prc = Math.round((100/(s.length-1))*10)/10;
var prc = (((100/(s.length-1)))*10)/10; // Math.round() change
for( var i=0; i < s.length; i++ ){
str += '' + ( s[i] != '|' ? '' + s[i] + '' : '' ) + '';
};
return str;
} else return "";
return "";
},
drawScale: function(){
this.domNode.find(OPTIONS.selector + "scale span ins").each(function(){
$(this).css({ marginLeft: -$(this).outerWidth()/2 });
});
},
onresize: function(){
var self = this;
this.sizes = {
domWidth: this.domNode.width(),
domOffset: this.domNode.offset()
};
$.each(this.o.pointers, function(i){
self.redraw(this);
});
},
limits: function( x, pointer ){
// smooth
if( !this.settings.smooth ){
var step = this.settings.step*100 / ( this.settings.interval );
x = Math.round( x/step ) * step;
}
var another = this.o.pointers[1-pointer.uid];
if( another && pointer.uid && x < another.value.prc ) x = another.value.prc;
if( another && !pointer.uid && x > another.value.prc ) x = another.value.prc;
// base limit
if( x < 0 ) x = 0;
if( x > 100 ) x = 100;
return Math.round( x*10 ) / 10;
},
redraw: function( pointer ){
if( !this.is.init ) return false;
this.setValue();
// redraw range line
if( this.o.pointers[0] && this.o.pointers[1] )
this.o.value.css({ left: this.o.pointers[0].value.prc + "%", width: ( this.o.pointers[1].value.prc - this.o.pointers[0].value.prc ) + "%" });
this.o.labels[pointer.uid].value.html(
this.nice(
pointer.value.origin
)
);
// redraw position of labels
this.redrawLabels( pointer );
},
redrawLabels: function( pointer ){
function setPosition( label, sizes, prc ){
sizes.margin = -sizes.label/2;
// left limit
label_left = sizes.border + sizes.margin;
if( label_left < 0 )
sizes.margin -= label_left;
// right limit
if( sizes.border+sizes.label / 2 > self.sizes.domWidth ){
sizes.margin = 0;
sizes.right = true;
} else
sizes.right = false;
label.o.css({ left: prc + "%", marginLeft: sizes.margin, right: "auto" });
if( sizes.right ) label.o.css({ left: "auto", right: 0 });
return sizes;
}
var self = this;
var label = this.o.labels[pointer.uid];
var prc = pointer.value.prc;
var sizes = {
label: label.o.outerWidth(),
right: false,
border: ( prc * this.sizes.domWidth ) / 100
};
//console.log(this.o.pointers[1-pointer.uid])
if( !this.settings.single ){
// glue if near;
var another = this.o.pointers[1-pointer.uid];
var another_label = this.o.labels[another.uid];
switch( pointer.uid ){
case 0:
if( sizes.border+sizes.label / 2 > another_label.o.offset().left-this.sizes.domOffset.left ){
another_label.o.css({ visibility: "hidden" });
another_label.value.html( this.nice( another.value.origin ) );
label.o.css({ visibility: "visible" });
prc = ( another.value.prc - prc ) / 2 + prc;
if( another.value.prc != pointer.value.prc ){
label.value.html( this.nice(pointer.value.origin) + " – " + this.nice(another.value.origin) );
sizes.label = label.o.outerWidth();
sizes.border = ( prc * this.sizes.domWidth ) / 100;
}
} else {
another_label.o.css({ visibility: "visible" });
}
break;
case 1:
if( sizes.border - sizes.label / 2 < another_label.o.offset().left - this.sizes.domOffset.left + another_label.o.outerWidth() ){
another_label.o.css({ visibility: "hidden" });
another_label.value.html( this.nice(another.value.origin) );
label.o.css({ visibility: "visible" });
prc = ( prc - another.value.prc ) / 2 + another.value.prc;
if( another.value.prc != pointer.value.prc ){
label.value.html( this.nice(another.value.origin) + " – " + this.nice(pointer.value.origin) );
sizes.label = label.o.outerWidth();
sizes.border = ( prc * this.sizes.domWidth ) / 100;
}
} else {
another_label.o.css({ visibility: "visible" });
}
break;
}
}
sizes = setPosition( label, sizes, prc );
/* draw second label */
if( another_label ){
var sizes = {
label: another_label.o.outerWidth(),
right: false,
border: ( another.value.prc * this.sizes.domWidth ) / 100
};
sizes = setPosition( another_label, sizes, another.value.prc );
}
this.redrawLimits();
},
redrawLimits: function(){
if( this.settings.limits ){
var limits = [ true, true ];
for( key in this.o.pointers ){
if( !this.settings.single || key == 0 ){
var pointer = this.o.pointers[key];
var label = this.o.labels[pointer.uid];
var label_left = label.o.offset().left - this.sizes.domOffset.left;
var limit = this.o.limits[0];
if( label_left < limit.outerWidth() )
limits[0] = false;
var limit = this.o.limits[1];
if( label_left + label.o.outerWidth() > this.sizes.domWidth - limit.outerWidth() )
limits[1] = false;
}
};
for( var i=0; i < limits.length; i++ ){
if( limits[i] )
this.o.limits[i].fadeIn("fast");
else
this.o.limits[i].fadeOut("fast");
};
}
},
setValue: function(){
var value = this.getValue();
this.inputNode.attr( "value", value );
this.onstatechange.call( this, value );
},
getValue: function(){
if(!this.is.init) return false;
var $this = this;
var value = "";
$.each( this.o.pointers, function(i){
if( this.value.prc != undefined && !isNaN(this.value.prc) ) value += (i > 0 ? ";" : "") + $this.prcToValue( this.value.prc );
});
return value;
},
getPrcValue: function(){
if(!this.is.init) return false;
var $this = this;
var value = "";
$.each( this.o.pointers, function(i){
if( this.value.prc != undefined && !isNaN(this.value.prc) ) value += (i > 0 ? ";" : "") + this.value.prc;
});
return value;
},
prcToValue: function( prc ){
if( this.settings.heterogeneity && this.settings.heterogeneity.length > 0 ){
var h = this.settings.heterogeneity;
var _start = 0;
var _from = this.settings.from;
for( var i=0; i <= h.length; i++ ){
if( h[i] ) var v = h[i].split("/");
else var v = [100, this.settings.to];
v[0] = new Number(v[0]);
v[1] = new Number(v[1]);
if( prc >= _start && prc <= v[0] ) {
var value = _from + ( (prc-_start) * (v[1]-_from) ) / (v[0]-_start);
}
_start = v[0];
_from = v[1];
};
} else {
var value = this.settings.from + ( prc * this.settings.interval ) / 100;
}
return this.round( value );
},
valueToPrc: function( value, pointer ){
if( this.settings.heterogeneity && this.settings.heterogeneity.length > 0 ){
var h = this.settings.heterogeneity;
var _start = 0;
var _from = this.settings.from;
for (var i=0; i <= h.length; i++) {
if(h[i]) var v = h[i].split("/");
else var v = [100, this.settings.to];
v[0] = new Number(v[0]); v[1] = new Number(v[1]);
if(value >= _from && value <= v[1]){
var prc = pointer.limits(_start + (value-_from)*(v[0]-_start)/(v[1]-_from));
}
_start = v[0]; _from = v[1];
};
} else {
var prc = pointer.limits((value-this.settings.from)*100/this.settings.interval);
}
return prc;
},
round: function( value ){
value = Math.round( value / this.settings.step ) * this.settings.step;
if( this.settings.round ) value = Math.round( value * Math.pow(10, this.settings.round) ) / Math.pow(10, this.settings.round);
else value = Math.round( value );
return value;
},
nice: function( value ){
value = value.toString().replace(/,/gi, ".");
value = value.toString().replace(/ /gi, "");
if( Number.prototype.jSliderNice )
return (new Number(value)).jSliderNice(this.settings.round).replace(/-/gi, "−");
else
return new Number(value);
}
};
function jSliderPointer(){
this.baseConstructor.apply(this, arguments);
}
jSliderPointer.inheritFrom(Draggable, {
oninit: function( ptr, id, _constructor ){
this.uid = id;
this.parent = _constructor;
this.value = {};
this.settings = this.parent.settings;
},
onmousedown: function(evt){
this._parent = {
offset: this.parent.domNode.offset(),
width: this.parent.domNode.width()
};
this.ptr.addDependClass("hover");
this.setIndexOver();
},
onmousemove: function( evt, x ){
var coords = this._getPageCoords( evt );
this._set( this.calc( coords.x ) );
},
onmouseup: function( evt ){
// var coords = this._getPageCoords( evt );
// this._set( this.calc( coords.x ) );
if( this.parent.settings.callback && $.isFunction(this.parent.settings.callback) )
this.parent.settings.callback.call( this.parent, this.parent.getValue() );
this.ptr.removeDependClass("hover");
},
setIndexOver: function(){
this.parent.setPointersIndex( 1 );
this.index( 2 );
},
index: function( i ){
this.ptr.css({ zIndex: i });
},
limits: function( x ){
return this.parent.limits( x, this );
},
calc: function(coords){
var x = this.limits(((coords-this._parent.offset.left)*100)/this._parent.width);
return x;
},
set: function( value, opt_origin ){
this.value.origin = this.parent.round(value);
this._set( this.parent.valueToPrc( value, this ), opt_origin );
},
_set: function( prc, opt_origin ){
if( !opt_origin )
this.value.origin = this.parent.prcToValue(prc);
this.value.prc = prc;
this.ptr.css({ left: prc + "%" });
this.parent.redraw(this);
}
});
})(jQuery);
/* end */
/*
* Depend Class v0.1b : attach class based on first class in list of current element
* File: jquery.dependClass.js
* Copyright (c) 2009 Egor Hmelyoff, hmelyoff@gmail.com
*/
(function($) {
// Init plugin function
$.baseClass = function(obj){
obj = $(obj);
return obj.get(0).className.match(/([^ ]+)/)[1];
};
$.fn.addDependClass = function(className, delimiter){
var options = {
delimiter: delimiter ? delimiter : '-'
}
return this.each(function(){
var baseClass = $.baseClass(this);
if(baseClass)
$(this).addClass(baseClass + options.delimiter + className);
});
};
$.fn.removeDependClass = function(className, delimiter){
var options = {
delimiter: delimiter ? delimiter : '-'
}
return this.each(function(){
var baseClass = $.baseClass(this);
if(baseClass)
$(this).removeClass(baseClass + options.delimiter + className);
});
};
$.fn.toggleDependClass = function(className, delimiter){
var options = {
delimiter: delimiter ? delimiter : '-'
}
return this.each(function(){
var baseClass = $.baseClass(this);
if(baseClass)
if($(this).is("." + baseClass + options.delimiter + className))
$(this).removeClass(baseClass + options.delimiter + className);
else
$(this).addClass(baseClass + options.delimiter + className);
});
};
// end of closure
})(jQuery);