$(document).ready(function () { initOnPageEdit(); //$("body").off("initAfterLoad"); $("body").on("initAfterLoad", function() { initOnPageEdit(); }); }); /** * Function inits onpage edit functionality */ function initOnPageEdit() { var typewatch = (function(){ var timer = 0; return function(callback, ms){ clearTimeout (timer); timer = setTimeout(callback, ms); }; })(); $('._onpage-edit').on('keydown', null, 'return', function(e){ var el = this; typewatch(function () { submitOnpageEdit(el); }, 400); }); $('._onpage-edit').typing({ stop: function (event, $elem) { submitOnpageEdit($elem); }, delay: 400 }); } /** * Function submits onpage edit to php API * * @param el */ function submitOnpageEdit(el) { var entityId = $(el).data('entity-id'); var entityType = $(el).data('entity-type'); var entityValueType = $(el).data('entity-value-type'); var value = $(el).val(); $.ajax({ type: "GET", url: '/app/api/onpageEdit', data: {entityId: entityId, entityType: entityType, entityValueType: entityValueType, value: value}, dataType: 'json' }).done(function(response) { if ( response.status == false ) { $('._onpage-edit[data-entity-id="' + response.data.entityId + '"]').effect("highlight", {color: '#f8c5c9'}, 500); } else { $('._onpage-edit[data-entity-id="' + response.data.entityId + '"]').effect("highlight", {color: '#cbf8c5'}, 500); //$('._onpage-edit[data-entity-id="' + response.data.entityId + '"]').removeClass('inline-editing-error'); } }); }