Add WebCms
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 830 B |
Binary file not shown.
|
After Width: | Height: | Size: 73 B |
Binary file not shown.
|
After Width: | Height: | Size: 833 B |
File diff suppressed because one or more lines are too long
@@ -0,0 +1,396 @@
|
||||
//
|
||||
// TableDnD plug-in for JQuery, allows you to drag and drop table rows
|
||||
// You can set up various options to control how the system will work
|
||||
// Copyright (c) Denis Howlett <denish@isocra.com>
|
||||
// Licensed like jQuery, see http://docs.jquery.com/License.
|
||||
//
|
||||
// Configuration options:
|
||||
//
|
||||
// onDragStyle
|
||||
// This is the style that is assigned to the row during drag. There are limitations to the styles that can be
|
||||
// associated with a row (such as you can't assign a border--well you can, but it won't be
|
||||
// displayed). (So instead consider using onDragClass.) The CSS style to apply is specified as
|
||||
// a map (as used in the jQuery css(...) function).
|
||||
// onDropStyle
|
||||
// This is the style that is assigned to the row when it is dropped. As for onDragStyle, there are limitations
|
||||
// to what you can do. Also this replaces the original style, so again consider using onDragClass which
|
||||
// is simply added and then removed on drop.
|
||||
// onDragClass
|
||||
// This class is added for the duration of the drag and then removed when the row is dropped. It is more
|
||||
// flexible than using onDragStyle since it can be inherited by the row cells and other content. The default
|
||||
// is class is tDnD_whileDrag. So to use the default, simply customise this CSS class in your
|
||||
// stylesheet.
|
||||
// onDrop
|
||||
// Pass a function that will be called when the row is dropped. The function takes 2 parameters: the table
|
||||
// and the row that was dropped. You can work out the new order of the rows by using
|
||||
// table.rows.
|
||||
// onDragStart
|
||||
// Pass a function that will be called when the user starts dragging. The function takes 2 parameters: the
|
||||
// table and the row which the user has started to drag.
|
||||
// onAllowDrop
|
||||
// Pass a function that will be called as a row is over another row. If the function returns true, allow
|
||||
// dropping on that row, otherwise not. The function takes 2 parameters: the dragged row and the row under
|
||||
// the cursor. It returns a boolean: true allows the drop, false doesn't allow it.
|
||||
// scrollAmount
|
||||
// This is the number of pixels to scroll if the user moves the mouse cursor to the top or bottom of the
|
||||
// window. The page should automatically scroll up or down as appropriate (tested in IE6, IE7, Safari, FF2,
|
||||
// FF3 beta
|
||||
// dragHandle
|
||||
// This is the name of a class that you assign to one or more cells in each row that is draggable. If you
|
||||
// specify this class, then you are responsible for setting cursor: move in the CSS and only these cells
|
||||
// will have the drag behaviour. If you do not specify a dragHandle, then you get the old behaviour where
|
||||
// the whole row is draggable.
|
||||
//
|
||||
// Other ways to control behaviour:
|
||||
//
|
||||
// Add class="nodrop" to any rows for which you don't want to allow dropping, and class="nodrag" to any rows
|
||||
// that you don't want to be draggable.
|
||||
//
|
||||
// Inside the onDrop method you can also call $.tableDnD.serialize() this returns a string of the form
|
||||
// <tableID>[]=<rowID1>&<tableID>[]=<rowID2> so that you can send this back to the server. The table must have
|
||||
// an ID as must all the rows.
|
||||
//
|
||||
// Other methods:
|
||||
//
|
||||
// $("...").tableDnDUpdate()
|
||||
// Will update all the matching tables, that is it will reapply the mousedown method to the rows (or handle cells).
|
||||
// This is useful if you have updated the table rows using Ajax and you want to make the table draggable again.
|
||||
// The table maintains the original configuration (so you don't have to specify it again).
|
||||
//
|
||||
// $("...").tableDnDSerialize()
|
||||
// Will serialize and return the serialized string as above, but for each of the matching tables--so it can be
|
||||
// called from anywhere and isn't dependent on the currentTable being set up correctly before calling
|
||||
//
|
||||
// Known problems:
|
||||
// - Auto-scoll has some problems with IE7 (it scrolls even when it shouldn't), work-around: set scrollAmount to 0
|
||||
//
|
||||
// Version 0.2: 2008-02-20 First public version
|
||||
// Version 0.3: 2008-02-07 Added onDragStart option
|
||||
// Made the scroll amount configurable (default is 5 as before)
|
||||
// Version 0.4: 2008-03-15 Changed the noDrag/noDrop attributes to nodrag/nodrop classes
|
||||
// Added onAllowDrop to control dropping
|
||||
// Fixed a bug which meant that you couldn't set the scroll amount in both directions
|
||||
// Added serialize method
|
||||
// Version 0.5: 2008-05-16 Changed so that if you specify a dragHandle class it doesn't make the whole row
|
||||
// draggable
|
||||
// Improved the serialize method to use a default (and settable) regular expression.
|
||||
// Added tableDnDupate() and tableDnDSerialize() to be called when you are outside the table
|
||||
//
|
||||
jQuery.tableDnD = {
|
||||
// Keep hold of the current table being dragged
|
||||
currentTable: null,
|
||||
// Keep hold of the current drag object if any
|
||||
dragObject: null,
|
||||
// The current mouse offset
|
||||
mouseOffset: null,
|
||||
// Remember the old value of Y so that we don't do too much processing
|
||||
oldY: 0,
|
||||
|
||||
// Actually build the structure
|
||||
build: function(options) {
|
||||
// Set up the defaults if any
|
||||
|
||||
this.each(function() {
|
||||
// This is bound to each matching table, set up the defaults and override with user options
|
||||
this.tableDnDConfig = jQuery.extend({
|
||||
onDragStyle: null,
|
||||
onDropStyle: null,
|
||||
// Add in the default class for whileDragging
|
||||
onDragClass: "tDnD_whileDrag",
|
||||
onDrop: null,
|
||||
onDragStart: null,
|
||||
scrollAmount: 5,
|
||||
serializeRegexp: /[^\-]*$/, // The regular expression to use to trim row IDs
|
||||
serializeParamName: null, // If you want to specify another parameter name instead of the table ID
|
||||
dragHandle: null, // If you give the name of a class here, then only Cells with this class will be draggable
|
||||
containment: null
|
||||
}, options || {});
|
||||
// Now make the rows draggable
|
||||
jQuery.tableDnD.makeDraggable(this);
|
||||
});
|
||||
|
||||
// Now we need to capture the mouse up and mouse move event
|
||||
// We can use bind so that we don't interfere with other event handlers
|
||||
jQuery(document)
|
||||
.bind('mousemove', jQuery.tableDnD.mousemove)
|
||||
.bind('mouseup', jQuery.tableDnD.mouseup);
|
||||
|
||||
// Don't break the chain
|
||||
return this;
|
||||
},
|
||||
|
||||
// This function makes all the rows on the table draggable apart from those marked as "NoDrag"
|
||||
makeDraggable: function(table) {
|
||||
var config = table.tableDnDConfig;
|
||||
if (table.tableDnDConfig.dragHandle) {
|
||||
// We only need to add the event to the specified cells
|
||||
var cells = jQuery("td." + table.tableDnDConfig.dragHandle, table);
|
||||
cells.each(function() {
|
||||
// The cell is bound to "this"
|
||||
jQuery(this).mousedown(function(ev) {
|
||||
jQuery.tableDnD.dragObject = this.parentNode;
|
||||
jQuery.tableDnD.currentTable = table;
|
||||
jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
|
||||
if (config.onDragStart) {
|
||||
// Call the onDrop method if there is one
|
||||
config.onDragStart(table, this);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
})
|
||||
} else {
|
||||
// For backwards compatibility, we add the event to the whole row
|
||||
var rows = jQuery("tr", table); // get all the rows as a wrapped set
|
||||
rows.each(function() {
|
||||
// Iterate through each row, the row is bound to "this"
|
||||
var row = jQuery(this);
|
||||
if (!row.hasClass("nodrag")) {
|
||||
row.mousedown(function(ev) {
|
||||
if (ev.target.tagName == "TD") {
|
||||
jQuery.tableDnD.dragObject = this;
|
||||
jQuery.tableDnD.currentTable = table;
|
||||
jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
|
||||
if (config.onDragStart) {
|
||||
// Call the onDrop method if there is one
|
||||
config.onDragStart(table, this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}).css("cursor", "move"); // Store the tableDnD object
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
updateTables: function() {
|
||||
this.each(function() {
|
||||
// this is now bound to each matching table
|
||||
if (this.tableDnDConfig) {
|
||||
jQuery.tableDnD.makeDraggable(this);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// Get the mouse coordinates from the event (allowing for browser differences)
|
||||
mouseCoords: function(ev) {
|
||||
if (ev.pageX || ev.pageY) {
|
||||
return { x: ev.pageX, y: ev.pageY };
|
||||
}
|
||||
return {
|
||||
x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
|
||||
y: ev.clientY + document.body.scrollTop - document.body.clientTop
|
||||
};
|
||||
},
|
||||
|
||||
// Given a target element and a mouse event, get the mouse offset from that element.
|
||||
// To do this we need the element's position and the mouse position
|
||||
getMouseOffset: function(target, ev) {
|
||||
ev = ev || window.event;
|
||||
|
||||
var docPos = this.getPosition(target);
|
||||
var mousePos = this.mouseCoords(ev);
|
||||
return { x: mousePos.x - docPos.x, y: mousePos.y - docPos.y };
|
||||
},
|
||||
|
||||
// Get the position of an element by going up the DOM tree and adding up all the offsets
|
||||
getPosition: function(e) {
|
||||
var left = 0;
|
||||
var top = 0;
|
||||
// Safari fix -- thanks to Luis Chato for this!
|
||||
if (e.offsetHeight == 0) {
|
||||
// Safari 2 doesn't correctly grab the offsetTop of a table row
|
||||
// this is detailed here:
|
||||
// http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari/
|
||||
// the solution is likewise noted there, grab the offset of a table cell in the row - the firstChild.
|
||||
// note that firefox will return a text node as a first child, so designing a more thorough
|
||||
// solution may need to take that into account, for now this seems to work in firefox, safari, ie
|
||||
e = e.firstChild; // a table cell
|
||||
}
|
||||
|
||||
while (e.offsetParent) {
|
||||
left += e.offsetLeft;
|
||||
top += e.offsetTop;
|
||||
e = e.offsetParent;
|
||||
}
|
||||
|
||||
left += e.offsetLeft;
|
||||
top += e.offsetTop;
|
||||
|
||||
return { x: left, y: top };
|
||||
},
|
||||
|
||||
mousemove: function(ev) {
|
||||
if (jQuery.tableDnD.dragObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var dragObj = jQuery(jQuery.tableDnD.dragObject);
|
||||
var config = jQuery.tableDnD.currentTable.tableDnDConfig;
|
||||
var mousePos = jQuery.tableDnD.mouseCoords(ev);
|
||||
var y = mousePos.y - jQuery.tableDnD.mouseOffset.y;
|
||||
|
||||
//auto scroll the window
|
||||
var yOffset = window.pageYOffset;
|
||||
if (document.all) {
|
||||
// Windows version
|
||||
//yOffset=document.body.scrollTop;
|
||||
if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
|
||||
yOffset = document.documentElement.scrollTop;
|
||||
}
|
||||
else if (typeof document.body != 'undefined') {
|
||||
yOffset = document.body.scrollTop;
|
||||
}
|
||||
}
|
||||
|
||||
//if our dragable items is inside a parent with overflow on...
|
||||
if (config.containment) {
|
||||
|
||||
var endofContainer = config.containment.offset().top + config.containment.height();
|
||||
var currentScrollTop = config.containment.scrollTop();
|
||||
|
||||
if (endofContainer - mousePos.y < config.scrollAmount) {
|
||||
config.containment.scrollTop(currentScrollTop + config.scrollAmount);
|
||||
|
||||
} else if ( mousePos.y - config.scrollAmount < config.containment.offset().top) {
|
||||
config.containment.scrollTop(currentScrollTop - config.scrollAmount);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (mousePos.y - yOffset < config.scrollAmount) {
|
||||
window.scrollBy(0, -config.scrollAmount);
|
||||
} else {
|
||||
var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
|
||||
if (windowHeight - (mousePos.y - yOffset) < config.scrollAmount) {
|
||||
window.scrollBy(0, config.scrollAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (y != jQuery.tableDnD.oldY) {
|
||||
// work out if we're going up or down...
|
||||
var movingDown = y > jQuery.tableDnD.oldY;
|
||||
// update the old value
|
||||
jQuery.tableDnD.oldY = y;
|
||||
// update the style to show we're dragging
|
||||
if (config.onDragClass) {
|
||||
dragObj.addClass(config.onDragClass);
|
||||
} else {
|
||||
dragObj.css(config.onDragStyle);
|
||||
}
|
||||
// If we're over a row then move the dragged row to there so that the user sees the
|
||||
// effect dynamically
|
||||
var currentRow = jQuery.tableDnD.findDropTargetRow(dragObj, y);
|
||||
if (currentRow) {
|
||||
// TODO worry about what happens when there are multiple TBODIES
|
||||
if (movingDown && jQuery.tableDnD.dragObject != currentRow) {
|
||||
jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow.nextSibling);
|
||||
} else if (!movingDown && jQuery.tableDnD.dragObject != currentRow) {
|
||||
jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
// We're only worried about the y position really, because we can only move rows up and down
|
||||
findDropTargetRow: function(draggedRow, y) {
|
||||
var rows = jQuery.tableDnD.currentTable.rows;
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
var row = rows[i];
|
||||
var rowY = this.getPosition(row).y;
|
||||
var rowHeight = parseInt(row.offsetHeight) / 2;
|
||||
if (row.offsetHeight == 0) {
|
||||
rowY = this.getPosition(row.firstChild).y;
|
||||
rowHeight = parseInt(row.firstChild.offsetHeight) / 2;
|
||||
}
|
||||
// Because we always have to insert before, we need to offset the height a bit
|
||||
if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {
|
||||
// that's the row we're over
|
||||
// If it's the same as the current row, ignore it
|
||||
if (row == draggedRow) { return null; }
|
||||
var config = jQuery.tableDnD.currentTable.tableDnDConfig;
|
||||
if (config.onAllowDrop) {
|
||||
if (config.onAllowDrop(draggedRow, row)) {
|
||||
return row;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
// If a row has nodrop class, then don't allow dropping (inspired by John Tarr and Famic)
|
||||
var nodrop = jQuery(row).hasClass("nodrop");
|
||||
if (!nodrop) {
|
||||
return row;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return row;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
mouseup: function(e) {
|
||||
if (jQuery.tableDnD.currentTable && jQuery.tableDnD.dragObject) {
|
||||
var droppedRow = jQuery.tableDnD.dragObject;
|
||||
var config = jQuery.tableDnD.currentTable.tableDnDConfig;
|
||||
// If we have a dragObject, then we need to release it,
|
||||
// The row will already have been moved to the right place so we just reset stuff
|
||||
if (config.onDragClass) {
|
||||
jQuery(droppedRow).removeClass(config.onDragClass);
|
||||
} else {
|
||||
jQuery(droppedRow).css(config.onDropStyle);
|
||||
}
|
||||
jQuery.tableDnD.dragObject = null;
|
||||
if (config.onDrop) {
|
||||
// Call the onDrop method if there is one
|
||||
config.onDrop(jQuery.tableDnD.currentTable, droppedRow);
|
||||
}
|
||||
jQuery.tableDnD.currentTable = null; // let go of the table too
|
||||
}
|
||||
},
|
||||
|
||||
serialize: function() {
|
||||
if (jQuery.tableDnD.currentTable) {
|
||||
return jQuery.tableDnD.serializeTable(jQuery.tableDnD.currentTable);
|
||||
} else {
|
||||
return "Error: No Table id set, you need to set an id on your table and every row";
|
||||
}
|
||||
},
|
||||
|
||||
serializeTable: function(table) {
|
||||
var result = "";
|
||||
var tableId = table.id;
|
||||
var rows = table.rows;
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
if (result.length > 0) result += "&";
|
||||
var rowId = rows[i].id;
|
||||
if (rowId && rowId && table.tableDnDConfig && table.tableDnDConfig.serializeRegexp) {
|
||||
rowId = rowId.match(table.tableDnDConfig.serializeRegexp)[0];
|
||||
}
|
||||
|
||||
result += tableId + '[]=' + rowId;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
serializeTables: function() {
|
||||
var result = "";
|
||||
this.each(function() {
|
||||
// this is now bound to each matching table
|
||||
result += jQuery.tableDnD.serializeTable(this);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
jQuery.fn.extend(
|
||||
{
|
||||
tableDnD: jQuery.tableDnD.build,
|
||||
tableDnDUpdate: jQuery.tableDnD.updateTables,
|
||||
tableDnDSerialize: jQuery.tableDnD.serializeTables
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,523 @@
|
||||
(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 };
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
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);
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (table.config.appender) {
|
||||
table.config.appender(table, rows);
|
||||
}
|
||||
rows = null;
|
||||
if (table.config.debug) {
|
||||
benchmark("Rebuilt table:", appendTime);
|
||||
}
|
||||
applyWidget(table);
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
var i;
|
||||
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) {
|
||||
$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 = $('<colgroup>');
|
||||
$("tr:first td", table.tBodies[0]).each(function() { colgroup.append($('<col>').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++;
|
||||
}
|
||||
}
|
||||
|
||||
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 { ";
|
||||
}
|
||||
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; }
|
||||
|
||||
;
|
||||
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);
|
||||
$this = $(this);
|
||||
$headers = buildHeaders(this);
|
||||
this.config.parsers = buildParserCache(this, $headers);
|
||||
cache = buildCache(this);
|
||||
var sortCSS = [config.cssDesc, config.cssAsc];
|
||||
fixColumnWidth(this);
|
||||
$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) {
|
||||
var $cell = $(this);
|
||||
var i = this.column;
|
||||
this.order = this.count++ % 2;
|
||||
if (!e[config.sortMultiSortKey]) {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
config.sortList.push([i, this.order]);
|
||||
}
|
||||
else {
|
||||
if (isValueInArray(i, config.sortList)) {
|
||||
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 {
|
||||
config.sortList.push([i, this.order]);
|
||||
}
|
||||
}
|
||||
;
|
||||
setTimeout(function() {
|
||||
setHeadersCss($this[0], $headers, config.sortList, sortCSS);
|
||||
appendToTable($this[0], multisort($this[0], config.sortList, cache));
|
||||
}, 1);
|
||||
return false;
|
||||
}
|
||||
}).mousedown(function() {
|
||||
if (config.cancelSelection) {
|
||||
this.onselectstart = function() { return false };
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$this.bind("update", function() {
|
||||
this.config.parsers = buildParserCache(this, $headers);
|
||||
cache = buildCache(this);
|
||||
}).bind("sorton", function(e, list) {
|
||||
$(this).trigger("sortStart");
|
||||
config.sortList = list;
|
||||
var sortList = config.sortList;
|
||||
updateHeaderSortCount(this, sortList);
|
||||
setHeadersCss(this, $headers, sortList, sortCSS);
|
||||
appendToTable(this, multisort(this, sortList, cache));
|
||||
}).bind("appendCache", function() { appendToTable(this, cache); }).bind("applyWidgetId", function(e, id) { getWidgetById(id).format(this); }).bind("applyWidgets", function() { applyWidget(this); });
|
||||
if ($.metadata && ($(this).metadata() && $(this).metadata().sortlist)) {
|
||||
config.sortList = $(this).metadata().sortlist;
|
||||
}
|
||||
if (config.sortList.length > 0) {
|
||||
$this.trigger("sorton", [config.sortList]);
|
||||
}
|
||||
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 = "";
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
$.fn.extend({ tablesorter: $.tablesorter.construct });
|
||||
var ts = $.tablesorter;
|
||||
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") {
|
||||
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$1/$2");
|
||||
}
|
||||
else if (c.dateFormat == "uk") {
|
||||
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"
|
||||
});
|
||||
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);
|
||||
@@ -0,0 +1,353 @@
|
||||
//
|
||||
// @author daemach
|
||||
//
|
||||
|
||||
daemach = function() {
|
||||
this.name = "Daemach's Toolbox";
|
||||
this.version = "2.0";
|
||||
this.debug = false;
|
||||
|
||||
// load extensions
|
||||
this.cw = new colorWeasel(this);
|
||||
this.cm = new cssMonkey(this);
|
||||
};
|
||||
|
||||
jQuery.extend(daemach, {
|
||||
prototype: {
|
||||
log: function() {
|
||||
if (!top.window.console || !top.window.console.log || !this.debug) {
|
||||
return;
|
||||
} else {
|
||||
top.window.console.log([].join.call(arguments, ''));
|
||||
};
|
||||
},
|
||||
time: function() {
|
||||
if (!top.window.console || !top.window.console.time || !this.debug) {
|
||||
return;
|
||||
} else {
|
||||
top.window.console.time([].join.call(arguments, ''));
|
||||
};
|
||||
},
|
||||
timeEnd: function() {
|
||||
if (!top.window.console || !top.window.console.timeEnd || !this.debug) {
|
||||
return;
|
||||
} else {
|
||||
top.window.console.timeEnd([].join.call(arguments, ''));
|
||||
};
|
||||
},
|
||||
profile: function() {
|
||||
if (!top.window.console || !top.window.console.profile || !this.debug) {
|
||||
return;
|
||||
} else {
|
||||
top.window.console.profile([].join.call(arguments, ''));
|
||||
};
|
||||
},
|
||||
profileEnd: function() {
|
||||
if (!top.window.console || !top.window.console.profileEnd || !this.debug) {
|
||||
return;
|
||||
} else {
|
||||
top.window.console.profileEnd([].join.call(arguments, ''));
|
||||
};
|
||||
},
|
||||
delay: function(condition, callback, scope, interval, done, i) {
|
||||
interval = interval || 15;
|
||||
if (typeof done === "undefined") {
|
||||
var done = false;
|
||||
i = setInterval(function() { $d.delay(condition, callback, scope, interval, done, i); }, interval)
|
||||
} else {
|
||||
var con = condition.apply(scope);
|
||||
console.log(con);
|
||||
if (con) {
|
||||
clearInterval(i);
|
||||
callback.call(scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// ==============================================================================================
|
||||
// ColorWeasel v1.4
|
||||
// ==============================================================================================
|
||||
//
|
||||
|
||||
colorWeasel = function(root) {
|
||||
this.name = "colorWeasel";
|
||||
this.version = "1.4";
|
||||
this.root = root;
|
||||
};
|
||||
jQuery.extend(colorWeasel, {
|
||||
prototype: {
|
||||
rgb2hsl: function(rgb) {
|
||||
rgb = this.rgb2hex(rgb);
|
||||
var r = parseInt(rgb.substr(0, 2), 16) / 255;
|
||||
var g = parseInt(rgb.substr(2, 2), 16) / 255;
|
||||
var b = parseInt(rgb.substr(4, 2), 16) / 255;
|
||||
var max = Math.max(r, g, b),
|
||||
min = Math.min(r, g, b),
|
||||
delta = (max - min),
|
||||
l = (max + min) / 2,
|
||||
h = 0,
|
||||
s = 0,
|
||||
dR, dG, dB;
|
||||
if (max != min) {
|
||||
s = (l < .5) ? (max - min) / (max + min) : (max - min) / (2 - max - min);
|
||||
dR = (((max - r) / 6) + (delta / 2)) / delta;
|
||||
dG = (((max - g) / 6) + (delta / 2)) / delta;
|
||||
dB = (((max - b) / 6) + (delta / 2)) / delta;
|
||||
h = (max != r) ? (max != g) ? ((2 / 3) + dG - dR) : ((1 / 3) + dR - dB) : (dB - dG);
|
||||
};
|
||||
if (h < 0) { h += 1; };
|
||||
if (h > 1) { h -= 1; };
|
||||
h *= 360;
|
||||
return [h, s, l];
|
||||
},
|
||||
hsl2rgb: function(h, s, l) { // H as degrees 0..360, S L as decimals, 0..1.
|
||||
if (typeof h == "object" && h.constructor == Array) {
|
||||
l = h[2];
|
||||
s = h[1];
|
||||
h = h[0];
|
||||
};
|
||||
h /= 360;
|
||||
var y = (l > .5) ? (l + s) - (l * s) : l * (s + 1),
|
||||
x = l * 2 - y,
|
||||
r = Math.round(255 * _hue2Rgb(x, y, h + (1 / 3))),
|
||||
g = Math.round(255 * _hue2Rgb(x, y, h)),
|
||||
b = Math.round(255 * _hue2Rgb(x, y, h - (1 / 3)));
|
||||
|
||||
function _hue2Rgb(x, y, h) {
|
||||
if (h < 0) {
|
||||
h += 1;
|
||||
} else if (h > 1) {
|
||||
h -= 1;
|
||||
};
|
||||
|
||||
return ((h * 6) < 1) ? (x + (y - x) * h * 6) : ((h * 2) < 1) ? y : ((h * 3) < 2) ? (x + (y - x) * ((2 / 3) - h) * 6) : x;
|
||||
}
|
||||
return this.zeroPad(r.toString(16)).toUpperCase() + this.zeroPad(g.toString(16)).toUpperCase() + this.zeroPad(b.toString(16)).toUpperCase();
|
||||
},
|
||||
zeroPad: function(num) {
|
||||
var str = '0' + num;
|
||||
return str.substring(str.length - 2);
|
||||
},
|
||||
rgb2hex: function(rgb) {
|
||||
if (!rgb.match(/(rgb\()[^\)]+(\))/)) {
|
||||
return rgb;
|
||||
};
|
||||
var t = /(rgb\()([^\)]+)(\))/.exec(rgb);
|
||||
t = t[2].replace(/\s+/g, "").split(",");
|
||||
var r = this.zeroPad(parseInt(t[0]).toString(16).toUpperCase());
|
||||
var g = this.zeroPad(parseInt(t[1]).toString(16).toUpperCase());
|
||||
var b = this.zeroPad(parseInt(t[2]).toString(16).toUpperCase());
|
||||
|
||||
return r + g + b;
|
||||
},
|
||||
ccLighter: function(rgb, perc) {
|
||||
var hsl = this.rgb2hsl(rgb);
|
||||
hsl[2] += (hsl[2] *= perc);
|
||||
hsl[2] = (hsl[2] >= 1) ? 1 : hsl[2];
|
||||
rgb = this.hsl2rgb(hsl);
|
||||
return rgb;
|
||||
},
|
||||
ccDarker: function(rgb, perc) {
|
||||
var hsl = this.rgb2hsl(rgb);
|
||||
hsl[2] -= (hsl[2] *= perc);
|
||||
hsl[2] = (hsl[2] <= 0) ? 0 : hsl[2];
|
||||
rgb = this.hsl2rgb(hsl);
|
||||
return rgb;
|
||||
},
|
||||
ccComplementary: function(rgb) {
|
||||
var hsl = this.rgb2hsl(rgb);
|
||||
hsl[0] += 180;
|
||||
hsl[0] = (hsl[0] > 360) ? hsl[0] - 360 : hsl[0];
|
||||
rgb = this.hsl2rgb(hsl);
|
||||
return rgb;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
//
|
||||
// ==============================================================================================
|
||||
// CSSMonkey v1.2
|
||||
// ==============================================================================================
|
||||
//
|
||||
|
||||
//
|
||||
// @author daemach
|
||||
//
|
||||
|
||||
cssMonkey = function(root) {
|
||||
this.name = "cssMonkey";
|
||||
this.version = "1.2";
|
||||
this.root = root;
|
||||
this.sheets = [];
|
||||
if (document.styleSheets) {
|
||||
this.parseStyles();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
jQuery.extend(cssMonkey, {
|
||||
prototype: {
|
||||
parseStyles: function() {
|
||||
var media, mediaType, styleSheet;
|
||||
if (document.styleSheets.length > 0) {
|
||||
for (var i = 0; i < document.styleSheets.length; i++) {
|
||||
if (document.styleSheets[i].disabled) {
|
||||
continue;
|
||||
}
|
||||
media = document.styleSheets[i].media;
|
||||
mediaType = typeof media;
|
||||
|
||||
if (mediaType == "string") {
|
||||
if (media == "" || media.indexOf("screen") != -1) {
|
||||
styleSheet = document.styleSheets[i];
|
||||
}
|
||||
} else if (mediaType == "object") {
|
||||
if (media.mediaText == "" || media.mediaText.indexOf("screen") != -1) {
|
||||
styleSheet = document.styleSheets[i];
|
||||
}
|
||||
}
|
||||
if (typeof styleSheet != "undefined") {
|
||||
this.sheets.push(styleSheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
toggleSheet: function(disable, id) {
|
||||
var s = this.sheets;
|
||||
id = (typeof id === "undefined") ? null : id;
|
||||
disable = (typeof disable === "undefined") ? null : disable;
|
||||
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
if (id === null || i == id || s[i].href.indexOf(id) >= 0) {
|
||||
s[i].disabled = (disable || (disable === null && !s[i].disabled)) ? true : false;
|
||||
}
|
||||
}
|
||||
},
|
||||
getRule: function(s, a) {
|
||||
var rules, matches = [], sObj = [];
|
||||
for (var i = this.sheets.length - 1; i >= 0; i--) {
|
||||
rules = (this.sheets[i].cssRules) ? this.sheets[i].cssRules : this.sheets[i].rules;
|
||||
if (!rules.length) {
|
||||
return matches;
|
||||
}
|
||||
s = s.toLowerCase();
|
||||
for (var r = rules.length - 1; r >= 0; r--) {
|
||||
if (typeof rules[r].selectorText != "undefined" && rules[r].selectorText.toLowerCase() == s) {
|
||||
a = (typeof a == "undefined") ? null : rules[r].style[this.camelCase(a)];
|
||||
matches.push([rules[r], i, r, a]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
},
|
||||
_findStyle: function(cssText, attr) {
|
||||
var n = (attr.indexOf(":") >= 0) ? attr.split(":")[0].trim() : attr;
|
||||
if (n.length) {
|
||||
for (var i = 0; i < cssText.length; i++) {
|
||||
if (cssText[i].indexOf(n) >= 0) { return i; }
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
camelCase: function(s) {
|
||||
if (s == "float") { return "cssFloat"; };
|
||||
for (var str = /-([a-z])/; str.test(s); s = s.replace(str, RegExp.$1.toUpperCase()));
|
||||
return s;
|
||||
},
|
||||
getComputedStyle: function(ele, attr) {
|
||||
attr = this.camelCase(attr);
|
||||
if (ele.currentStyle) {
|
||||
return ele.currentStyle[attr];
|
||||
} else if (window.getComputedStyle) {
|
||||
return window.getComputedStyle(ele, null)[attr];
|
||||
}
|
||||
return null;
|
||||
},
|
||||
getRootStyle: function(ele, attr) {
|
||||
attr = this.camelCase(attr);
|
||||
var tmpAttr = this.getComputedStyle(ele, attr), tmpEle = ele;
|
||||
if (attr.indexOf("Color") >= 0) {
|
||||
tmpAttr = this.root.cw.rgb2hex(tmpAttr);
|
||||
while (tmpEle !== "body" && tmpAttr == "transparent") {
|
||||
tmpEle = tmpEle.parentNode;
|
||||
tmpAttr = this.root.cw.rgb2hex(this.getComputedStyle(tmpEle, attr));
|
||||
}
|
||||
tmpAttr = (tmpAttr == "transparent") ? "000000" : tmpAttr;
|
||||
}
|
||||
return tmpAttr;
|
||||
},
|
||||
setRule: function(selector, styles, index) {
|
||||
|
||||
var rules = this.getRule(selector), oCSS, nCSS, o, s, rCSS;
|
||||
if (rules.length) {
|
||||
nCSS = styles.split(";");
|
||||
if (!nCSS[nCSS.length - 1].trim().length) { nCSS.pop(); }
|
||||
for (var i = 0; i < rules.length; i++) {
|
||||
oCSS = rules[i][0].style.cssText.split(";");
|
||||
for (var x = 0; x < nCSS.length; x++) {
|
||||
s = this._findStyle(oCSS, nCSS[x]);
|
||||
if (s >= 0) {
|
||||
oCSS[s] = nCSS[x];
|
||||
} else {
|
||||
oCSS.push(nCSS[x]);
|
||||
}
|
||||
}
|
||||
rules[i][0].style.cssText = oCSS.join(";");
|
||||
}
|
||||
} else {
|
||||
var sheet = this.sheets[this.sheets.length - 1];
|
||||
var rules = sheet.cssRules ? sheet.cssRules : sheet.rules;
|
||||
if (index == undefined) {
|
||||
index = rules.length;
|
||||
}
|
||||
this._insertRule(sheet, selector, styles, index)
|
||||
}
|
||||
},
|
||||
_insertRule: function(sheet, selector, styles, index) {
|
||||
|
||||
if (sheet.insertRule) {
|
||||
sheet.insertRule(selector + "{" + styles + "}", index);
|
||||
} else if (sheet.addRule) {
|
||||
sheet.addRule(selector, styles, index);
|
||||
}
|
||||
},
|
||||
deleteRule: function(s) {
|
||||
var rules = this.getRule(s), sheet;
|
||||
for (var i = rules.length - 1; i >= 0; i--) {
|
||||
sheet = this.sheets[rules[i][1]];
|
||||
if (sheet.deleteRule) {
|
||||
sheet.deleteRule(rules[i][2]);
|
||||
} else if (sheet.removeRule) {
|
||||
sheet.removeRule(rules[i][2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// ==============================================================================================
|
||||
// Light it up...
|
||||
// ==============================================================================================
|
||||
//
|
||||
if (typeof $daemach == "undefined") {
|
||||
var $daemach = new daemach();
|
||||
}
|
||||
var $d = $daemach;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user