diff --git a/app/views/projects/_table.html.erb b/app/views/projects/_table.html.erb index 145ec8a..c9a8a44 100644 --- a/app/views/projects/_table.html.erb +++ b/app/views/projects/_table.html.erb @@ -1,20 +1,21 @@ - + +
- + <% project_tree(projects) do |project, level| %> - "> + "> - <% end %> @@ -22,5 +23,11 @@
<%= t :field_name %><%= t :field_description %><%= t :field_created_on %>
<%= link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}") %> - <%= textilizable(project.short_description, :project => project) if project.description.present? %> + + <%= format_date(project.created_on) %>
<% content_for :header_tags do %> - <%= stylesheet_link_tag 'projects', :plugin => 'projects_table' %> -<% end %> \ No newline at end of file + <%= stylesheet_link_tag 'jquery.treegrid.css', :plugin => 'projects_table' %> + + <%= javascript_include_tag 'sorttable.js', :plugin => 'projects_table' %> + + <%= javascript_include_tag 'jquery.treegrid.js', :plugin => 'projects_table' %> + <%= javascript_include_tag 'jquery.cookie.js', :plugin => 'projects_table' %> + <%= javascript_include_tag 'createTree.js', :plugin => 'projects_table' %> +<% end %> diff --git a/assets/images/collapse.png b/assets/images/collapse.png new file mode 100644 index 0000000..76577a5 Binary files /dev/null and b/assets/images/collapse.png differ diff --git a/assets/images/expand.png b/assets/images/expand.png new file mode 100644 index 0000000..cfb42a4 Binary files /dev/null and b/assets/images/expand.png differ diff --git a/assets/javascripts/createTree.js b/assets/javascripts/createTree.js new file mode 100644 index 0000000..4e4a58f --- /dev/null +++ b/assets/javascripts/createTree.js @@ -0,0 +1,9 @@ + +console.log("Hello from doc!"); +$(document).ready(function() { + $('.tree').treegrid({ + 'initialState': 'collapsed', + 'saveState': true + }); + console.log("Hello from tree!"); +}); \ No newline at end of file diff --git a/assets/javascripts/jquery.cookie.js b/assets/javascripts/jquery.cookie.js new file mode 100644 index 0000000..5505f5e --- /dev/null +++ b/assets/javascripts/jquery.cookie.js @@ -0,0 +1,96 @@ +/*! + * jQuery Cookie Plugin v1.3.1 + * https://github.com/carhartl/jquery-cookie + * + * Copyright 2013 Klaus Hartl + * Released under the MIT license + */ +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else { + // Browser globals. + factory(jQuery); + } +}(function ($) { + + var pluses = /\+/g; + + function decode(s) { + if (config.raw) { + return s; + } + return decodeURIComponent(s.replace(pluses, ' ')); + } + + function decodeAndParse(s) { + if (s.indexOf('"') === 0) { + // This is a quoted cookie as according to RFC2068, unescape... + s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); + } + + s = decode(s); + + try { + return config.json ? JSON.parse(s) : s; + } catch(e) {} + } + + var config = $.cookie = function (key, value, options) { + + // Write + if (value !== undefined) { + options = $.extend({}, config.defaults, options); + + if (typeof options.expires === 'number') { + var days = options.expires, t = options.expires = new Date(); + t.setDate(t.getDate() + days); + } + + value = config.json ? JSON.stringify(value) : String(value); + + return (document.cookie = [ + config.raw ? key : encodeURIComponent(key), + '=', + config.raw ? value : encodeURIComponent(value), + options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE + options.path ? '; path=' + options.path : '', + options.domain ? '; domain=' + options.domain : '', + options.secure ? '; secure' : '' + ].join('')); + } + + // Read + var cookies = document.cookie.split('; '); + var result = key ? undefined : {}; + for (var i = 0, l = cookies.length; i < l; i++) { + var parts = cookies[i].split('='); + var name = decode(parts.shift()); + var cookie = parts.join('='); + + if (key && key === name) { + result = decodeAndParse(cookie); + break; + } + + if (!key) { + result[name] = decodeAndParse(cookie); + } + } + + return result; + }; + + config.defaults = {}; + + $.removeCookie = function (key, options) { + if ($.cookie(key) !== undefined) { + // Must not alter options, thus extending a fresh object... + $.cookie(key, '', $.extend({}, options, { expires: -1 })); + return true; + } + return false; + }; + +})); \ No newline at end of file diff --git a/assets/javascripts/jquery.treegrid.js b/assets/javascripts/jquery.treegrid.js new file mode 100644 index 0000000..1785e53 --- /dev/null +++ b/assets/javascripts/jquery.treegrid.js @@ -0,0 +1,619 @@ +/* + * jQuery treegrid Plugin 0.2.0 + * https://github.com/maxazan/jquery-treegrid + * + * Copyright 2013, Pomazan Max + * Licensed under the MIT licenses. + */ +(function($) { + + var methods = { + /** + * Initialize tree + * + * @param {Object} options + * @returns {Object[]} + */ + initTree: function(options) { + var settings = $.extend({}, this.treegrid.defaults, options); + return this.each(function() { + var $this = $(this); + $this.treegrid('setTreeContainer', $(this)); + $this.treegrid('setSettings', settings); + settings.getRootNodes.apply(this, [$(this)]).treegrid('initNode', settings); + }); + }, + /** + * Initialize node + * + * @param {Object} settings + * @returns {Object[]} + */ + initNode: function(settings) { + return this.each(function() { + var $this = $(this); + $this.treegrid('setTreeContainer', settings.getTreeGridContainer.apply(this)); + $this.treegrid('getChildNodes').treegrid('initNode', settings); + $this.treegrid('initExpander').treegrid('initIndent').treegrid('initEvents').treegrid('initState').treegrid("initSettingsEvents"); + }); + }, + /** + * Initialize node events + * + * @returns {Node} + */ + initEvents: function() { + var $this = $(this); + //Save state on change + $this.on("change", function() { + var $this = $(this); + $this.treegrid('render'); + if ($this.treegrid('getSetting', 'saveState')) { + $this.treegrid('saveState'); + } + }); + //Default behavior on collapse + $this.on("collapse", function() { + var $this = $(this); + $this.removeClass('treegrid-expanded'); + $this.addClass('treegrid-collapsed'); + }); + //Default behavior on expand + $this.on("expand", function() { + var $this = $(this); + $this.removeClass('treegrid-collapsed'); + $this.addClass('treegrid-expanded'); + }); + + return $this; + }, + /** + * Initialize events from settings + * + * @returns {Node} + */ + initSettingsEvents: function() { + var $this = $(this); + //Save state on change + $this.on("change", function() { + var $this = $(this); + if (typeof ($this.treegrid('getSetting', 'onChange')) === "function") { + $this.treegrid('getSetting', 'onChange').apply($this); + } + }); + //Default behavior on collapse + $this.on("collapse", function() { + var $this = $(this); + if (typeof ($this.treegrid('getSetting', 'onCollapse')) === "function") { + $this.treegrid('getSetting', 'onCollapse').apply($this); + } + }); + //Default behavior on expand + $this.on("expand", function() { + var $this = $(this); + if (typeof ($this.treegrid('getSetting', 'onExpand')) === "function") { + $this.treegrid('getSetting', 'onExpand').apply($this); + } + + }); + + return $this; + }, + /** + * Initialize expander for node + * + * @returns {Node} + */ + initExpander: function() { + var $this = $(this); + var cell = $this.find('td').get($this.treegrid('getSetting', 'treeColumn')); + var tpl = $this.treegrid('getSetting', 'expanderTemplate'); + var expander = $this.treegrid('getSetting', 'getExpander').apply(this); + if (expander) { + expander.remove(); + } + $(tpl).prependTo(cell).click(function() { + $($(this).closest('tr')).treegrid('toggle'); + }); + return $this; + }, + /** + * Initialize indent for node + * + * @returns {Node} + */ + initIndent: function() { + var $this = $(this); + $this.find('.treegrid-indent').remove(); + for (var i = 0; i < $(this).treegrid('getDepth'); i++) { + $($this.treegrid('getSetting', 'indentTemplate')).insertBefore($this.find('.treegrid-expander')); + } + return $this; + }, + /** + * Initialise state of node + * + * @returns {Node} + */ + initState: function() { + var $this = $(this); + if ($this.treegrid('getSetting', 'saveState') && !$this.treegrid('isFirstInit')) { + $this.treegrid('restoreState'); + } else { + if ($this.treegrid('getSetting', 'initialState') === "expanded") { + $this.treegrid('expand'); + } else { + $this.treegrid('collapse'); + } + } + return $this; + }, + /** + * Return true if this tree was never been initialised + * + * @returns {Boolean} + */ + isFirstInit: function() { + var tree = $(this).treegrid('getTreeContainer'); + if (tree.data('first_init') === undefined) { + tree.data('first_init', $.cookie(tree.treegrid('getSetting', 'saveStateName')) === undefined); + } + return tree.data('first_init'); + }, + /** + * Save state of current node + * + * @returns {Node} + */ + saveState: function() { + var $this = $(this); + if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') { + + var stateArrayString = $.cookie($this.treegrid('getSetting', 'saveStateName')) || ''; + var stateArray = (stateArrayString === '' ? [] : stateArrayString.split(',')); + var nodeId = $this.treegrid('getNodeId'); + + if ($this.treegrid('isExpanded')) { + if ($.inArray(nodeId, stateArray) === -1) { + stateArray.push(nodeId); + } + } else if ($this.treegrid('isCollapsed')) { + if ($.inArray(nodeId, stateArray) !== -1) { + stateArray.splice($.inArray(nodeId, stateArray), 1); + } + } + $.cookie($this.treegrid('getSetting', 'saveStateName'), stateArray.join(',')); + } + return $this; + }, + /** + * Restore state of current node. + * + * @returns {Node} + */ + restoreState: function() { + var $this = $(this); + if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') { + var stateArray = $.cookie($this.treegrid('getSetting', 'saveStateName')).split(','); + if ($.inArray($this.treegrid('getNodeId'), stateArray) !== -1) { + $this.treegrid('expand'); + } else { + $this.treegrid('collapse'); + } + + } + return $this; + }, + /** + * Method return setting by name + * + * @param {type} name + * @returns {unresolved} + */ + getSetting: function(name) { + if (!$(this).treegrid('getTreeContainer')) { + return null; + } + return $(this).treegrid('getTreeContainer').data('settings')[name]; + }, + /** + * Add new settings + * + * @param {Object} settings + */ + setSettings: function(settings) { + $(this).treegrid('getTreeContainer').data('settings', settings); + }, + /** + * Return tree container + * + * @returns {HtmlElement} + */ + getTreeContainer: function() { + return $(this).data('treegrid'); + }, + /** + * Set tree container + * + * @param {HtmlE;ement} container + */ + setTreeContainer: function(container) { + return $(this).data('treegrid', container); + }, + /** + * Method return all root nodes of tree. + * + * Start init all child nodes from it. + * + * @returns {Array} + */ + getRootNodes: function() { + return $(this).treegrid('getSetting', 'getRootNodes').apply(this, [$(this).treegrid('getTreeContainer')]); + }, + /** + * Method return all nodes of tree. + * + * @returns {Array} + */ + getAllNodes: function() { + return $(this).treegrid('getSetting', 'getAllNodes').apply(this, [$(this).treegrid('getTreeContainer')]); + }, + /** + * Mthod return true if element is Node + * + * @returns {String} + */ + isNode: function() { + return $(this).treegrid('getNodeId') !== null; + }, + /** + * Mthod return id of node + * + * @returns {String} + */ + getNodeId: function() { + if ($(this).treegrid('getSetting', 'getNodeId') === null) { + return null; + } else { + return $(this).treegrid('getSetting', 'getNodeId').apply(this); + } + }, + /** + * Method return parent id of node or null if root node + * + * @returns {String} + */ + getParentNodeId: function() { + return $(this).treegrid('getSetting', 'getParentNodeId').apply(this); + }, + /** + * Method return parent node or null if root node + * + * @returns {Object[]} + */ + getParentNode: function() { + if ($(this).treegrid('getParentNodeId') === null) { + return null; + } else { + return $(this).treegrid('getSetting', 'getNodeById').apply(this, [$(this).treegrid('getParentNodeId'), $(this).treegrid('getTreeContainer')]); + } + }, + /** + * Method return array of child nodes or null if node is leaf + * + * @returns {Object[]} + */ + getChildNodes: function() { + return $(this).treegrid('getSetting', 'getChildNodes').apply(this, [$(this).treegrid('getNodeId'), $(this).treegrid('getTreeContainer')]); + }, + /** + * Method return depth of tree. + * + * This method is needs for calculate indent + * + * @returns {Number} + */ + getDepth: function() { + if ($(this).treegrid('getParentNode') === null) { + return 0; + } + return $(this).treegrid('getParentNode').treegrid('getDepth') + 1; + }, + /** + * Method return true if node is root + * + * @returns {Boolean} + */ + isRoot: function() { + return $(this).treegrid('getDepth') === 0; + }, + /** + * Method return true if node has no child nodes + * + * @returns {Boolean} + */ + isLeaf: function() { + return $(this).treegrid('getChildNodes').length === 0; + }, + /** + * Method return true if node last in branch + * + * @returns {Boolean} + */ + isLast: function() { + if ($(this).treegrid('isNode')) { + var parentNode = $(this).treegrid('getParentNode'); + if (parentNode === null) { + if ($(this).treegrid('getNodeId') === $(this).treegrid('getRootNodes').last().treegrid('getNodeId')) { + return true; + } + } else { + if ($(this).treegrid('getNodeId') === parentNode.treegrid('getChildNodes').last().treegrid('getNodeId')) { + return true; + } + } + } + return false; + }, + /** + * Method return true if node first in branch + * + * @returns {Boolean} + */ + isFirst: function() { + if ($(this).treegrid('isNode')) { + var parentNode = $(this).treegrid('getParentNode'); + if (parentNode === null) { + if ($(this).treegrid('getNodeId') === $(this).treegrid('getRootNodes').first().treegrid('getNodeId')) { + return true; + } + } else { + if ($(this).treegrid('getNodeId') === parentNode.treegrid('getChildNodes').first().treegrid('getNodeId')) { + return true; + } + } + } + return false; + }, + /** + * Return true if node expanded + * + * @returns {Boolean} + */ + isExpanded: function() { + return $(this).hasClass('treegrid-expanded'); + }, + /** + * Return true if node collapsed + * + * @returns {Boolean} + */ + isCollapsed: function() { + return $(this).hasClass('treegrid-collapsed'); + }, + /** + * Return true if at least one of parent node is collapsed + * + * @returns {Boolean} + */ + isOneOfParentsCollapsed: function() { + var $this = $(this); + if ($this.treegrid('isRoot')) { + return false; + } else { + if ($this.treegrid('getParentNode').treegrid('isCollapsed')) { + return true; + } else { + return $this.treegrid('getParentNode').treegrid('isOneOfParentsCollapsed'); + } + } + }, + /** + * Expand node + * + * @returns {Node} + */ + expand: function() { + return $(this).each(function() { + var $this = $(this); + if (!$this.treegrid('isLeaf') && !$this.treegrid("isExpanded")) { + $this.trigger("expand"); + $this.trigger("change"); + } + }); + }, + /** + * Expand all nodes + * + * @returns {Node} + */ + expandAll: function() { + var $this = $(this); + $this.treegrid('getRootNodes').treegrid('expandRecursive'); + return $this; + }, + /** + * Expand current node and all child nodes begin from current + * + * @returns {Node} + */ + expandRecursive: function() { + return $(this).each(function() { + var $this = $(this); + $this.treegrid('expand'); + if (!$this.treegrid('isLeaf')) { + $this.treegrid('getChildNodes').treegrid('expandRecursive'); + } + }); + }, + /** + * Collapse node + * + * @returns {Node} + */ + collapse: function() { + return $(this).each(function() { + var $this = $(this); + if (!$this.treegrid('isLeaf') && !$this.treegrid("isCollapsed")) { + $this.trigger("collapse"); + $this.trigger("change"); + } + }); + }, + /** + * Collapse all nodes + * + * @returns {Node} + */ + collapseAll: function() { + var $this = $(this); + $this.treegrid('getRootNodes').treegrid('collapseRecursive'); + return $this; + }, + /** + * Collapse current node and all child nodes begin from current + * + * @returns {Node} + */ + collapseRecursive: function() { + return $(this).each(function() { + var $this = $(this); + $this.treegrid('collapse'); + if (!$this.treegrid('isLeaf')) { + $this.treegrid('getChildNodes').treegrid('collapseRecursive'); + } + }); + }, + /** + * Expand if collapsed, Collapse if expanded + * + * @returns {Node} + */ + toggle: function() { + var $this = $(this); + if ($this.treegrid('isExpanded')) { + $this.treegrid('collapse'); + } else { + $this.treegrid('expand'); + } + return $this; + }, + /** + * Rendering node + * + * @returns {Node} + */ + render: function() { + return $(this).each(function() { + var $this = $(this); + + if ($this.treegrid('isOneOfParentsCollapsed')) { + $this.hide(); + } else { + $this.show(); + } + if (!$this.treegrid('isLeaf')) { + $this.treegrid('renderExpander'); + $this.treegrid('getChildNodes').treegrid('render'); + } + }); + }, + /** + * Rendering expander depends on node state + * + * @returns {Node} + */ + renderExpander: function() { + return $(this).each(function() { + var $this = $(this); + var expander = $this.treegrid('getSetting', 'getExpander').apply(this); + if (expander) { + + if (!$this.treegrid('isCollapsed')) { + expander.removeClass($this.treegrid('getSetting', 'expanderCollapsedClass')); + expander.addClass($this.treegrid('getSetting', 'expanderExpandedClass')); + } else { + expander.removeClass($this.treegrid('getSetting', 'expanderExpandedClass')); + expander.addClass($this.treegrid('getSetting', 'expanderCollapsedClass')); + } + } else { + $this.treegrid('initExpander'); + $this.treegrid('renderExpander'); + } + }); + } + }; + $.fn.treegrid = function(method) { + if (methods[method]) { + return methods[ method ].apply(this, Array.prototype.slice.call(arguments, 1)); + } else if (typeof method === 'object' || !method) { + return methods.initTree.apply(this, arguments); + } else { + $.error('Method with name ' + method + ' does not exists for jQuery.treegrid'); + } + }; + /** + * Plugin's default options + */ + $.fn.treegrid.defaults = { + initialState: 'expanded', + saveState: false, + saveStateMethod: 'cookie', + saveStateName: 'tree-grid-state', + expanderTemplate: '', + indentTemplate: '', + expanderExpandedClass: 'treegrid-expander-expanded', + expanderCollapsedClass: 'treegrid-expander-collapsed', + treeColumn: 0, + getExpander: function() { + return $(this).find('.treegrid-expander'); + }, + getNodeId: function() { + var template = /treegrid-([A-Za-z0-9_-]+)/; + if (template.test($(this).attr('class'))) { + return template.exec($(this).attr('class'))[1]; + } + return null; + }, + getParentNodeId: function() { + var template = /treegrid-parent-([A-Za-z0-9_-]+)/; + if (template.test($(this).attr('class'))) { + return template.exec($(this).attr('class'))[1]; + } + return null; + }, + getNodeById: function(id, treegridContainer) { + var templateClass = "treegrid-" + id; + return treegridContainer.find('tr.' + templateClass); + }, + getChildNodes: function(id, treegridContainer) { + var templateClass = "treegrid-parent-" + id; + return treegridContainer.find('tr.' + templateClass); + }, + getTreeGridContainer: function() { + return $(this).closest('table'); + }, + getRootNodes: function(treegridContainer) { + var result = $.grep(treegridContainer.find('tr'), function(element) { + var classNames = $(element).attr('class'); + var templateClass = /treegrid-([A-Za-z0-9_-]+)/; + var templateParentClass = /treegrid-parent-([A-Za-z0-9_-]+)/; + return templateClass.test(classNames) && !templateParentClass.test(classNames); + }); + return $(result); + }, + getAllNodes: function(treegridContainer) { + var result = $.grep(treegridContainer.find('tr'), function(element) { + var classNames = $(element).attr('class'); + var templateClass = /treegrid-([A-Za-z0-9_-]+)/; + return templateClass.test(classNames); + }); + return $(result); + }, + //Events + onCollapse: null, + onExpand: null, + onChange: null + + }; +})(jQuery); \ No newline at end of file diff --git a/assets/javascripts/sorttable.js b/assets/javascripts/sorttable.js new file mode 100644 index 0000000..38b0fc6 --- /dev/null +++ b/assets/javascripts/sorttable.js @@ -0,0 +1,495 @@ +/* + SortTable + version 2 + 7th April 2007 + Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/ + + Instructions: + Download this file + Add to your HTML + Add class="sortable" to any table you'd like to make sortable + Click on the headers to sort + + Thanks to many, many people for contributions and suggestions. + Licenced as X11: http://www.kryogenix.org/code/browser/licence.html + This basically means: do what you want with it. +*/ + + +var stIsIE = /*@cc_on!@*/false; + +sorttable = { + init: function() { + // quit if this function has already been called + if (arguments.callee.done) return; + // flag this function so we don't do the same thing twice + arguments.callee.done = true; + // kill the timer + if (_timer) clearInterval(_timer); + + if (!document.createElement || !document.getElementsByTagName) return; + + sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/; + + forEach(document.getElementsByTagName('table'), function(table) { + if (table.className.search(/\bsortable\b/) != -1) { + sorttable.makeSortable(table); + } + }); + + }, + + makeSortable: function(table) { + if (table.getElementsByTagName('thead').length == 0) { + // table doesn't have a tHead. Since it should have, create one and + // put the first table row in it. + the = document.createElement('thead'); + the.appendChild(table.rows[0]); + table.insertBefore(the,table.firstChild); + } + // Safari doesn't support table.tHead, sigh + if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0]; + + if (table.tHead.rows.length != 1) return; // can't cope with two header rows + + // Sorttable v1 put rows with a class of "sortbottom" at the bottom (as + // "total" rows, for example). This is B&R, since what you're supposed + // to do is put them in a tfoot. So, if there are sortbottom rows, + // for backwards compatibility, move them to tfoot (creating it if needed). + sortbottomrows = []; + for (var i=0; i5' : ' ▴'; + this.appendChild(sortrevind); + return; + } + if (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) { + // if we're already sorted by this column in reverse, just + // re-reverse the table, which is quicker + sorttable.reverse(this.sorttable_tbody); + this.className = this.className.replace('sorttable_sorted_reverse', + 'sorttable_sorted'); + this.removeChild(document.getElementById('sorttable_sortrevind')); + sortfwdind = document.createElement('span'); + sortfwdind.id = "sorttable_sortfwdind"; + sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; + this.appendChild(sortfwdind); + return; + } + + // remove sorttable_sorted classes + theadrow = this.parentNode; + forEach(theadrow.childNodes, function(cell) { + if (cell.nodeType == 1) { // an element + cell.className = cell.className.replace('sorttable_sorted_reverse',''); + cell.className = cell.className.replace('sorttable_sorted',''); + } + }); + sortfwdind = document.getElementById('sorttable_sortfwdind'); + if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); } + sortrevind = document.getElementById('sorttable_sortrevind'); + if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); } + + this.className += ' sorttable_sorted'; + sortfwdind = document.createElement('span'); + sortfwdind.id = "sorttable_sortfwdind"; + sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; + this.appendChild(sortfwdind); + + // build an array to sort. This is a Schwartzian transform thing, + // i.e., we "decorate" each row with the actual sort key, + // sort based on the sort keys, and then put the rows back in order + // which is a lot faster because you only do getInnerText once per row + row_array = []; + col = this.sorttable_columnindex; + rows = this.sorttable_tbody.rows; + for (var j=0; j 12) { + // definitely dd/mm + return sorttable.sort_ddmm; + } else if (second > 12) { + return sorttable.sort_mmdd; + } else { + // looks like a date, but we can't tell which, so assume + // that it's dd/mm (English imperialism!) and keep looking + sortfn = sorttable.sort_ddmm; + } + } + } + } + return sortfn; + }, + + getInnerText: function(node) { + // gets the text we want to use for sorting for a cell. + // strips leading and trailing whitespace. + // this is *not* a generic getInnerText function; it's special to sorttable. + // for example, you can override the cell text with a customkey attribute. + // it also gets .value for fields. + + if (!node) return ""; + + hasInputs = (typeof node.getElementsByTagName == 'function') && + node.getElementsByTagName('input').length; + + if (node.getAttribute("sorttable_customkey") != null) { + return node.getAttribute("sorttable_customkey"); + } + else if (typeof node.textContent != 'undefined' && !hasInputs) { + return node.textContent.replace(/^\s+|\s+$/g, ''); + } + else if (typeof node.innerText != 'undefined' && !hasInputs) { + return node.innerText.replace(/^\s+|\s+$/g, ''); + } + else if (typeof node.text != 'undefined' && !hasInputs) { + return node.text.replace(/^\s+|\s+$/g, ''); + } + else { + switch (node.nodeType) { + case 3: + if (node.nodeName.toLowerCase() == 'input') { + return node.value.replace(/^\s+|\s+$/g, ''); + } + case 4: + return node.nodeValue.replace(/^\s+|\s+$/g, ''); + break; + case 1: + case 11: + var innerText = ''; + for (var i = 0; i < node.childNodes.length; i++) { + innerText += sorttable.getInnerText(node.childNodes[i]); + } + return innerText.replace(/^\s+|\s+$/g, ''); + break; + default: + return ''; + } + } + }, + + reverse: function(tbody) { + // reverse the rows in a tbody + newrows = []; + for (var i=0; i=0; i--) { + tbody.appendChild(newrows[i]); + } + delete newrows; + }, + + /* sort functions + each sort function takes two parameters, a and b + you are comparing a[0] and b[0] */ + sort_numeric: function(a,b) { + aa = parseFloat(a[0].replace(/[^0-9.-]/g,'')); + if (isNaN(aa)) aa = 0; + bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); + if (isNaN(bb)) bb = 0; + return aa-bb; + }, + sort_alpha: function(a,b) { + if (a[0]==b[0]) return 0; + if (a[0] 0 ) { + var q = list[i]; list[i] = list[i+1]; list[i+1] = q; + swap = true; + } + } // for + t--; + + if (!swap) break; + + for(var i = t; i > b; --i) { + if ( comp_func(list[i], list[i-1]) < 0 ) { + var q = list[i]; list[i] = list[i-1]; list[i-1] = q; + swap = true; + } + } // for + b++; + + } // while(swap) + } +} + +/* ****************************************************************** + Supporting functions: bundled here to avoid depending on a library + ****************************************************************** */ + +// Dean Edwards/Matthias Miller/John Resig + +/* for Mozilla/Opera9 */ +if (document.addEventListener) { + document.addEventListener("DOMContentLoaded", sorttable.init, false); +} + +/* for Internet Explorer */ +/*@cc_on @*/ +/*@if (@_win32) + document.write("