if(window.jQuery===undefined){throw new Error('The jQuery library is not loaded. The Winter CMS framework cannot be initialized.');}if(window.jQuery.request!==undefined){throw new Error('The Winter CMS framework is already loaded.');}+function($){"use strict";var Request=function(element,handler,options){var $el=this.$el=$(element);this.options=options||{};if(handler===undefined){throw new Error('The request handler name is not specified.')}if(!handler.match(/^(?:\w+\:{2})?on*/)){throw new Error('Invalid handler name. The correct handler name format is: "onEvent".')}var $form=options.form?$(options.form):$el.closest('form'),$triggerEl=!!$form.length?$form:$el,context={handler:handler,options:options} if((options.browserValidate!==undefined)&&typeof document.createElement('input').reportValidity=='function'&&$form&&$form[0]&&!$form[0].checkValidity()){$form[0].reportValidity();return false;}$el.trigger('ajaxSetup',[context]) var _event=jQuery.Event('oc.beforeRequest') $triggerEl.trigger(_event,context) if(_event.isDefaultPrevented())return var loading=options.loading!==undefined?options.loading:null,url=options.url!==undefined?options.url:window.location.href,isRedirect=options.redirect!==undefined&&options.redirect.length,useFlash=options.flash!==undefined,useFiles=options.files!==undefined if(useFiles&&typeof FormData==='undefined'){console.warn('This browser does not support file uploads via FormData') useFiles=false}if($.type(loading)=='string'){loading=$(loading)}var requestHeaders={'X-WINTER-REQUEST-HANDLER':handler,'X-WINTER-REQUEST-PARTIALS':this.extractPartials(options.update)} if(useFlash){requestHeaders['X-WINTER-REQUEST-FLASH']=1}var csrfToken=getXSRFToken() if(csrfToken){requestHeaders['X-XSRF-TOKEN']=csrfToken}var requestData,inputName,data={} $.each($el.parents('[data-request-data]').toArray().reverse(),function extendRequest(){$.extend(data,paramToObj('data-request-data',$(this).data('request-data')))}) if($el.is(':input')&&!$form.length){inputName=$el.attr('name') if(inputName!==undefined&&options.data[inputName]===undefined){options.data[inputName]=$el.val()}}if(options.data!==undefined&&!$.isEmptyObject(options.data)){$.extend(data,options.data)}var requestParentData=$form.getRequestParentData() if(useFiles){requestData=new FormData() $.each(requestParentData,function(key){if(Array.isArray(this)){for(let i=0;i0){var _event=jQuery.Event('ajaxInvalidField') $(window).trigger(_event,[fieldElement.get(0),fieldName,fieldMessages,isFirstInvalidField]) if(isFirstInvalidField){if(!_event.isDefaultPrevented())fieldElement.focus() isFirstInvalidField=false}}})},handleFlashMessage:function(message,type){},handleRedirectResponse:function(url){$el.trigger('ajaxRedirected') window.location.assign(url)},handleUpdateResponse:function(data,textStatus,jqXHR){var updatePromise=$.Deferred().done(function(){for(var partial in data){var selector=(options.update[partial])?options.update[partial]:partial if($.type(selector)=='string'&&selector.charAt(0)=='@'){$(selector.substring(1)).append(data[partial]).trigger('ajaxUpdate',[context,data,textStatus,jqXHR])}else if($.type(selector)=='string'&&selector.charAt(0)=='^'){$(selector.substring(1)).prepend(data[partial]).trigger('ajaxUpdate',[context,data,textStatus,jqXHR])}else if($.type(selector)=='string'&&(selector.charAt(0)=='#'||selector.charAt(0)=='.')){$(selector).trigger('ajaxBeforeReplace') $(selector).html(data[partial]).trigger('ajaxUpdate',[context,data,textStatus,jqXHR])}}setTimeout(function(){$(window).trigger('ajaxUpdateComplete',[context,data,textStatus,jqXHR]).trigger('resize')},0)}) if(data['X_WINTER_REDIRECT']){options.redirect=data['X_WINTER_REDIRECT'] isRedirect=true}if(isRedirect){requestOptions.handleRedirectResponse(options.redirect)}if(data['X_WINTER_ERROR_FIELDS']){requestOptions.handleValidationMessage(data['X_WINTER_ERROR_MESSAGE'],data['X_WINTER_ERROR_FIELDS'])}if(data['X_WINTER_ASSETS']){assetManager.load(data['X_WINTER_ASSETS'],$.proxy(updatePromise.resolve,updatePromise))}else{updatePromise.resolve()}return updatePromise}} if(useFiles){requestOptions.processData=requestOptions.contentType=false}context.success=requestOptions.success context.error=requestOptions.error context.complete=requestOptions.complete requestOptions=$.extend(requestOptions,options) requestOptions.data=requestData if(options.confirm&&!requestOptions.handleConfirmMessage(options.confirm)){return}if(loading)loading.show() $(window).trigger('ajaxBeforeSend',[context]) $el.trigger('ajaxPromise',[context]) return $.ajax(requestOptions).fail(function(jqXHR,textStatus,errorThrown){if(!isRedirect){$el.trigger('ajaxFail',[context,textStatus,jqXHR])}if(loading)loading.hide()}).done(function(data,textStatus,jqXHR){if(!isRedirect){$el.trigger('ajaxDone',[context,data,textStatus,jqXHR])}if(loading)loading.hide()}).always(function(dataOrXhr,textStatus,xhrOrError){$el.trigger('ajaxAlways',[context,dataOrXhr,textStatus,xhrOrError])})} Request.DEFAULTS={update:{},type:'POST',beforeUpdate:function(data,textStatus,jqXHR){},evalBeforeUpdate:null,evalSuccess:null,evalError:null,evalComplete:null,ajaxGlobal:false} Request.prototype.extractPartials=function(update){var result=[] for(var partial in update)result.push(partial) return result.join('&')} var old=$.fn.request $.fn.request=function(handler,option){var $this=$(this).first() var data={evalBeforeUpdate:$this.data('request-before-update'),evalSuccess:$this.data('request-success'),evalError:$this.data('request-error'),evalComplete:$this.data('request-complete'),ajaxGlobal:$this.data('request-ajax-global'),confirm:$this.data('request-confirm'),redirect:$this.data('request-redirect'),loading:$this.data('request-loading'),flash:$this.data('request-flash'),files:$this.data('request-files'),browserValidate:$this.data('browser-validate'),form:$this.data('request-form'),url:$this.data('request-url'),update:paramToObj('data-request-update',$this.data('request-update')),data:paramToObj('data-request-data',$this.data('request-data'))} if(!handler)handler=$this.data('request') var options=$.extend(true,{},Request.DEFAULTS,data,typeof option=='object'&&option) return new Request($this,handler,options)} $.fn.request.Constructor=Request $.request=function(handler,option){return $(document).request(handler,option)} $.fn.request.noConflict=function(){$.fn.request=old return this} $.fn.getRequestParentData=function(){var $form=$(this).first(),parentDataObjects=[formDataToObj(new FormData($form.get(0)))],parentFormData={};var findParentForms=function($form){if($form.length&&$form.data('request-parent')){var $parentEl=$($form.data('request-parent'));if($parentEl.length){var parentEmbeddedData={};$.each($parentEl.parents('[data-request-data]').toArray().reverse(),function extendRequest(){$.extend(parentEmbeddedData,paramToObj('data-request-data',$(this).data('request-data')));});if($parentEl.is('[data-request-data]')){$.extend(parentEmbeddedData,paramToObj('data-request-data',$parentEl.data('request-data')));}var $parentForm=$parentEl.closest('form');if($parentForm.length){parentDataObjects.push($.extend(formDataToObj(new FormData($parentForm.get(0))),parentEmbeddedData));findParentForms($parentForm);}}}};findParentForms($form);parentDataObjects.reverse().forEach(function(data){$.extend(parentFormData,data);});return parentFormData;} function paramToObj(name,value){if(value===undefined)value='' if(typeof value=='object')return value try{return ocJSON("{"+value+"}")}catch(e){throw new Error('Error parsing the '+name+' attribute value. '+e)}}function formDataToObj(formDataInstance){var objectData={};for(const pair of formDataInstance.entries()){const key=pair[0];const value=pair[1];if(!Reflect.has(objectData,key)||!key.includes('[]')){objectData[key]=value;continue;}if(!Array.isArray(objectData[key])){objectData[key]=[objectData[key]];}objectData[key].push(value);}return objectData;}function getXSRFToken(){var cookieValue=null if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';') for(var i=0;i="0"&&str[pos]<="9")){var body="";for(var i=pos;i="0"&&str[i]<="9")){body+=str[i];}else{return{originLength:body.length,body:body};}}throw new Error("Broken JSON number body near "+body);}if(str[pos]==="{"||str[pos]==="["){var stack=[str[pos]];var body=str[pos];for(var i=pos+1;i=0)?pos-5:0,50));}function canBeKeyHead(ch){if(ch[0]==="\\")return false;if((ch[0]>='a'&&ch[0]<='z')||(ch[0]>='A'&&ch[0]<='Z')||ch[0]==='_')return true;if(ch[0]>='0'&&ch[0]<='9')return true;if(ch[0]==='$')return true;if(ch.charCodeAt(0)>255)return true;return false;}function isBlankChar(ch){return ch===" "||ch==="\n"||ch==="\t";} function parse(str){str=str.trim();if(!str.length)throw new Error("Broken JSON object.");var result="";while(str&&str[0]===","){str=str.substr(1);}if(str[0]==="\""||str[0]==="'"){if(str[str.length-1]!==str[0]){throw new Error("Invalid string JSON object.");}var body="\"";for(var i=1;i'+html+'',null,false));output.find('*').each(function(){trimAttributes(this);});return output.html();}window.ocSanitize=function(html){return sanitize(html)};}(window);