YadaWeb/src/main/resources/net/yadaframework/views/yada/js/yada.ajax.js
/**
	 * 
	 * @param $element the link or the form
	 * @param responseHtml jquery object received from the ajax call
	 * @returns the jQuery HTML that has been added to the page, which will be a clone 
	 *		    of responseHtml or the original responseHtml when no update has been made.
	 *		    In case of multiple replacements, an array will be returned.
	 */
@param $element the link or the form
@param responseHtml jquery object received from the ajax call
@returns the jQuery HTML that has been added to the page, which will be a clone
of responseHtml or the original responseHtml when no update has been made.
In case of multiple replacements, an array will be returned.
@param $element the link or the form @param responseHtml jquery object received from the ajax call @returns the jQuery HTML that has been added to the page which will be a clone of responseHtml or the original responseHtml when no update has been made . In case of multiple replacements an array will be returned .
function updateOnSuccess($element, responseHtml) {
		var updateSelector = $element.attr("data-yadaUpdateOnSuccess");
		if (updateSelector == null) {
			return responseHtml;
		}
		var $replacement = responseHtml.children().clone(true, true); 
		var $return = $replacement;
		var selectors = updateSelector.split(',');
		var $replacementArray = null;
		if (selectors.length>1) {
			$replacementArray = $(".yadaFragment", responseHtml);
			if ($replacementArray.length==0) {
				$replacementArray = $("._yadaReplacement_", responseHtml); 
			}
		}
		if ($replacementArray!=null && $replacementArray.length>1) {
			$return = [];
		}
		var fragmentCount = 0;
		for (var count=0; count<selectors.length; count++) {
			var selector = selectors[count];
			if ($replacementArray!=null && $replacementArray.length>0) {
				$replacement = $replacementArray.eq(fragmentCount).clone(true, true);
				if (count==0 && $replacementArray.length==1) {
					$return = $replacement;
				} else {
					$return.push($replacement);
				}
				fragmentCount = (fragmentCount+1) % $replacementArray.length;
			}
			yada.extendedSelect($element, selector).replaceWith($replacement);
		}
		return $return;
	}
function updateOnSuccess ( $element , responseHtml ) { var updateSelector = $element . attr ( "data-yadaUpdateOnSuccess" ) ; if ( updateSelector == null ) { return responseHtml ; } var $replacement = responseHtml . children ( ) . clone ( true , true ) ; var $return = $replacement ; var selectors = updateSelector . split ( ',' ) ; var $replacementArray = null ; if ( selectors . length > 1 ) { $replacementArray = $ ( ".yadaFragment" , responseHtml ) ; if ( $replacementArray . length == 0 ) { $replacementArray = $ ( "._yadaReplacement_" , responseHtml ) ; } } if ( $replacementArray != null && $replacementArray . length > 1 ) { $return = [ ] ; } var fragmentCount = 0 ; for ( var count = 0 ; count < selectors . length ; count ++ ) { var selector = selectors [ count ] ; if ( $replacementArray != null && $replacementArray . length > 0 ) { $replacement = $replacementArray . eq ( fragmentCount ) . clone ( true , true ) ; if ( count == 0 && $replacementArray . length == 1 ) { $return = $replacement ; } else { $return . push ( $replacement ) ; } fragmentCount = ( fragmentCount + 1 ) % $replacementArray . length ; } yada . extendedSelect ( $element , selector ) . replaceWith ( $replacement ) ; } return $return ; }
@param $element the link or the form
 @param responseHtml jquery object received from the ajax call
 @returns the jQuery HTML that has been added to the page, which will be a clone
                  of responseHtml or the original responseHtml when no update has been made.
@param $element the link or the form @param responseHtml jquery object received from the ajax call @returns the jQuery HTML that has been added to the page which will be a clone of responseHtml or the original responseHtml when no update has been made .
// If "yadaUpdateOnSuccess" is set, replace its target; if it's empty, replace the original link.
 // The target can be a parent when the css selector starts with parentSelector (currently "yadaParents:").
 // The selector can be multiple, separated by comma. The replacement can be multiple, identified by yadaFragment
 // Clone so that the original responseHtml is not removed by replaceWith.
 // All handlers are also cloned.
 // Uso .children() per skippare il primo div inserito da yada.ajax()
 // yadaFragment is used only when there is more than one selector, otherwise the whole result is used for replacement
 // Legacy
 // Clone so that the original responseHtml is not removed by replaceWith.
 // All handlers are also cloned.
 // When there are more selectors than fragments, fragments are cycled from the first one
 //				if (selector == "") {
 //					// 
 //					$element.replaceWith($replacement);
 //				} else {
 //					var fromParents = yada.startsWith(selector, parentSelector); // yadaParents:
 //					var fromSiblings = yada.startsWith(selector, siblingSelector); // yadaSiblings:
 //					var fromClosestFind = yada.startsWith(selector, closestFindSelector); // yadaClosestFind:
 //					if (fromParents==false && fromSiblings==false && fromClosestFind==false) {
 //						var $oldElement = $(selector);
 //						$oldElement.replaceWith($replacement);
 //					} else if (fromParents) {
 //						selector = selector.replace(parentSelector, "").trim();
 //						$element.parent().closest(selector).replaceWith($replacement);
 //					} else if (fromSiblings) {
 //						selector = selector.replace(siblingSelector, "").trim();
 //						$element.siblings(selector).replaceWith($replacement);
 //					} else if (fromClosestFind) {
 //						selector = selector.replace(closestFindSelector, "").trim();
 //						var splitSelector = selector.split(" ", 2);
 //						$element.closest(splitSelector[0]).find(splitSelector[1]).replaceWith($replacement);
 //					}
 //				}
 // Not needed  because handlers are initialized before entering this method, then cloned
 // yada.initHandlersOn($replacement);
