').append($('#' + $settings.containerid).clone()).html(); return result; }
- function ConvertDataStructureToTable() {
- var result = "
"; return result;
- }
- function Export(htmltable) { var excelFile = ""; excelFile += ""; excelFile += '
'; 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
+/*! battatech_excelexport 2014-11-25 */
+!function(a){var b={containerid:null,datatype:"table",dataset:null,columns:null,returnUri:!1,worksheetName:"My Worksheet",encoding:"utf-8"},c=b;a.fn.battatech_excelexport=function(d){function e(){var a=c.datatype.toLowerCase();switch(f(a),a){case"table":l=i(g());break;case"json":l=i(h());break;case"xml":l=i(h());break;case"jqgrid":l=i(h())}return c.returnUri?l:void window.open(l)}function f(b){switch(b){case"table":break;case"json":m=c.dataset;break;case"xml":a(c.dataset).find("row").each(function(){var b={};null!=this.attributes&&this.attributes.length>0&&(a(this.attributes).each(function(){b[this.name]=this.value}),m.push(b))});break;case"jqgrid":a(c.dataset).find("rows > row").each(function(){var b={};null!=this.children&&this.children.length>0&&(a(this.children).each(function(){b[this.tagName]=a(this).text()}),m.push(b))})}}function g(){var b=a("
").append(a("#"+c.containerid).clone()).html();return b}function h(){var b="
";return b+="",a(c.columns).each(function(){1!=this.ishidden&&(b+="",b+=this.headertext,b+=" | ")}),b+="
",b+="",a(m).each(function(d,e){b+="",a(c.columns).each(function(){e.hasOwnProperty(this.datafield)&&1!=this.ishidden&&(b+="",b+=e[this.datafield],b+=" | ")}),b+="
"}),b+="",b+="
"}function i(a){var d="";d+="",d+='
',d+="",d+="",d+="",d+=a.replace(/"/g,"'"),d+="",d+="";var e="data:application/vnd.ms-excel;base64,",f={worksheet:c.worksheetName,table:a};return e+j(k(d,f))}function j(a){return window.btoa(unescape(encodeURIComponent(a)))}function k(a,b){return a.replace(/{(\w+)}/g,function(a,c){return b[c]})}c=a.extend({},b,d);var l,m=[];return e()}}(jQuery);
\ No newline at end of file
diff --git a/src/Gruntfile.js b/src/Gruntfile.js
new file mode 100644
index 0000000..f2d693a
--- /dev/null
+++ b/src/Gruntfile.js
@@ -0,0 +1,39 @@
+module.exports = function (grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: grunt.file.readJSON('package.json')
+ , uglify: {
+ options: {
+ banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
+ },
+ build: {
+ src: 'Scripts/jquery.battatech.excelexport.js',
+ dest: 'Scripts/jquery.battatech.excelexport.min.js'
+ },
+ dist: {
+ src: 'Scripts/jquery.battatech.excelexport.js',
+ dest: '../dist/jquery.battatech.excelexport.min.js'
+ }
+ }
+ , copy: {
+ main: {
+ src: 'Scripts/jquery.battatech.excelexport.js',
+ dest: '../dist/jquery.battatech.excelexport.js'
+ }
+ }
+ , watch: {
+ files: 'Scripts/jquery.battatech.excelexport.js'
+ , tasks: ['uglify']
+ }
+ });
+
+ // Load the plugin that provides the "uglify" task.
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+
+ // Load the plugin that provides the "copy" task.
+ grunt.loadNpmTasks('grunt-contrib-copy');
+
+ // Default task(s).
+ grunt.registerTask('default', ['uglify', 'copy']);
+};
\ No newline at end of file
diff --git a/src/Scripts/jquery.battatech.excelexport.min.js b/src/Scripts/jquery.battatech.excelexport.min.js
index 6a11a10..873b1fe 100644
--- a/src/Scripts/jquery.battatech.excelexport.min.js
+++ b/src/Scripts/jquery.battatech.excelexport.min.js
@@ -1,31 +1,2 @@
-(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 += ""; result += this.headertext; result += " | ";
- }
- }); result += "
"; result += ""; $(gridData).each(function (key, value) {
- result += ""; $($settings.columns).each(function (k, v) {
- if (value.hasOwnProperty(this.datafield)) {
- if (this.ishidden != true) {
- result += ""; result += value[this.datafield]; result += " | ";
- }
- }
- }); result += "
";
- }); result += ""; result += "
"; return result;
- }
- function Export(htmltable) { var excelFile = ""; excelFile += ""; excelFile += '
'; 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
+/*! battatech_excelexport 2014-11-25 */
+!function(a){var b={containerid:null,datatype:"table",dataset:null,columns:null,returnUri:!1,worksheetName:"My Worksheet",encoding:"utf-8"},c=b;a.fn.battatech_excelexport=function(d){function e(){var a=c.datatype.toLowerCase();switch(f(a),a){case"table":l=i(g());break;case"json":l=i(h());break;case"xml":l=i(h());break;case"jqgrid":l=i(h())}return c.returnUri?l:void window.open(l)}function f(b){switch(b){case"table":break;case"json":m=c.dataset;break;case"xml":a(c.dataset).find("row").each(function(){var b={};null!=this.attributes&&this.attributes.length>0&&(a(this.attributes).each(function(){b[this.name]=this.value}),m.push(b))});break;case"jqgrid":a(c.dataset).find("rows > row").each(function(){var b={};null!=this.children&&this.children.length>0&&(a(this.children).each(function(){b[this.tagName]=a(this).text()}),m.push(b))})}}function g(){var b=a("
").append(a("#"+c.containerid).clone()).html();return b}function h(){var b="
";return b+="",a(c.columns).each(function(){1!=this.ishidden&&(b+="",b+=this.headertext,b+=" | ")}),b+="
",b+="",a(m).each(function(d,e){b+="",a(c.columns).each(function(){e.hasOwnProperty(this.datafield)&&1!=this.ishidden&&(b+="",b+=e[this.datafield],b+=" | ")}),b+="
"}),b+="",b+="
"}function i(a){var d="";d+="",d+='
',d+="",d+="",d+="",d+=a.replace(/"/g,"'"),d+="",d+="";var e="data:application/vnd.ms-excel;base64,",f={worksheet:c.worksheetName,table:a};return e+j(k(d,f))}function j(a){return window.btoa(unescape(encodeURIComponent(a)))}function k(a,b){return a.replace(/{(\w+)}/g,function(a,c){return b[c]})}c=a.extend({},b,d);var l,m=[];return e()}}(jQuery);
\ No newline at end of file
diff --git a/src/battatech_excelexport.jquery.json b/src/battatech_excelexport.jquery.json
index cd83eae..5b718dc 100644
--- a/src/battatech_excelexport.jquery.json
+++ b/src/battatech_excelexport.jquery.json
@@ -7,7 +7,7 @@
, "excel"
, "export"
],
- "version": "2.1.1",
+ "version": "2.1.2",
"author": {
"name": "Tarun Batta",
"url": "http://battatech.com/"
diff --git a/src/bower.json b/src/bower.json
index 360046f..06440f8 100644
--- a/src/bower.json
+++ b/src/bower.json
@@ -1,6 +1,6 @@
{
"name": "battatech_excelexport",
- "version": "2.1.1",
+ "version": "2.1.2",
"homepage": "http://battatech.com/blog/how-to-export-to-excel-sheet-on-server-side.aspx",
"authors": [
"Tarun Batta
"
diff --git a/src/package.json b/src/package.json
new file mode 100644
index 0000000..bd61154
--- /dev/null
+++ b/src/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "battatech_excelexport",
+ "version": "2.1.2",
+ "devDependencies":
+ {
+ "grunt": "~0.4.5",
+ "grunt-contrib-uglify": "~0.6.0",
+ "grunt-contrib-copy": "~0.7.0"
+ }
+}
\ No newline at end of file