Created
July 7, 2015 18:02
-
-
Save bologer/395108a5183ce3798adc to your computer and use it in GitHub Desktop.
createNewAdmin jQuery script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This function is operatin with tables. | |
* It created opens up new form after the row | |
* that is being cliked. It slideToggles each | |
* of the active tr (if required) and removes | |
* name="" attribute if it is required. | |
*/ | |
function createServerAdmin($this) { | |
// Element that is bein clicked | |
var thiz = $this; | |
// slideToggle elements | |
$('.open-form-' + thiz.attr('data-openid')).slideToggle(800); | |
$('.open-form-' + thiz.attr('data-openid')).find('td div.height-block').slideToggle({ | |
duration: 600, | |
complete: function() { | |
$('.open-form-' + thiz.attr('data-openid')).find('input, select').each(function() { | |
if( $(this).attr('data-name') ) { | |
$(this).attr('name', $(this).attr('data-name') ); | |
$(this).removeAttr('data-name'); // Remove data-name="" | |
} else { | |
$(this).attr('data-name', $(this).attr('name') ); | |
$(this).removeAttr('name'); // Remove name="" | |
} | |
}); | |
} | |
}); | |
// Remove any other, already opened tr and apply slidetoggle as well | |
thiz.closest('tbody').find('tr.hidden_form').each(function(index, element) { | |
var $this = $(this); | |
$(this).attr('data-id', index + 1); // add id to every div | |
/* | |
This if() statement is checking if | |
css value of tr is eqaul to 'table-row' and | |
==== Explanation: ==== | |
Value: $('.open-form-' + thiz.attr('data-openid')).attr('data-id') | |
Explanation: This value is taking '.open-form' and taking thiz value, which is $this (from the initial function) | |
and getting data-openid="" value from each tr and then taking attr('data-id') and checking whether this | |
is not equal to $(this).attr('data-id') value. (This is made on purpose, because otherwise we will close | |
active tr element.) | |
*/ | |
if( ( $(this).css('display') == 'table-row' ) && ( int_( $('.open-form-' + thiz.attr('data-openid')).attr('data-id') ) != int_( $(this).attr('data-id') ) ) ) { | |
// Toggling elements | |
$(this).slideToggle(700); | |
$(this).find('td div.height-block').slideToggle({ | |
duration: 600, // Duiration of the animation | |
complete: function() { // Complete function of the slideToggle event | |
// This console log is finding previously closed tr and gets it's data-id="" value | |
console.log( $(this).closest('tr').attr('data-id') ); | |
// Defined previously found tr | |
$prev_closed_tr = $(this).closest('tr').attr('data-id'); | |
// Check each input of the specified tr (data-id="") value | |
$('.open-form-' + $prev_closed_tr).find('input, select').each(function() { | |
// If input has name="" values, create face data-name value and remove actual name="" | |
if( $(this).attr('name') ) { | |
$(this).attr('data-name', $(this).attr('name') ); | |
$(this).removeAttr('name'); // Remove name="" | |
} else { | |
// Do the oposite from the root if() | |
$(this).attr('name', $(this).attr('data-name') ); | |
$(this).removeAttr('data-name'); // Remove data-name="" | |
} | |
// end of the each() event (each of the input type ) | |
}); | |
// end of the complete function | |
} | |
// end toggleSlide event | |
}); | |
// end of the if statement | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment