You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1 lines
2.4 KiB

define(["jquery","core/log","core/str","core/notification"],function(a,b,c,d){var e={FIELDSETCONTAINSADVANCED:"fieldset.containsadvancedelements",DIVFITEMADVANCED:"div.fitem.advanced",DIVFCONTAINER:"div.fcontainer",MORELESSLINK:"fieldset.containsadvancedelements .moreless-toggler"},f={SHOW:"show",MORELESSACTIONS:"moreless-actions",MORELESSTOGGLER:"moreless-toggler",SHOWLESS:"moreless-less"},g={FITEM:'<div class="fitem"></div>',FELEMENT:'<div class="felement"></div>'},h="showadvancedid-",i=0,j=function(b){this.id=b;var c=a(document.getElementById(b));this.enhanceForm(c)};return j.prototype.id="",j.prototype.enhanceForm=function(b){var c=b.find(e.FIELDSETCONTAINSADVANCED);return c.each(function(b,c){this.enhanceFieldset(a(c))}.bind(this)),b.on("click",e.MORELESSLINK,this.switchState),b.on("keydown",e.MORELESSLINK,function(a){return 13!=a.which&&32!=a.which||this.switchState(a)}.bind(this)),this},j.prototype.generateId=function(a){var b=a.prop("id");return"undefined"==typeof b&&(b=h+i++,a.prop("id",b)),b},j.prototype.enhanceFieldset=function(h){var i=a("input[name=mform_showmore_"+h.prop("id")+"]");return i.length?(c.get_strings([{key:"showmore",component:"core_form"},{key:"showless",component:"core_form"}]).then(function(b){var c=b[0],d=b[1],j=a('<a href="#"></a>');j.addClass(f.MORELESSTOGGLER),"0"===i.val()?j.html(c):(j.html(d),j.addClass(f.SHOWLESS),h.find(e.DIVFITEMADVANCED).addClass(f.SHOW));var k=[];h.find(e.DIVFITEMADVANCED).each(function(b,c){k[k.length]=this.generateId(a(c))}.bind(this)),j.attr("role","button"),j.attr("aria-controls",k.join(" "));var l=a(g.FITEM);l.addClass(f.MORELESSACTIONS);var m=a(g.FELEMENT);return m.append(j),l.append(m),h.find(e.DIVFCONTAINER).append(l),!0}.bind(this)).fail(d.exception),this):(b.debug("M.form.showadvanced::processFieldset was called on an fieldset without a status field: '"+h.prop("id")+"'"),this)},j.prototype.switchState=function(b){return b.preventDefault(),c.get_strings([{key:"showmore",component:"core_form"},{key:"showless",component:"core_form"}]).then(function(c){var d=c[0],g=c[1],h=a(b.target).closest(e.FIELDSETCONTAINSADVANCED);h.find(e.DIVFITEMADVANCED).toggleClass(f.SHOW);var i=a("input[name=mform_showmore_"+h.prop("id")+"]");return"0"===i.val()?(i.val(1),a(b.target).addClass(f.SHOWLESS),a(b.target).html(g)):(i.val(0),a(b.target).removeClass(f.SHOWLESS),a(b.target).html(d)),!0}).fail(d.exception),this},{init:function(a){return new j(a)}}});