diff --git a/src/Grid.js b/src/Grid.js index 9aaf7f0..2594767 100644 --- a/src/Grid.js +++ b/src/Grid.js @@ -6,18 +6,28 @@ //////////////////////////////////// (function(window, document, undefined) { "use strict"; - - var GridProto; + + var nothing = function() {}, + jsonData = {}, + sortCache = {}, + ctxArr = [], + visibleData = [], + lastSortedColumn = [-1, null]; var Grid = function(element, options) { if ((this.element = (typeof(element) === "string") ? $(element) : element)) { - this.css = { idRulePrefix : "#" + this.element.id + " ", sheet : null, rules : {} }; + this.css = { + idRulePrefix: "#" + this.element.id + " ", + sheet: null, + rules: {} + }; this.columns = 0; this.columnWidths = []; - this.cellData = { head : [], body : [], foot : [] }; + this.cellData = { + head: [], + body: [], + foot: [] + }; this.alignTimer = null; - this.rawData = []; - this.sortCache = {}; - this.lastSortedColumn = [-1, null]; this.selectedIndexes = []; this.usesTouch = (window.ontouchstart !== undefined); this.startEvt = (this.usesTouch) ? "touchstart" : "mousedown"; @@ -27,41 +37,42 @@ this.init(); } }; - - ////////////////////////////////////////////////////////////////////////////////// - (GridProto = Grid.prototype).nothing = function(){}; - - ////////////////////////////////////////////////////////////////////////////////// + + var GridProto = Grid.prototype; + GridProto.setOptions = function(options) { - var hasOwnProp = Object.prototype.hasOwnProperty, - option; - + var option; + this.options = { - srcType : "", // "dom", "json", "xml" - srcData : "", - allowGridResize : false, - allowColumnResize : false, - allowClientSideSorting : false, - allowSelections : false, - allowMultipleSelections : false, - showSelectionColumn : false, - onColumnSort : this.nothing, - onResizeGrid : this.nothing, - onResizeGridEnd : this.nothing, - onResizeColumn : this.nothing, - onResizeColumnEnd : this.nothing, - onRowSelect : this.nothing, - onLoad : this.nothing, - supportMultipleGridsInView : false, - fixedCols : 0, - selectedBgColor : "#eaf1f7", - fixedSelectedBgColor : "#dce7f0", - colAlign : [], // "left", "center", "right" - colBGColors : [], - colSortTypes : [], // "string", "number", "date", "custom", "none" - customSortCleaner : null + srcType: "", // "dom", "json", "xml" + srcData: "", + allowGridResize: false, + allowColumnResize: false, + allowClientSideSorting: false, + allowSelections: false, + allowMultipleSelections: false, + showSelectionColumn: false, + onColumnSort: nothing, + onResizeGrid: nothing, + onResizeGridEnd: nothing, + onResizeColumn: nothing, + onResizeColumnEnd: nothing, + onRowSelect: nothing, + onLoad: nothing, + fixedCols: 0, + selectedBgColor: "#eaf1f7", + fixedSelectedBgColor: "#dce7f0", + colAlign: [], // "left", "center", "right" + colBGColors: [], + colSortTypes: [], // "string", "number", "date", "custom", "none" + customSortCleaner: null, + autoFoot: false, + footArray: [], + autoHead: false, + headArray: [], + nullValue: '' }; - + if (options) { for (option in this.options) { if (hasOwnProp.call(this.options, option) && options[option] !== undefined) { @@ -69,71 +80,83 @@ } } } - + this.options.allowColumnResize = this.options.allowColumnResize && !this.usesTouch; this.options.allowMultipleSelections = this.options.allowMultipleSelections && this.options.allowSelections; this.options.showSelectionColumn = this.options.showSelectionColumn && this.options.allowSelections; this.options.fixedCols = (!this.usesTouch) ? this.options.fixedCols : 0; }; - - ////////////////////////////////////////////////////////////////////////////////// + + GridProto.rowLength = 0; + GridProto.init = function() { - var srcType = this.options.srcType, - srcData = this.options.srcData, - data; - + var srcType = this.options.srcType, + srcData = this.options.srcData; + this.generateSkeleton(); this.addEvents(); - + // DOM: if (srcType === "dom" && (srcData = (typeof(srcData) === "string") ? $(srcData) : srcData)) { - this.convertData(this.convertDomDataToJsonData(srcData)); - - // JSON: - } else if (srcType === "json" && (data = parseJSON(srcData))) { - this.convertData(data); - - // XML: - } else if (srcType === "xml" && (data = parseXML(srcData))) { - this.convertData(this.convertXmlDataToJsonData(data)); - } - + this.convertData(jsonData = parseJSON.call(this, this.convertDomDataToJsonData(srcData))); + + // JSON: + } else if (srcType === "json" && (jsonData = parseJSON.call(this, srcData))) { + this.convertData(jsonData); + + // XML: + } else if (srcType === "xml" && (jsonData = parseXML(srcData))) { + this.convertData(jsonData = parseJSON.call(this, this.convertXmlDataToJsonData(jsonData))); + } + + this.rowLength = jsonData.Body.length; + visibleData = clone(jsonData.Body); + this.initCtxArr(); this.generateGrid(); this.displayGrid(); }; - - ////////////////////////////////////////////////////////////////////////////////// + + GridProto.initCtxArr = function() { + for (var i = 0; i < jsonData.Body.length; i++) { + ctxArr[i] = jsonData.Body[i].toString(); + } + } + GridProto.generateSkeleton = function() { - var doc = document, - elems = [["base", "g_Base", "docFrag"], - ["head", "g_Head", "base"], - ["headFixed", "g_HeadFixed", "head"], - ["headStatic", "g_HeadStatic", "head"], - ["foot", "g_Foot", "base"], - ["footFixed", "g_FootFixed", "foot"], - ["footStatic", "g_FootStatic", "foot"], - ["body", "g_Body", "base"], - ["bodyFixed", "g_BodyFixed", "body"], - ["bodyFixed2", "g_BodyFixed2", "bodyFixed"], - ["bodyStatic", "g_BodyStatic", "body"]]; - - this.parentDimensions = { x : this.element.offsetWidth, y : this.element.offsetHeight }; + var doc = document, + elems = [ + ["base", "g_Base", "docFrag"], + ["head", "g_Head", "base"], + ["headFixed", "g_HeadFixed", "head"], + ["headStatic", "g_HeadStatic", "head"], + ["foot", "g_Foot", "base"], + ["footFixed", "g_FootFixed", "foot"], + ["footStatic", "g_FootStatic", "foot"], + ["body", "g_Body", "base"], + ["bodyFixed", "g_BodyFixed", "body"], + ["bodyFixed2", "g_BodyFixed2", "bodyFixed"], + ["bodyStatic", "g_BodyStatic", "body"] + ]; + + this.parentDimensions = { + x: this.element.offsetWidth, + y: this.element.offsetHeight + }; this.docFrag = doc.createDocumentFragment(); - for (var i=0, elem; elem=elems[i]; i++) { + for (var i = 0, elem; elem = elems[i]; i++) { (this[elem[0]] = doc.createElement("DIV")).className = elem[1]; this[elem[2]].appendChild(this[elem[0]]); } - + if (this.options.allowGridResize) { (this.baseResize = doc.createElement("DIV")).className = "g_BaseResize"; this.base.appendChild(this.baseResize); } }; - - ////////////////////////////////////////////////////////////////////////////////// + GridProto.addEvents = function() { var wheelEvent; - + // Simulate mouse scrolling over non-scrollable content: if (this.options.fixedCols > 0 && !this.usesTouch && !msie) { try { @@ -145,17 +168,17 @@ addEvent(this.bodyFixed, wheelEvent, bind(this.simulateMouseScroll, this)); } } - + // Grid resizing: if (this.options.allowGridResize) { addEvent(this.baseResize, this.startEvt, bind(this.initResizeGrid, this)); } - + // Column resizing and client side sorting: if (this.options.allowColumnResize || this.options.allowClientSideSorting) { addEvent(this.head, this.startEvt, bind(this.delegateHeaderEvent, this)); } - + // Row selection: if (this.options.allowSelections) { addEvent(this.body, this.startEvt, bind(this.selectRange, this)); @@ -164,52 +187,60 @@ } } }; - - ////////////////////////////////////////////////////////////////////////////////// + GridProto.convertDomDataToJsonData = function(data) { - var sections = { "thead" : "Head", "tbody" : "Body", "tfoot" : "Foot" }, - section, rows, row, cells, arr, arr2, i, j, k, - json = {}; - + var sections = { + "thead": "Head", + "tbody": "Body", + "tfoot": "Foot" + }, + section, rows, row, cells, arr, arr2, i, j, k, + json = {}; + // Cycle through all table rows, change sections when needed: if (((data || {}).tagName || "").toLowerCase() === "table") { - for (i=0, j=0, rows=data.rows; row=rows[i]; i++) { + for (i = 0, j = 0, rows = data.rows; row = rows[i]; i++) { if (row.sectionRowIndex === 0 && (section = sections[row.parentNode.tagName.toLowerCase()])) { json[section] = arr = (json[section] || []); j = arr.length; } arr[j++] = arr2 = []; k = (cells = row.cells).length; - while (k) { arr2[--k] = cells[k].innerHTML; } + while (k) { + arr2[--k] = cells[k].innerHTML; + } } } - + return json; }; - - ////////////////////////////////////////////////////////////////////////////////// + GridProto.convertXmlDataToJsonData = function(data) { - var sections = { "thead" : "Head", "tbody" : "Body", "tfoot" : "Foot" }, - cellText = (msie < 9) ? "text" : "textContent", - nodes, node, section, rows, row, cells, cell, tag, n, i, j, - arr, arr2, a, a2, - json = {}; - + var sections = { + "thead": "Head", + "tbody": "Body", + "tfoot": "Foot" + }, + cellText = (msie < 9) ? "text" : "textContent", + nodes, node, section, rows, row, cells, cell, tag, n, i, j, + arr, arr2, a, a2, + json = {}; + // By section: if ((nodes = (data.getElementsByTagName("table")[0] || {}).childNodes)) { - for (n=0; node=nodes[n]; n++) { + for (n = 0; node = nodes[n]; n++) { if ((section = sections[node.nodeName]) && (rows = node.childNodes)) { json[section] = arr = (json[section] || []); a = arr.length; - + // By row: - for (i=0; row=rows[i]; i++) { + for (i = 0; row = rows[i]; i++) { if (row.nodeName === "tr" && (cells = row.childNodes)) { arr[a++] = arr2 = []; a2 = 0; - + // By cell: - for (j=0; cell=cells[j]; j++) { + for (j = 0; cell = cells[j]; j++) { if ((tag = cell.nodeName) === "td" || tag === "th") { arr2[a2++] = cell[cellText] || ""; } @@ -219,47 +250,61 @@ } } } - + return json; }; - - ////////////////////////////////////////////////////////////////////////////////// + GridProto.convertData = function(data) { var base, cols, h, b, f; - + this.addSelectionColumn(data); - this.rawData = data.Body || []; - if ((base = data.Head || data.Body || data.Foot || null)) { + //this.rawData = data.Body || []; + + if ((base = data.Body || data.Head || data.Foot || null)) { cols = this.columns = base[0].length; h = this.cellData.head; b = this.cellData.body; f = this.cellData.foot; - while (cols) { h[--cols] = []; b[cols] = []; f[cols] = []; } - + while (cols) { + h[--cols] = []; + b[cols] = []; + f[cols] = []; + } + cols = this.columns; if (data.Head) { this.convertDataItem(h, data.Head, "
"; row = rows[rowIdx]; @@ -275,11 +320,10 @@ } } }; - - ////////////////////////////////////////////////////////////////////////////////// + GridProto.addSelectionColumn = function(data) { var html, rows, i; - + if (this.options.showSelectionColumn) { this.options.colBGColors.unshift(this.options.colBGColors[0] || ""); this.options.colSortTypes.unshift("none"); @@ -287,84 +331,86 @@ if (!this.usesTouch) { this.options.fixedCols++; } - + if ((rows = data.Head) && (i = rows.length)) { - while (i) { rows[--i].unshift(""); } + while (i) { + rows[--i].unshift(""); + } } if ((rows = data.Body) && (i = rows.length)) { html = "
"); }, - replaceRgx = /@(\d+)@/g, - fixedCols = this.options.fixedCols, - fHtml = [], sHtml = [], - colIdx = cols.length; - + var replaceFunc = function($1, $2) { + return cols[parseInt($2, 10)].join(""); + }, + replaceRgx = /@(\d+)@/g, + fixedCols = this.options.fixedCols, + fHtml = [], + sHtml = [], + colIdx = cols.length; + while (colIdx) { if ((--colIdx) < fixedCols) { fHtml[colIdx] = "
@" + colIdx + "@
"; @@ -373,22 +419,23 @@ sHtml[colIdx] = "
@" + colIdx + "@
"; } } - - return { fixedHTML : (fixedCols) ? fHtml.join("").replace(replaceRgx, replaceFunc) : "", - fullHTML : sHtml.join("").replace(replaceRgx, replaceFunc) }; + + return { + fixedHTML: (fixedCols) ? fHtml.join("").replace(replaceRgx, replaceFunc) : "", + fullHTML: sHtml.join("").replace(replaceRgx, replaceFunc) + }; }; - - ////////////////////////////////////////////////////////////////////////////////// + GridProto.displayGrid = function() { - var srcType = this.options.srcType, - srcData = this.options.srcData, - replace = false; - + var srcType = this.options.srcType, + srcData = this.options.srcData, + replace = false; + // Setup scrolling: this.lastScrollLeft = 0; this.lastScrollTop = 0; this.body.onscroll = bind(this.syncScrolls, this); - + // Prep style element: try { this.css.sheet.parentNode.removeChild(this.css.sheet); @@ -396,7 +443,7 @@ (this.css.sheet = document.createElement("STYLE")).id = this.element.id + "SS"; this.css.sheet.type = "text/css"; } - + // Insert grid into DOM: if (srcType === "dom" && (srcData = (typeof(srcData) === "string") ? $(srcData) : srcData)) { if ((replace = (this.element === srcData.parentNode))) { @@ -406,47 +453,150 @@ if (!replace) { this.element.appendChild(this.docFrag); } - + // Align columns: this.alignTimer = window.setTimeout(bind(this.alignColumns, this, false, true), 16); }; - - ////////////////////////////////////////////////////////////////////////////////// + + GridProto.hideRow = function(rowIdx) { + var divArr = doc.getElementsByClassName('g_C g_BR g_R' + rowIdx); + setVisible(divArr, 'none'); + } + + GridProto.showRow = function(rowIdx) { + var divArr = doc.getElementsByClassName('g_C g_BR g_R' + rowIdx); + setVisible(divArr, ''); + } + + GridProto.hideRows = function(rowIdxArr) { + for (var i = 0; i < rowIdxArr.length; i++) { + this.hideRow(rowIdxArr[i]); + } + } + + GridProto.showRows = function(rowIdxArr) { + for (var i = 0; i < rowIdxArr.length; i++) { + this.showRow(rowIdxArr[i]); + } + } + + GridProto.hideColumn = function(colIdx) { + var divArr = doc.getElementsByClassName('g_Cl g_Cl' + colIdx); + setVisible(divArr, 'none'); + } + + GridProto.showColumn = function(colIdx) { + var divArr = doc.getElementsByClassName('g_Cl g_Cl' + colIdx); + setVisible(divArr, ''); + } + + GridProto.hideColumns = function(colIdxArr) { + for (var i = 0; i < colIdxArr.length; i++) { + this.hideColumn(colIdxArr[i]); + } + } + + GridProto.showColumns = function(colIdxArr) { + for (var i = 0; i < colIdxArr.length; i++) { + this.showColumn(colIdxArr[i]); + } + } + + GridProto.hideHead = function() { + var divArr = doc.getElementsByClassName('g_C g_HR g_R0'); + setVisible(divArr, 'none'); + } + + GridProto.showHead = function() { + var divArr = doc.getElementsByClassName('g_C g_HR g_R0'); + setVisible(divArr, ''); + } + + GridProto.hideFoot = function() { + var divArr = doc.getElementsByClassName('g_C g_FR g_R0'); + setVisible(divArr, 'none'); + } + + GridProto.showFoot = function() { + var divArr = doc.getElementsByClassName('g_C g_FR g_R0'); + setVisible(divArr, ''); + } + + GridProto.filterSearch = function(searchStr) { + searchStr = trim(searchStr); + var toFilter = clone(jsonData); + if (searchStr != '') { + var strArr = searchStr.split(' '); + var founded = true; + var j = ctxArr.length; + while (--j > -1) { + founded = true; + for (var i = 0; i < strArr.length; i++) { + founded &= (ctxArr[j].indexOf(strArr[i]) != -1); + if (!founded) break; + } + if (!founded) { + toFilter.Body.splice(j, 1); + } + } + } + visibleData = toFilter.Body; + this.rowLength = toFilter.Body.length; + var cols = this.hasBody = this.rowLength > 0 ? toFilter.Body[0].length : 0; + this.convertDataItem(this.cellData.body, visibleData, "
-1)); isCtrlKeyLike = this.usesTouch || isSelCol; - + if (this.usesTouch && this.options.showSelectionColumn && (update = isSelCol)) { stopEvent(event); } @@ -840,14 +1005,14 @@ } } }; - - ////////////////////////////////////////////////////////////////////////////////// + GridProto.updateSelectedIndexes = function(rowIdx, ctrlPressed, shiftPressed) { - var selIndexes = this.selectedIndexes.concat(), - rowIdxSelected = (indexOf(selIndexes, rowIdx) > -1), - toSelect = [], toRemove = [], - startIdx, i, j, len; - + var selIndexes = this.selectedIndexes.concat(), + rowIdxSelected = (indexOf(selIndexes, rowIdx) > -1), + toSelect = [], + toRemove = [], + startIdx, i, j, len; + if (!this.options.allowMultipleSelections || !selIndexes.length || (!ctrlPressed && !shiftPressed)) { toSelect = (rowIdxSelected && selIndexes.length === 1) ? [] : [rowIdx]; toRemove = selIndexes.concat(); @@ -856,18 +1021,24 @@ toRemove = rowIdxSelected ? [rowIdx] : []; } else if (shiftPressed) { if ((startIdx = selIndexes[0]) <= rowIdx) { - for (i=startIdx + 1, j=0; i<=rowIdx; i++) { - if (indexOf(selIndexes, i) === -1) { toSelect[j++] = i; } + for (i = startIdx + 1, j = 0; i <= rowIdx; i++) { + if (indexOf(selIndexes, i) === -1) { + toSelect[j++] = i; + } } } else { - for (i=startIdx - 1, j=0; i>=rowIdx; i--) { - if (indexOf(selIndexes, i) === -1) { toSelect[j++] = i; } + for (i = startIdx - 1, j = 0; i >= rowIdx; i--) { + if (indexOf(selIndexes, i) === -1) { + toSelect[j++] = i; + } } } } - - for (i=0, len=toRemove.length; i -1) { selIndexes.splice(j, 1); } + + for (i = 0, len = toRemove.length; i < len; i++) { + if ((j = indexOf(selIndexes, toRemove[i])) > -1) { + selIndexes.splice(j, 1); + } } this.selectedIndexes = selIndexes.concat(toSelect); this.highlightRows(toSelect, toRemove); @@ -876,50 +1047,56 @@ } this.options.onRowSelect.apply(this, [toSelect, toRemove, rowIdx]); }; - - ////////////////////////////////////////////////////////////////////////////////// + GridProto.highlightRows = function(toSelect, toRemove) { - var nodes = [this.bodyFixed2.children, this.bodyStatic.children], - fixedSelBgColor = this.options.fixedSelectedBgColor, - selBgColor = this.options.selectedBgColor, - fixedCols = this.options.fixedCols, - colIdx = this.columns, - bgColor, rows, inputs, i; - + var nodes = [this.bodyFixed2.children, this.bodyStatic.children], + fixedSelBgColor = this.options.fixedSelectedBgColor, + selBgColor = this.options.selectedBgColor, + fixedCols = this.options.fixedCols, + colIdx = this.columns, + bgColor, rows, inputs, i; + while (colIdx) { rows = (((--colIdx) < fixedCols) ? nodes[0] : nodes[1])[colIdx].children; bgColor = (colIdx < fixedCols) ? fixedSelBgColor : selBgColor; - + i = toRemove.length; - while (i) { rows[toRemove[--i]].style.backgroundColor = ""; } - + while (i) { + rows[toRemove[--i]].style.backgroundColor = ""; + } + i = toSelect.length; - while (i) { rows[toSelect[--i]].style.backgroundColor = bgColor; } + while (i) { + rows[toSelect[--i]].style.backgroundColor = bgColor; + } } if (this.options.showSelectionColumn) { inputs = nodes[(!this.usesTouch) ? 0 : 1][0].getElementsByTagName("INPUT"); - + i = toRemove.length; - while (i) { inputs[toRemove[--i]].checked = false; } - + while (i) { + inputs[toRemove[--i]].checked = false; + } + i = toSelect.length; - while (i) { inputs[toSelect[--i]].checked = true; } + while (i) { + inputs[toSelect[--i]].checked = true; + } } }; - - ////////////////////////////////////////////////////////////////////////////////// + GridProto.preventSelectionInputStateChange = function(event) { - var event = event || window.event, - target = event.target || event.srcElement, - targetClass = target.className || "", - rowIdx; - + var event = event || window.event, + target = event.target || event.srcElement, + targetClass = target.className || "", + rowIdx; + if (event.button !== 2) { if (targetClass.indexOf("g_Cb") > -1 || targetClass.indexOf("g_Rd") > -1) { do { targetClass = (target = target.parentNode).className || ""; } while (targetClass.indexOf("g_BR") === -1 && targetClass !== "g_Body"); - + if (targetClass.indexOf("g_BR") > -1) { rowIdx = parseInt(/g_R(\d+)/.exec(targetClass)[1], 10); (event.target || event.srcElement).checked = (indexOf(this.selectedIndexes, rowIdx) > -1); @@ -927,50 +1104,124 @@ } } }; - - ////////////////////////////////////////////////////////////////////////////////// - GridProto.cleanUp = function() { - this.alignTimer = (this.alignTimer) ? window.clearTimeout(this.alignTimer) : null; - this.element.innerHTML = ""; - try { this.css.sheet.parentNode.removeChild(this.css.sheet); } catch (e) {} - return null; - }; - - ////////////////////////////////// - // - // Utility Methods - // - ////////////////////////////////////////////////////////////////////////////////// - var getIEVersion = function() { - var nav, version; - - if ((nav = navigator).appName === "Microsoft Internet Explorer") { - if (new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})").exec(nav.userAgent)) { - version = parseFloat(RegExp.$1); + + var clone = function(ori) { + var objClone; + if (typeof ori !== 'object') objClone = ori; + else { + objClone = ori && new ori.constructor(); + for (var key in ori) { + if (typeof(ori[key]) !== 'object') { + objClone[key] = ori[key]; + } else { + objClone[key] = clone(ori[key]); + } } } - return (version > 5) ? version : undefined; + return objClone; }; - - ////////////////////////////////////////////////////////////////////////////////// + + var trim = function(str) {   + return str.replace(/(^\s*)|(\s*$)/g, "");   + } + + var setVisible = function(divArr, style) { + for (var i = 0, len = divArr.length; i < len; i++) { + divArr[i].style.display = style; + } + } + var parseJSON = function(source) { - var sourceType, json, win; - + var sourceType, json, win, k = 0, + obj = {}; + if ((sourceType = typeof(source)) === "string") { if (((win = window).JSON || {}).parse) { json = win.JSON.parse(source); } else { - json = (function() { try { return (new Function("return " + source))(); } catch (e) { return; } })(); + json = (function() { + try { + return (new Function("return " + source))(); + } catch (e) { + return; + } + })(); } + } else { + json = source; } - - return json || (sourceType === "object" && (json = source)) || null; + //non-formatable object + if (!hasOwnProp.call(json, 'Body')) { + if (this.options.autoHead) { + fillHeadorFoot(obj, json, 'Head', this.options.headArray); + } + obj.Body = []; + for (var i = 0, len = json.length; i < len; i++) { + obj.Body[i] = []; + k = 0; + for (var p in json[i]) { + obj.Body[i][k] = json[i][p]; + k++; + } + } + if (this.options.autoFoot) { + fillHeadorFoot(obj, json, 'Foot', this.options.footArray); + } + json = obj; + } else { + if (this.options.autoHead) { + json.Head = [ + [] + ]; + json.Head[0] = this.options.headArray; + } + if (this.options.autoFoot) { + json.Foot = [ + [] + ]; + //json.Foot[0] = this.options.footArray; + for (var i = 0; i < this.options.footArray.length; i++) { + if (typeof(this.options.footArray[i]) === 'function') { + json.Foot[0][i] = this.options.footArray[i](visibleData); + } else { + json.Foot[0][i] = this.options.footArray[i]; + } + } + } + } + + return json || null; }; - - ////////////////////////////////////////////////////////////////////////////////// + + var addHeadorFoot = function() { + + } + + var fillHeadorFoot = function(obj, json, prop, arr) { + obj[prop] = [ + [] + ]; + var k = 0; + if (arr.length > 0) { + //obj[prop][0] = arr; + for (var i = 0; i < arr.length; i++) { + if (typeof(arr[i]) === 'function') { + obj[prop][0][i] = arr[i](visibleData); + } else { + obj[prop][0][i] = arr[i]; + } + } + } else { + for (var p in json[0]) { + obj[prop][0][k] = p; + k++; + } + } + } + var parseXML = function(source) { var sourceType, dE, xml; - + if ((sourceType = typeof(source)) === "string") { if (window.DOMParser) { xml = new DOMParser().parseFromString(source, "text/xml"); @@ -985,16 +1236,16 @@ xml = source; } } - + return xml || null; }; - - ////////////////////////////////////////////////////////////////////////////////// - var addEvent = (document.addEventListener) ? - function(elem, type, listener) { elem.addEventListener(type, listener, false); } : - function(elem, type, listener) { elem.attachEvent("on" + type, listener); }; - - ////////////////////////////////////////////////////////////////////////////////// + + var addEvent = (document.addEventListener) ? function(elem, type, listener) { + elem.addEventListener(type, listener, false); + } : function(elem, type, listener) { + elem.attachEvent("on" + type, listener); + }; + var stopEvent = function(event) { if (event.stopPropagation) { event.stopPropagation(); @@ -1005,60 +1256,90 @@ } return false; }; - - ////////////////////////////////////////////////////////////////////////////////// - var removeEvent = (document.addEventListener) ? - function(elem, type, listener) { elem.removeEventListener(type, listener, false); } : - function(elem, type, listener) { elem.detachEvent("on" + type, listener); }; - - ////////////////////////////////////////////////////////////////////////////////// + + var removeEvent = (document.addEventListener) ? function(elem, type, listener) { + elem.removeEventListener(type, listener, false); + } : function(elem, type, listener) { + elem.detachEvent("on" + type, listener); + }; + var getEventPositions = function(event, type) { - var pageX = event.pageX, - pageY = event.pageY, - doc, elem; - + var pageX = event.pageX, + pageY = event.pageY, + doc, elem; + // Client position: if (type === "client") { if (pageX !== undefined || pageY !== undefined) { - return { x : pageX - window.pageXOffset, y : pageY - window.pageYOffset }; + return { + x: pageX - window.pageXOffset, + y: pageY - window.pageYOffset + }; } - return { x : event.clientX, y : event.clientY }; + return { + x: event.clientX, + y: event.clientY + }; } - + // Page position: if (pageX === undefined || pageY === undefined) { elem = ((doc = document).documentElement.scrollLeft !== undefined) ? doc.documentElement : doc.body; - return { x : event.clientX + elem.scrollLeft, y : event.clientY + elem.scrollTop }; + return { + x: event.clientX + elem.scrollLeft, + y: event.clientY + elem.scrollTop + }; } - return { x : pageX, y : pageY }; + return { + x: pageX, + y: pageY + }; }; - - ////////////////////////////////////////////////////////////////////////////////// + var bind = function(func, that) { var a = slice.call(arguments, 2); - return function() { return func.apply(that, a.concat(slice.call(arguments))); }; + return function() { + return func.apply(that, a.concat(slice.call(arguments))); + }; }; - - ////////////////////////////////////////////////////////////////////////////////// - var indexOf = ([].indexOf) ? - function(arr, item) { return arr.indexOf(item); } : - function(arr, item) { - for (var i=0, len=arr.length; i 5) ? version : undefined; + }(), + slice = Array.prototype.slice, + hasOwnProp = Object.prototype.hasOwnProperty; + + window.Grid = Grid; +})(window, document); \ No newline at end of file