(function($) {
$.fn.extend({
pureAjax: function(options) {
var defaults = {
urlAppend: "&tx_pure_pi[ajax_request_id]=",
urlAppendIdSelecetor: "",
urlAppendUserClick: "&tx_pure_pi[userclick]=true",
urlAppendCookieClick: "&tx_pure_pi[userclick]=false",
aSelector: ".pure-ajax-request a, a.ajax_request",
resultPageSelector: ".pure-result-page, .pure-tabs-contents",
resultSelector: ".pure-result",
loader: ".pure_loading",
succesFunc: function(loadedContent) {}
};
var opts = $.extend({},defaults, options);
//Iterate over the current set of matched elements
return this.each(function() {
var obj = $(this);
var anchors= $(opts.aSelector, obj);
//Unbind and bind to click event
anchors.unbind("click.pureAjax");
anchors.bind('click.pureAjax', function(event) {
//Find closest resultPage
var resultPage = $(this).closest(opts.resultPageSelector);
//Find the id, for this page.
var id = resultPage.attr("id");
if (id)
id = id.substring(1);
else
id = "1:1";
var result;
if (typeof opts.resultSelector == "string")
result = $(opts.resultSelector, resultPage);
else if (typeof opts.resultSelector == "object")
{
result = opts.resultSelector;
}
var loader = $(opts.loader, resultPage);
//Show loader and hide if any content showed.
result.slideUp("normal");
loader.stop(true, true).slideDown("normal");
//Load content.
var xhr = $.ajax({
url: this.href
+ (this.href.indexOf("?") > -1 ? "" : "?")
+ opts.urlAppend + id + "&type=5055&cid=" + parseInt(id) + (typeof event.which == "undefined" ? opts.urlAppendCookieClick : opts.urlAppendUserClick),
cache: true,
success: function(html) {
result.hide().html(html).slideDown("normal");
loader.slideUp("normal");
if (typeof opts.succesFunc == "function")
opts.succesFunc(result);
}
});
//Add the xhr to data for the result, so it can be cancelled by other.
$.data(resultPage.get(0), "pure-page-xhr", xhr);
//Handle click event
if (event.which && event.which != 1) {
return true;
}
event.preventDefault();
return false;
});
});
},
pureTabs: function(options) {
//Set the default values
var defaults = {
urlAppend: "&tx_pure_pi[ajax_request_id]=1:1",
urlAppendUserClick: "&tx_pure_pi[userclick]=true",
urlAppendCookieClick: "&tx_pure_pi[userclick]=false",
cookieName: 'au_pure_tabs_',
succesFunc: function(loadedtab){},
loader: $(".pure_loading:first") //Find a element to use.
};
var opts = $.extend({},defaults, options);
function abort(xhr)
{
// terminate pending requests from other tabs
if (xhr) {
xhr.abort();
delete xhr;
}
}
//Iterate over the current set of matched elements
var objs = this;
return this.each(function() {
var obj = $(this);
//Index of this tabs.
var index = $(objs).index(obj);
//All the tabs:
var tabs = $(".pure-tabs-ul li a.pure-tab", obj);
//Add hover events.
$(".pure-tabs-ul li", obj).hover(
function() {
$(this).addClass("pure-tabs-hover");
},
function() {
$(this).removeClass("pure-tabs-hover");
}
);
var loaderObj;
if (typeof opts.loader == "string")
loaderObj = obj.closest(opts.loader);//$(opts.loader, obj);
else if (typeof opts.loader == "object")
loaderObj = opts.loader.clone();
loaderObj = loaderObj.stop(true, true).hide();
//Add tab elements
obj.append('
');
var tabContainer = $("div.pure-tabs-contents", obj);
tabContainer.append(loaderObj);
tabs.each(function() {
var el;
//Find id="#id" tabs with are corresponding div element.
var idIndex = $(this).attr("href").indexOf("#");
if ( idIndex > -1 && $($(this).attr("href").substring(idIndex), obj).size() > 0)
{
el = $('');
$(el).append($($(this).attr("href").substring(idIndex), obj));
}
else
el = $('');
tabContainer.append(el.show());
});
//The tab holders
var tabContents = $(".pure-tabs-contents div.pure-tabs-result", obj);
tabContents.hide();
var selected = -1;
tabs.unbind('click.pureTabs');
tabs.bind('click.pureTabs', function(event) {
//Reset all tabs
tabs.closest("li").removeClass("pure-tabs-selected");
//Abort the current xhr for this page
var xhr = $.data(tabContainer.get(0), "pure-page-xhr");
abort(xhr);
var current = tabs.index($(this));
if (current != selected) {
//Set selected tab
selected = current;
$(this).closest("li").addClass("pure-tabs-selected");
//Trigger ajax if there is no cached.
if (!tabContents.eq(current).hasClass("pure-loaded"))
{
//Stop all running animations
tabContents.slideUp("normal");
loaderObj.stop(true,true).slideDown("normal");
//Load content.
var xhr = $.ajax({
url: this.href
+ (this.href.indexOf("?") > -1 ? "" : "?")
+ opts.urlAppend
+ (typeof event.which == "undefined" ? opts.urlAppendCookieClick : opts.urlAppendUserClick),
cache: true,
success: function(html) {
$(".pure-result",tabContents.eq(current)).html(html);
tabContents.eq(current).slideDown("normal");
loaderObj.stop(true, true).slideUp("normal");
if (typeof opts.succesFunc == "function")
opts.succesFunc(tabContents.eq(current));
tabContents.eq(current).addClass("pure-loaded");
}
});
//Set the xhr for this page.
$.data(tabContainer.get(0), "pure-page-xhr", xhr);
}
else
{
loaderObj.stop(true, true).hide();
//tabContents.hide();
//tabContents.eq(current).show();
tabContents.slideUp("normal");
tabContents.eq(current).slideDown("normal");
}
//Save cookie
var cookieOptions = { expires: 30, path: window.location.pathname };
jQuery.cookie(opts.cookieName + index, current, cookieOptions);
}
else {
//Stop all running animations and run to end.
tabContents.stop(true, true);
tabContents.eq(current).slideUp("normal");
loaderObj.stop(true,true).slideUp("normal");
selected = -1;
//Remove cookie
var cookieOptions = { expires: -1, path: window.location.pathname };
jQuery.cookie(opts.cookieName + index, null, cookieOptions);
}
//Handle click event
if (event.which && event.which != 1) {
return true;
}
event.preventDefault();
return false;
});
//Get selected from cookie if any, and trigger click
var cokSel = $.cookie(opts.cookieName + index);
if (cokSel) //Trigger click event for loading.
tabs.eq(cokSel).trigger('click');
else if (obj.hasClass("pure-tabs-foldOutFirst"))
tabs.eq(0).trigger('click');
else //Open tabs that want to be open.
$(".pure-tab-open").trigger('click');
});
}
});
$(document).ready(function() {
var tablesorterOptions = {widgets: ['zebra']};
//testing new plugin.
var tabOptions = {succesFunc: function(loadedtab){
var ajaxOp = {
succesFunc: function(loadedPage){
loadedPage.pureAjax(ajaxOp);
$(".pure-tabs", loadedPage).pureTabs(tabOptions);
},
resultSelector: loadedtab
};
$(loadedtab).pureAjax(ajaxOp);
}};
var ajaxOptions = {succesFunc: function(loadedPage){
loadedPage.pureAjax(ajaxOptions);
$(".pure-tabs", loadedPage).pureTabs(tabOptions);
$(".pure-persons-table", loadedPage).tablesorter(tablesorterOptions);
}
};
// Dycon disabled in .min.js by adding -dycon to selctor: $(".tx-pure-pi-dycon").pureAjax(ajaxOptions);
$(".pure-tabs").pureTabs(tabOptions);
$(".pure-persons-table").tablesorter(tablesorterOptions);
//Auto load content:
$(".tx-pure-pi a.ajax_request").trigger("click");
//Search settings - show or hide
$(".pure_search_form").each(function() {
var thisSearch = this;
$(".pure-search-settings", thisSearch).hide();
$(".pure-show-search-settings", thisSearch).show();
$(".pure-show-search-settings a, .pure-hide-search-settings a", thisSearch).click(function() {
$(".pure-show-search-settings, .pure-hide-search-settings, .pure-search-settings", thisSearch).toggle();
return false;
});
});
//Sorting toogle.
$(".tx-pure-sorting-body").hide();
$("#au_content").on("click", ".tx-pure-sorting-head", function()
{
$(this).next(".tx-pure-sorting-body").toggle();
});
//Resize image to fill the containing box.
$(".pure-image-person a img").cjObjectScaler({
destObj: $(".pure-image-person a img").parent("a"), //The object to resize after.
method: "fill" // Fill the destination object. Will crop image.
});
//Remove the max-width/height from the images
$(".pure-image-person a img").css("min-height", "100%");
$(".pure-image-person a img").css("max-width", "100%");
});
})(jQuery);
/**
* Cookie plugin
*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
/**
* Create a cookie with the given name and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
* used when the cookie was set.
*
* @param String name The name of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in minutes or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
/**
* Get the value of a cookie with the given name.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String name The name of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
(function($) {
$.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = $.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
})(jQuery);
/*
*
* TableSorter 2.0 - Client-side table sorting with ease!
* Version 2.0.3
* @requires jQuery v1.2.3
*
* Copyright (c) 2007 Christian Bach
* Examples and docs at: http://tablesorter.com
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
/**
*
* @description Create a sortable table with multi-column sorting capabilitys
*
* @example $('table').tablesorter();
* @desc Create a simple tablesorter interface.
*
* @example $('table').tablesorter({ sortList:[[0,0],[1,0]] });
* @desc Create a tablesorter interface and sort on the first and secound column in ascending order.
*
* @example $('table').tablesorter({ headers: { 0: { sorter: false}, 1: {sorter: false} } });
* @desc Create a tablesorter interface and disableing the first and secound column headers.
*
* @example $('table').tablesorter({ 0: {sorter:"integer"}, 1: {sorter:"currency"} });
* @desc Create a tablesorter interface and set a column parser for the first and secound column.
*
*
* @param Object settings An object literal containing key/value pairs to provide optional settings.
*
* @option String cssHeader (optional) A string of the class name to be appended to sortable tr elements in the thead of the table.
* Default value: "header"
*
* @option String cssAsc (optional) A string of the class name to be appended to sortable tr elements in the thead on a ascending sort.
* Default value: "headerSortUp"
*
* @option String cssDesc (optional) A string of the class name to be appended to sortable tr elements in the thead on a descending sort.
* Default value: "headerSortDown"
*
* @option String sortInitialOrder (optional) A string of the inital sorting order can be asc or desc.
* Default value: "asc"
*
* @option String sortMultisortKey (optional) A string of the multi-column sort key.
* Default value: "shiftKey"
*
* @option String textExtraction (optional) A string of the text-extraction method to use.
* For complex html structures inside td cell set this option to "complex",
* on large tables the complex option can be slow.
* Default value: "simple"
*
* @option Object headers (optional) An array containing the forces sorting rules.
* This option let's you specify a default sorting rule.
* Default value: null
*
* @option Array sortList (optional) An array containing the forces sorting rules.
* This option let's you specify a default sorting rule.
* Default value: null
*
* @option Array sortForce (optional) An array containing forced sorting rules.
* This option let's you specify a default sorting rule, which is prepended to user-selected rules.
* Default value: null
*
* @option Array sortAppend (optional) An array containing forced sorting rules.
* This option let's you specify a default sorting rule, which is appended to user-selected rules.
* Default value: null
*
* @option Boolean widthFixed (optional) Boolean flag indicating if tablesorter should apply fixed widths to the table columns.
* This is usefull when using the pager companion plugin.
* This options requires the dimension jquery plugin.
* Default value: false
*
* @option Boolean cancelSelection (optional) Boolean flag indicating if tablesorter should cancel selection of the table headers text.
* Default value: true
*
* @option Boolean debug (optional) Boolean flag indicating if tablesorter should display debuging information usefull for development.
*
* @type jQuery
*
* @name tablesorter
*
* @cat Plugins/Tablesorter
*
* @author Christian Bach/christian.bach@polyester.se
*/
(function($) {
$.extend({
tablesorter: new function() {
var parsers = [], widgets = [];
this.defaults = {
cssHeader: "header",
cssAsc: "headerSortUp",
cssDesc: "headerSortDown",
sortInitialOrder: "asc",
sortMultiSortKey: "shiftKey",
sortForce: null,
sortAppend: null,
textExtraction: "simple",
parsers: {},
widgets: [],
widgetZebra: {css: ["even","odd"]},
headers: {},
widthFixed: false,
cancelSelection: true,
sortList: [],
headerList: [],
dateFormat: "us",
decimal: '.',
debug: false
};
/* debuging utils */
function benchmark(s,d) {
log(s + "," + (new Date().getTime() - d.getTime()) + "ms");
}
this.benchmark = benchmark;
function log(s) {
if (typeof console != "undefined" && typeof console.debug != "undefined") {
console.log(s);
} else {
alert(s);
}
}
/* parsers utils */
function buildParserCache(table,$headers) {
if(table.config.debug) { var parsersDebug = ""; }
var rows = table.tBodies[0].rows;
if(table.tBodies[0].rows[0]) {
var list = [], cells = rows[0].cells, l = cells.length;
for (var i=0;i < l; i++) {
var p = false;
if($.metadata && ($($headers[i]).metadata() && $($headers[i]).metadata().sorter) ) {
p = getParserById($($headers[i]).metadata().sorter);
} else if((table.config.headers[i] && table.config.headers[i].sorter)) {
p = getParserById(table.config.headers[i].sorter);
}
if(!p) {
p = detectParserForColumn(table,cells[i]);
}
if(table.config.debug) { parsersDebug += "column:" + i + " parser:" +p.id + "\n"; }
list.push(p);
}
}
if(table.config.debug) { log(parsersDebug); }
return list;
};
function detectParserForColumn(table,node) {
var l = parsers.length;
for(var i=1; i < l; i++) {
if(parsers[i].is($.trim(getElementText(table.config,node)),table,node)) {
return parsers[i];
}
}
// 0 is always the generic parser (text)
return parsers[0];
}
function getParserById(name) {
var l = parsers.length;
for(var i=0; i < l; i++) {
if(parsers[i].id.toLowerCase() == name.toLowerCase()) {
return parsers[i];
}
}
return false;
}
/* utils */
function buildCache(table) {
if(table.config.debug) { var cacheTime = new Date(); }
var totalRows = (table.tBodies[0] && table.tBodies[0].rows.length) || 0,
totalCells = (table.tBodies[0].rows[0] && table.tBodies[0].rows[0].cells.length) || 0,
parsers = table.config.parsers,
cache = {row: [], normalized: []};
for (var i=0;i < totalRows; ++i) {
/** Add the table data to main data array */
var c = table.tBodies[0].rows[i], cols = [];
cache.row.push($(c));
for(var j=0; j < totalCells; ++j) {
cols.push(parsers[j].format(getElementText(table.config,c.cells[j]),table,c.cells[j]));
}
cols.push(i); // add position for rowCache
cache.normalized.push(cols);
cols = null;
};
if(table.config.debug) { benchmark("Building cache for " + totalRows + " rows:", cacheTime); }
return cache;
};
function getElementText(config,node) {
if(!node) return "";
var t = "";
if(config.textExtraction == "simple") {
if(node.childNodes[0] && node.childNodes[0].hasChildNodes()) {
t = node.childNodes[0].innerHTML;
} else {
t = node.innerHTML;
}
} else {
if(typeof(config.textExtraction) == "function") {
t = config.textExtraction(node);
} else {
t = $(node).text();
}
}
return t;
}
function appendToTable(table,cache) {
if(table.config.debug) {var appendTime = new Date()}
var c = cache,
r = c.row,
n= c.normalized,
totalRows = n.length,
checkCell = (n[0].length-1),
tableBody = $(table.tBodies[0]),
rows = [];
for (var i=0;i < totalRows; i++) {
rows.push(r[n[i][checkCell]]);
if(!table.config.appender) {
var o = r[n[i][checkCell]];
var l = o.length;
for(var j=0; j < l; j++) {
tableBody[0].appendChild(o[j]);
}
//tableBody.append(r[n[i][checkCell]]);
}
}
if(table.config.appender) {
table.config.appender(table,rows);
}
rows = null;
if(table.config.debug) { benchmark("Rebuilt table:", appendTime); }
//apply table widgets
applyWidget(table);
// trigger sortend
setTimeout(function() {
$(table).trigger("sortEnd");
},0);
};
function buildHeaders(table) {
if(table.config.debug) { var time = new Date(); }
var meta = ($.metadata) ? true : false, tableHeadersRows = [];
for(var i = 0; i < table.tHead.rows.length; i++) { tableHeadersRows[i]=0; };
$tableHeaders = $("thead th",table);
$tableHeaders.each(function(index) {
this.count = 0;
this.column = index;
this.order = formatSortingOrder(table.config.sortInitialOrder);
if(checkHeaderMetadata(this) || checkHeaderOptions(table,index)) this.sortDisabled = true;
if(!this.sortDisabled) {
$(this).addClass(table.config.cssHeader);
}
// add cell to headerList
table.config.headerList[index]= this;
});
if(table.config.debug) { benchmark("Built headers:", time); log($tableHeaders); }
return $tableHeaders;
};
function checkCellColSpan(table, rows, row) {
var arr = [], r = table.tHead.rows, c = r[row].cells;
for(var i=0; i < c.length; i++) {
var cell = c[i];
if ( cell.colSpan > 1) {
arr = arr.concat(checkCellColSpan(table, headerArr,row++));
} else {
if(table.tHead.length == 1 || (cell.rowSpan > 1 || !r[row+1])) {
arr.push(cell);
}
//headerArr[row] = (i+row);
}
}
return arr;
};
function checkHeaderMetadata(cell) {
if(($.metadata) && ($(cell).metadata().sorter === false)) { return true; };
return false;
}
function checkHeaderOptions(table,i) {
if((table.config.headers[i]) && (table.config.headers[i].sorter === false)) { return true; };
return false;
}
function applyWidget(table) {
var c = table.config.widgets;
var l = c.length;
for(var i=0; i < l; i++) {
getWidgetById(c[i]).format(table);
}
}
function getWidgetById(name) {
var l = widgets.length;
for(var i=0; i < l; i++) {
if(widgets[i].id.toLowerCase() == name.toLowerCase() ) {
return widgets[i];
}
}
};
function formatSortingOrder(v) {
if(typeof(v) != "Number") {
i = (v.toLowerCase() == "desc") ? 1 : 0;
} else {
i = (v == (0 || 1)) ? v : 0;
}
return i;
}
function isValueInArray(v, a) {
var l = a.length;
for(var i=0; i < l; i++) {
if(a[i][0] == v) {
return true;
}
}
return false;
}
function setHeadersCss(table,$headers, list, css) {
// remove all header information
$headers.removeClass(css[0]).removeClass(css[1]);
var h = [];
$headers.each(function(offset) {
if(!this.sortDisabled) {
h[this.column] = $(this);
}
});
var l = list.length;
for(var i=0; i < l; i++) {
h[list[i][0]].addClass(css[list[i][1]]);
}
}
function fixColumnWidth(table,$headers) {
var c = table.config;
if(c.widthFixed) {
var colgroup = $('');
$("tr:first td",table.tBodies[0]).each(function() {
colgroup.append($('').css('width',$(this).width()));
});
$(table).prepend(colgroup);
};
}
function updateHeaderSortCount(table,sortList) {
var c = table.config, l = sortList.length;
for(var i=0; i < l; i++) {
var s = sortList[i], o = c.headerList[s[0]];
o.count = s[1];
o.count++;
}
}
/* sorting methods */
function multisort(table,sortList,cache) {
if(table.config.debug) { var sortTime = new Date(); }
var dynamicExp = "var sortWrapper = function(a,b) {", l = sortList.length;
for(var i=0; i < l; i++) {
var c = sortList[i][0];
var order = sortList[i][1];
var s = (getCachedSortType(table.config.parsers,c) == "text") ? ((order == 0) ? "sortText" : "sortTextDesc") : ((order == 0) ? "sortNumeric" : "sortNumericDesc");
var e = "e" + i;
dynamicExp += "var " + e + " = " + s + "(a[" + c + "],b[" + c + "]); ";
dynamicExp += "if(" + e + ") { return " + e + "; } ";
dynamicExp += "else { ";
}
// if value is the same keep orignal order
var orgOrderCol = cache.normalized[0].length - 1;
dynamicExp += "return a[" + orgOrderCol + "]-b[" + orgOrderCol + "];";
for(var i=0; i < l; i++) {
dynamicExp += "}; ";
}
dynamicExp += "return 0; ";
dynamicExp += "}; ";
eval(dynamicExp);
cache.normalized.sort(sortWrapper);
if(table.config.debug) { benchmark("Sorting on " + sortList.toString() + " and dir " + order+ " time:", sortTime); }
return cache;
};
function sortText(a,b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
};
function sortTextDesc(a,b) {
return ((b < a) ? -1 : ((b > a) ? 1 : 0));
};
function sortNumeric(a,b) {
return a-b;
};
function sortNumericDesc(a,b) {
return b-a;
};
function getCachedSortType(parsers,i) {
return parsers[i].type;
};
/* public methods */
this.construct = function(settings) {
return this.each(function() {
if(!this.tHead || !this.tBodies) return;
var $this, $document,$headers, cache, config, shiftDown = 0, sortOrder;
this.config = {};
config = $.extend(this.config, $.tablesorter.defaults, settings);
// store common expression for speed
$this = $(this);
// build headers
$headers = buildHeaders(this);
// try to auto detect column type, and store in tables config
this.config.parsers = buildParserCache(this,$headers);
// build the cache for the tbody cells
cache = buildCache(this);
// get the css class names, could be done else where.
var sortCSS = [config.cssDesc,config.cssAsc];
// fixate columns if the users supplies the fixedWidth option
fixColumnWidth(this);
// apply event handling to headers
// this is to big, perhaps break it out?
$headers.click(function(e) {
$this.trigger("sortStart");
var totalRows = ($this[0].tBodies[0] && $this[0].tBodies[0].rows.length) || 0;
if(!this.sortDisabled && totalRows > 0) {
// store exp, for speed
var $cell = $(this);
// get current column index
var i = this.column;
// get current column sort order
this.order = this.count++ % 2;
// user only whants to sort on one column
if(!e[config.sortMultiSortKey]) {
// flush the sort list
config.sortList = [];
if(config.sortForce != null) {
var a = config.sortForce;
for(var j=0; j < a.length; j++) {
if(a[j][0] != i) {
config.sortList.push(a[j]);
}
}
}
// add column to sort list
config.sortList.push([i,this.order]);
// multi column sorting
} else {
// the user has clicked on an all ready sortet column.
if(isValueInArray(i,config.sortList)) {
// revers the sorting direction for all tables.
for(var j=0; j < config.sortList.length; j++) {
var s = config.sortList[j], o = config.headerList[s[0]];
if(s[0] == i) {
o.count = s[1];
o.count++;
s[1] = o.count % 2;
}
}
} else {
// add column to sort list array
config.sortList.push([i,this.order]);
}
};
setTimeout(function() {
//set css for headers
setHeadersCss($this[0],$headers,config.sortList,sortCSS);
appendToTable($this[0],multisort($this[0],config.sortList,cache));
},1);
// stop normal event by returning false
return false;
}
// cancel selection
}).mousedown(function() {
if(config.cancelSelection) {
this.onselectstart = function() {return false};
return false;
}
});
// apply easy methods that trigger binded events
$this.bind("update",function() {
// rebuild parsers.
this.config.parsers = buildParserCache(this,$headers);
// rebuild the cache map
cache = buildCache(this);
}).bind("sorton",function(e,list) {
$(this).trigger("sortStart");
config.sortList = list;
// update and store the sortlist
var sortList = config.sortList;
// update header count index
updateHeaderSortCount(this,sortList);
//set css for headers
setHeadersCss(this,$headers,sortList,sortCSS);
// sort the table and append it to the dom
appendToTable(this,multisort(this,sortList,cache));
}).bind("appendCache",function() {
appendToTable(this,cache);
}).bind("applyWidgetId",function(e,id) {
getWidgetById(id).format(this);
}).bind("applyWidgets",function() {
// apply widgets
applyWidget(this);
});
if($.metadata && ($(this).metadata() && $(this).metadata().sortlist)) {
config.sortList = $(this).metadata().sortlist;
}
// if user has supplied a sort list to constructor.
if(config.sortList.length > 0) {
$this.trigger("sorton",[config.sortList]);
}
// apply widgets
applyWidget(this);
});
};
this.addParser = function(parser) {
var l = parsers.length, a = true;
for(var i=0; i < l; i++) {
if(parsers[i].id.toLowerCase() == parser.id.toLowerCase()) {
a = false;
}
}
if(a) { parsers.push(parser); };
};
this.addWidget = function(widget) {
widgets.push(widget);
};
this.formatFloat = function(s) {
var i = parseFloat(s);
return (isNaN(i)) ? 0 : i;
};
this.formatInt = function(s) {
var i = parseInt(s);
return (isNaN(i)) ? 0 : i;
};
this.isDigit = function(s,config) {
var DECIMAL = '\\' + config.decimal;
var exp = '/(^[+]?0(' + DECIMAL +'0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)' + DECIMAL +'(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*' + DECIMAL +'0+$)/';
return RegExp(exp).test($.trim(s));
};
this.clearTableBody = function(table) {
if($.browser.msie) {
function empty() {
while ( this.firstChild ) this.removeChild( this.firstChild );
}
empty.apply(table.tBodies[0]);
} else {
table.tBodies[0].innerHTML = "";
}
};
}
});
// extend plugin scope
$.fn.extend({
tablesorter: $.tablesorter.construct
});
var ts = $.tablesorter;
// add default parsers
ts.addParser({
id: "text",
is: function(s) {
return true;
},
format: function(s) {
return $.trim(s.toLowerCase());
},
type: "text"
});
ts.addParser({
id: "digit",
is: function(s,table) {
var c = table.config;
return $.tablesorter.isDigit(s,c);
},
format: function(s) {
return $.tablesorter.formatFloat(s);
},
type: "numeric"
});
ts.addParser({
id: "currency",
is: function(s) {
return /^[£$€?.]/.test(s);
},
format: function(s) {
return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g),""));
},
type: "numeric"
});
ts.addParser({
id: "ipAddress",
is: function(s) {
return /^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(s);
},
format: function(s) {
var a = s.split("."), r = "", l = a.length;
for(var i = 0; i < l; i++) {
var item = a[i];
if(item.length == 2) {
r += "0" + item;
} else {
r += item;
}
}
return $.tablesorter.formatFloat(r);
},
type: "numeric"
});
ts.addParser({
id: "url",
is: function(s) {
return /^(https?|ftp|file):\/\/$/.test(s);
},
format: function(s) {
return jQuery.trim(s.replace(new RegExp(/(https?|ftp|file):\/\//),''));
},
type: "text"
});
ts.addParser({
id: "isoDate",
is: function(s) {
return /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(s);
},
format: function(s) {
return $.tablesorter.formatFloat((s != "") ? new Date(s.replace(new RegExp(/-/g),"/")).getTime() : "0");
},
type: "numeric"
});
ts.addParser({
id: "percent",
is: function(s) {
return /\%$/.test($.trim(s));
},
format: function(s) {
return $.tablesorter.formatFloat(s.replace(new RegExp(/%/g),""));
},
type: "numeric"
});
ts.addParser({
id: "usLongDate",
is: function(s) {
return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/));
},
format: function(s) {
return $.tablesorter.formatFloat(new Date(s).getTime());
},
type: "numeric"
});
ts.addParser({
id: "shortDate",
is: function(s) {
return /\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);
},
format: function(s,table) {
var c = table.config;
s = s.replace(/\-/g,"/");
if(c.dateFormat == "us") {
// reformat the string in ISO format
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$1/$2");
} else if(c.dateFormat == "uk") {
//reformat the string in ISO format
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
} else if(c.dateFormat == "dd/mm/yy" || c.dateFormat == "dd-mm-yy") {
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, "$1/$2/$3");
}
return $.tablesorter.formatFloat(new Date(s).getTime());
},
type: "numeric"
});
ts.addParser({
id: "time",
is: function(s) {
return /^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(s);
},
format: function(s) {
return $.tablesorter.formatFloat(new Date("2000/01/01 " + s).getTime());
},
type: "numeric"
});
ts.addParser({
id: "metadata",
is: function(s) {
return false;
},
format: function(s,table,cell) {
var c = table.config, p = (!c.parserMetadataName) ? 'sortValue' : c.parserMetadataName;
return $(cell).metadata()[p];
},
type: "numeric"
});
// add default widgets
ts.addWidget({
id: "zebra",
format: function(table) {
if(table.config.debug) { var time = new Date(); }
$("tr:visible",table.tBodies[0])
.filter(':even')
.removeClass(table.config.widgetZebra.css[1]).addClass(table.config.widgetZebra.css[0])
.end().filter(':odd')
.removeClass(table.config.widgetZebra.css[0]).addClass(table.config.widgetZebra.css[1]);
if(table.config.debug) { $.tablesorter.benchmark("Applying Zebra widget", time); }
}
});
})(jQuery);
/*global jQuery */
/* ****************************************************************************
CJ Object Scaler jQuery Plug-In v2.0
This library is released under the BSD license:
Copyright (c) 2008, Doug Jones. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. Redistributions in binary
form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials
provided with the distribution. Neither the name BernieCode nor
the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
For more information please visit www.cjboco.com.
Example:
$("#myImage").cjObjectScaler({
destObj: $("#myDiv"), // Needs to be a jQuery object
method: "fit", // fit | fill (default)
fade: 500 // 0 no fade, positive integer fade duration
});
CHANGELOG
v1.0 09/10/08 - Initial Release
v2.0 09/22/09 - Coverted it to a jQuery plug-in
v2.0.1 10/14/09 - Fixed a bug where the scaling function
wasn't being triggered, do to the
image already being loaded.
(Discovered by Ben Visser)
**************************************************************************** */
(function ($) {
$.fn.cjObjectScaler = function (options) {
/*
user variables (settings)
***************************************/
var settings = {
// user editable settings
destObj: null,
// must be a jQuery object
method: "fill",
// fit|fill
fade: 0 // if positive value, do hide/fadeIn
};
/*
system variables
***************************************/
var sys = {
// function parameters
version: '2.0.0',
elem: null
};
/*
scale the image
***************************************/
function scale(self) {
// declare some local variables
var dest = settings.destObj,
destW = $(dest).width(),
destH = $(dest).height(),
ratioX,
ratioY,
scale,
newWidth,
newHeight;
// calculate scale ratios
ratioX = destW / $(self).width();
ratioY = destH / $(self).height();
// Determine which algorithm to use
if (!$(self).hasClass("cf_image_scaler_fill") && ($(self).hasClass("cf_image_scaler_fit") || settings.method === "fit")) {
scale = ratioX < ratioY ? ratioX : ratioY;
} else if (!$(self).hasClass("cf_image_scaler_fit") && ($(self).hasClass("cf_image_scaler_fill") || settings.method === "fill")) {
scale = ratioX > ratioY ? ratioX : ratioY;
}
// calculate our new image dimensions
newWidth = parseInt($(self).width() * scale, 10);
newHeight = parseInt($(self).height() * scale, 10);
// Set new dimensions & offset
$(self).css({
"width": newWidth + "px",
"height": newHeight + "px",
"position": "absolute",
"top": parseInt((destH - newHeight) / 2, 10) + "px",
"left": parseInt((destW - newWidth) / 2, 10) + "px"
}).attr({
"width": newWidth,
"height": newHeight
});
// do our fancy fade in, if user supplied a fade amount
if (settings.fade > 0) {
$(self).fadeIn(settings.fade);
}
}
/*
initialize the flipBox
***************************************/
function init() {
var self = $(sys.elem)[0];
// check to make sure we have a valid destination object
if (settings.destObj === null || typeof settings.method !== "string" || typeof $(settings.destObj)[0] !== "object") {
return;
} else {
// need to make sure the user set the parent's position
// things go bonkers, if not set.
if ($(settings.destObj).css("position") === "static") {
$(settings.destObj).css({
"position": "relative"
});
}
// if the user supplied a fade amount, hide our image
if (settings.fade > 0) {
$(self).hide();
}
// run our scale function. Special case for images, we need
// to make sure the image has loaded in order to get the width & height
if ($(self)[0].nodeName === "IMG") {
// check to see if the image is already loaded
if ($(self).attr("complete")) {
scale($(self)[0]);
} else {
$(self).load(function () {
scale($(self)[0]);
});
}
} else {
scale($(self)[0]);
}
}
}
/*
set up any user passed variables
***************************************/
if (options) {
$.extend(settings, options);
}
/*
main
***************************************/
return this.each(function () {
sys.elem = this;
init();
});
};
})(jQuery);