From 2ddda2602fc2cb02e7281d8bd8f5cd810f27bc08 Mon Sep 17 00:00:00 2001 From: RIGAUDIE David Date: Mon, 30 May 2016 21:37:38 +0200 Subject: [PATCH] Add callback event --- demo.html | 2 ++ dynatab.js | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/demo.html b/demo.html index 2dd1d2e..100f614 100644 --- a/demo.html +++ b/demo.html @@ -34,6 +34,7 @@ dynatab.ajaxType = 'GET'; dynatab.prefixIdTab = 'css'; dynatab.contentId = 'content-search-css'; + dynatab.callback = function(){alert('Click done!')}; var idGenerated = Math.round(Math.random() * (9999 - 1) + 1); dynatab.createTab( 'list__table1', @@ -52,6 +53,7 @@ dynatab.ajaxType = 'GET'; dynatab.prefixIdTab = 'css'; dynatab.contentId = 'content-search-css'; + dynatab.callback = function(){}; var idGenerated = Math.round(Math.random() * (9999 - 1) + 1); dynatab.createTab( 'list__table2', diff --git a/dynatab.js b/dynatab.js index e8cfcb9..3f55568 100644 --- a/dynatab.js +++ b/dynatab.js @@ -1,10 +1,9 @@ /*! * Dynamic tab management for foundation 5 - * - * https://github.com/general03/dynatab.git + * http://github.com/general03 * * @author RIGAUDIE David - * @version 0.0.1 + * @version 0.1.0 */ (function (global) { @@ -18,6 +17,7 @@ dynatab.contentId = 'content'; dynatab.ajaxType = 'POST'; dynatab.prefixIdTab = ''; + dynatab.callback = function(){}; /* * Public methods @@ -26,16 +26,16 @@ // Create Tab dynatab.createTab = function (tabClass, contentClass, textContentTab, urlAjax, dataAjax) { $.ajax( - { + { url : urlAjax, data: dataAjax, type: dynatab.ajaxType - }).done(function( data ) { - - $('.'+contentClass+' section').removeClass('active'); + }).done(function( data ) { + $('.'+contentClass+' section').removeClass('active'); $('.'+contentClass).append(data); + // var idTable = dynatab.prefixIdTab + '-' + dataAjax["id-tab-section"]; var liContent = $('
  • ') @@ -65,7 +65,8 @@ } }); - }).fail(function(e){console.log(e)}); + dynatab.callback(); + }).fail(function(e){console.log(e)}); }; @@ -73,3 +74,4 @@ global.dynatab = dynatab; }(window)); +