-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-htmltagrelate-1.0.0.min.js
1 lines (1 loc) · 5.07 KB
/
jquery-htmltagrelate-1.0.0.min.js
1
!function($){function initRelationships(inputVal){var input="undefined"==typeof inputVal.target?inputVal:inputVal.target,that=$(input),i,relatejson=that.data("relatejson"),temp;"undefined"!=typeof fullrelatedesc&&(fullrelatedesc=JSON.stringify(eval("("+relatejson+")")),fullrelatedesc=JSON.parse(relatejson),$.each(relatejson,function(a,b){temp=getRelationshipFromJSON(that,b),null!=temp&&"undefined"!=typeof temp&&Relationships.push(temp)})),"undefined"!=typeof that.data("relate-parent")&&(temp=getRelationshipFromElement(that),null!=temp&&"undefined"!=typeof temp&&Relationships.push(temp)),jQuery.each(Relationships,function(a,b){ProcessRelationship(b)})}function getRelationshipFromJSON(a,b){var c="undefined"==typeof a.target?a:a.target,d=$(c),e=new Object;return e.type="json",e.child=d,e.parent=$(b.relate_parent),e.parentEvent=b.relate_parent_event,e.values=b.relate_values,e.action=b.relate_action,e.attrib=b.relate_attrib,e.attribValueTrue=b.relate_attribvalue_true,e.attribValueFalse=b.relate_attribvalue_false,e.functionTrue=b.relate_function_true,e.functionFalse=b.relate_function_true,e.parentinittrigger=b.relate_parentinittrigger,ValidateRelationship(e)}function getRelationshipFromElement(a){var b="undefined"==typeof a.target?a:a.target,c=$(b),d=new Object;return d.type="html",d.child=c,d.parent=$(c.data("relate-parent")),d.parentEvent=c.data("relate-parent-event"),d.values=c.data("relate-values"),d.action=c.data("relate-action"),d.attrib=c.data("relate-attrib"),d.attribValueTrue=c.data("relate-attribvalue-true"),d.attribValueFalse=c.data("relate-attribvalue-false"),d.functionTrue=c.data("relate-function-true"),d.functionFalse=c.data("relate-function-false"),d.parentinittrigger=c.data("relate-parentinittrigger"),ValidateRelationship(d)}function ValidateRelationship(a){var b=a,c=b.child;return"undefined"==typeof b.parent?(reportError("Relationship is missing parent attribute.",c),null):("undefined"==typeof b.parentEvent&&(b.parentEvent=b.parent.is("input, textarea")?"keyup":"change"),"undefined"!=typeof b.values&&(b.values=getArrayOfString(b.values)),"undefined"==typeof b.action&&b.parent.is("select")&&(b.action="hideoption",b.parentinittrigger="change"),b)}function getArrayOfString(a){var b;b=a.split(",");for(var c=b.length;c<b.length;c++)b[c]=b[c].trim();return b}function ProcessRelationship(a){return null===a?($.error("This relationship is not valid. Below are the details of the relationship."),console.log(a),!0):(a.parent.on(a.parentEvent,function(){var b=-1!==jQuery.inArray($(this).val(),a.values)||"undefined"==typeof a.values;a.parent.is("select")&&(b=!0,a.executedTrue=!1),b&&a.executedTrue===!0||!b&&a.executedTrue===!1||(b?(a.executedTrue=!0,"undefined"!=typeof a.action&&doFriendsAction(a,!1),"undefined"!=typeof a.attribValueTrue&&doFriendsAttributeChange(a,!0),"undefined"!=typeof a.functionTrue&&doFriendsFunction(a,!0)):(a.executedTrue=!1,"undefined"!=typeof a.action&&doFriendsAction(a,!0),"undefined"!=typeof a.attribValueFalse&&doFriendsAttributeChange(a,!1),"undefined"!=typeof a.functionFalse&&doFriendsFunction(a,!1)))}),"undefined"!=typeof a.parentinittrigger&&a.parent.trigger(a.parentinittrigger),void 0)}function reportError(a,b){$.error(a+" ::::: Element ID is #"+b.attr("ID"))}function getElementValue(a){return a.val()}function doFriendsAction(a,b){switch(undo="undefined"!=typeof b?b:!1,a.action){case"hide":undo?a.child.show():a.child.hide();break;case"show":undo?a.child.hide():a.child.show();break;case"disable":case"disabled":undo?a.child.prop("disabled",!1):a.child.prop("disabled",!0);break;case"checked":undo?a.child.prop("checked",!1):a.child.prop("checked",!0);break;case"hideoption":var d;if(null===a.child.data("originalOptions")||"undefined"==typeof a.child.data("originalOptions")){var e=[];a.child.find("option").each(function(){e.push({value:$(this).val(),dataParentValues:$(this).attr("data-parent-values"),text:$(this).text(),isselected:$(this).is(":selected")?!0:!1})}),a.child.data("originalOptions",e)}d=a.child.data("originalOptions").filter(function(b){return-1!==getArrayOfString(b.dataParentValues).indexOf(a.parent.val())}),a.child.find('option[value!="-1"]').remove(),$.each(d,function(b){a.child.append('<option value="'+d[b].value+'" data-parent-values="'+d[b].dataParentValues+'">'+d[b].text+"</option>")})}}function doFriendsAttributeChange(a,b){var c=b?a.attribValueTrue:a.attribValueFalse;a.child.attr(a.attrib,c)}function doFriendsFunction(Relationship,dotrue){eval(dotrue?Relationship.functionTrue:Relationship.functionFalse)}function emptyFunc(){}var Relationships=[],settings;$.fn.htmltagrelate=function(a){return methods[a]?methods[a].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof a&&a?($.error("Method "+a+" does not exist on jQuery.HTMLTagFriend"),void 0):methods.init.apply(this,arguments)};var methods={init:function(a){settings=$.extend({},$.fn.htmltagrelate.defaults,a);var b=$("*[data-relate-parent], *[data-relatejson]");$.each(b,function(){initRelationships(this)})},clearRelationship:function(){return!0},loadRelationship:function(){return!0},getRelationship:function(){return!0},restart:function(){return!0}};$.fn.htmltagrelate.defaults={}}(jQuery);