From 319129d02fb856d0af2d7327f060ff8d3e52c3d5 Mon Sep 17 00:00:00 2001 From: Tarun Batta Date: Tue, 25 Nov 2014 14:42:26 -0800 Subject: [PATCH] added dist folder --- .gitignore | 1 - dist/jquery.battatech.excelexport.js | 180 +++++++++++++++++++++++ dist/jquery.battatech.excelexport.min.js | 31 ++++ 3 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 dist/jquery.battatech.excelexport.js create mode 100644 dist/jquery.battatech.excelexport.min.js diff --git a/.gitignore b/.gitignore index 299654e..3a405d1 100644 --- a/.gitignore +++ b/.gitignore @@ -198,7 +198,6 @@ $RECYCLE.BIN/ # Packages *.egg *.egg-info -dist/ build/ eggs/ parts/ diff --git a/dist/jquery.battatech.excelexport.js b/dist/jquery.battatech.excelexport.js new file mode 100644 index 0000000..818aaaf --- /dev/null +++ b/dist/jquery.battatech.excelexport.js @@ -0,0 +1,180 @@ +/* + * jQuery Client Side Excel Export Plugin Library + * http://www.battatech.com/ + * + * Copyright (c) 2013 Batta Tech Private Limited + * Licensed under https://github.com/battatech/battatech_excelexport/blob/master/LICENSE.txt + */ + +(function ($) { + var $defaults = { + containerid: null + , datatype: 'table' + , dataset: null + , columns: null + , returnUri: false + , worksheetName: "My Worksheet" + , encoding: "utf-8" + }; + + var $settings = $defaults; + + $.fn.battatech_excelexport = function (options) { + $settings = $.extend({}, $defaults, options); + + var gridData = []; + var excelData; + + return Initialize(); + + function Initialize() { + var type = $settings.datatype.toLowerCase(); + + BuildDataStructure(type); + + switch (type) { + case 'table': + excelData = Export(ConvertFromTable()); + break; + case 'json': + excelData = Export(ConvertDataStructureToTable()); + break; + case 'xml': + excelData = Export(ConvertDataStructureToTable()); + break; + case 'jqgrid': + excelData = Export(ConvertDataStructureToTable()); + break; + } + + if ($settings.returnUri) { + return excelData; + } + else { + window.open(excelData); + } + } + + function BuildDataStructure(type) { + switch (type) { + case 'table': + break; + case 'json': + gridData = $settings.dataset; + break; + case 'xml': + $($settings.dataset).find("row").each(function (key, value) { + var item = {}; + + if (this.attributes != null && this.attributes.length > 0) { + $(this.attributes).each(function () { + item[this.name] = this.value; + }); + + gridData.push(item); + } + }); + break; + case 'jqgrid': + $($settings.dataset).find("rows > row").each(function (key, value) { + var item = {}; + + if (this.children != null && this.children.length > 0) { + $(this.children).each(function () { + item[this.tagName] = $(this).text(); + }); + + gridData.push(item); + } + }); + break; + } + } + + function ConvertFromTable() { + var result = $('
').append($('#' + $settings.containerid).clone()).html(); + return result; + } + + function ConvertDataStructureToTable() { + var result = ""; + + result += ""; + $($settings.columns).each(function (key, value) { + if (this.ishidden != true) { + result += "'; + excelFile += ""; + excelFile += " "; + excelFile += ""; + excelFile += htmltable.replace(/"/g, '\''); + excelFile += ""; + excelFile += ""; + + var uri = "data:application/vnd.ms-excel;base64,"; + var ctx = { worksheet: $settings.worksheetName, table: htmltable }; + + return (uri + base64(format(excelFile, ctx))); + } + + function base64(s) { + return window.btoa(unescape(encodeURIComponent(s))); + } + + function format(s, c) { + return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }); + } + }; +})(jQuery); diff --git a/dist/jquery.battatech.excelexport.min.js b/dist/jquery.battatech.excelexport.min.js new file mode 100644 index 0000000..6a11a10 --- /dev/null +++ b/dist/jquery.battatech.excelexport.min.js @@ -0,0 +1,31 @@ +(function ($) { + var $defaults = { containerid: null, datatype: 'table', dataset: null, columns: null, returnUri: false, worksheetName: "My Worksheet", encoding: "utf-8" }; var $settings = $defaults; $.fn.battatech_excelexport = function (options) { + $settings = $.extend({}, $defaults, options); var gridData = []; var excelData; return Initialize(); function Initialize() { + var type = $settings.datatype.toLowerCase(); BuildDataStructure(type); switch (type) { case 'table': excelData = Export(ConvertFromTable()); break; case 'json': excelData = Export(ConvertDataStructureToTable()); break; case 'xml': excelData = Export(ConvertDataStructureToTable()); break; case 'jqgrid': excelData = Export(ConvertDataStructureToTable()); break; } + if ($settings.returnUri) { return excelData; } + else { window.open(excelData); } + } + function BuildDataStructure(type) { switch (type) { case 'table': break; case 'json': gridData = $settings.dataset; break; case 'xml': $($settings.dataset).find("row").each(function (key, value) { var item = {}; if (this.attributes != null && this.attributes.length > 0) { $(this.attributes).each(function () { item[this.name] = this.value; }); gridData.push(item); } }); break; case 'jqgrid': $($settings.dataset).find("rows > row").each(function (key, value) { var item = {}; if (this.children != null && this.children.length > 0) { $(this.children).each(function () { item[this.tagName] = $(this).text(); }); gridData.push(item); } }); break; } } + function ConvertFromTable() { var result = $('
').append($('#' + $settings.containerid).clone()).html(); return result; } + function ConvertDataStructureToTable() { + var result = "
"; result += ""; $($settings.columns).each(function (key, value) { + if (this.ishidden != true) { + result += "'; excelFile += ""; excelFile += " "; excelFile += ""; excelFile += htmltable.replace(/"/g, '\''); excelFile += ""; excelFile += ""; var uri = "data:application/vnd.ms-excel;base64,"; var ctx = { worksheet: $settings.worksheetName, table: htmltable }; return (uri + base64(format(excelFile, ctx))); } + function base64(s) { return window.btoa(unescape(encodeURIComponent(s))); } + function format(s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }); } + }; +})(jQuery); \ No newline at end of file