mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-26 11:08:06 +01:00
f36cccde7e
Add a JavaScript hooks library with an API that mirrors the WordPress Plugin API; provides similar functionality and API to PHP hooks. Called via the global `wp.hooks`, eg: `wp.hooks.addAction()`, etc. Adds: * `addAction( 'hook', 'vendor/plugin/function', callback, priority )` * `addFilter( 'hook', 'vendor/plugin/function', callback, priority )` * `removeAction( 'hook', 'vendor/plugin/function' )` * `removeFilter( 'hook', 'vendor/plugin/function' )` * `removeAllActions( 'hook' )` * `removeAllFilters( 'hook' )` * `doAction( 'hook', arg1, arg2, moreArgs, finalArg )` * `applyFilters( 'hook', content, arg1, arg2, moreArgs, finalArg )` * `doingAction( 'hook' )` * `doingFilter( 'hook' )` * `didAction( 'hook' )` * `didFilter( 'hook' )` * `hasAction( 'hook' )` * `hasFilter( 'hook' )` Props adamsilverstein, jnylen0, aduth, kadamwhite, youknowriad, schlessera, mikeschinkel, azaozz, vhauri, CaptainN, scribu, carldanley, chetanchauhan, mgibbs189, stephenharris, justnorris, koopersmith, gcorne, TV productions, atimmer. Fixes #21170. Built from https://develop.svn.wordpress.org/trunk@41375 git-svn-id: http://core.svn.wordpress.org/trunk@41208 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
5.8 KiB
JavaScript
1 line
5.8 KiB
JavaScript
this.wp=this.wp||{},this.wp.hooks=function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={i:d,l:!1,exports:{}};return a[d].call(e.exports,e,e.exports,b),e.l=!0,e.exports}var c={};return b.m=a,b.c=c,b.d=function(a,c,d){b.o(a,c)||Object.defineProperty(a,c,{configurable:!1,enumerable:!0,get:d})},b.n=function(a){var c=a&&a.__esModule?function(){return a["default"]}:function(){return a};return b.d(c,"a",c),c},b.o=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},b.p="",b(b.s=13)}([function(a,b,c){"use strict";function d(a){return"string"!=typeof a||""===a?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(a)?(console.error("The hook name cannot begin with `__`."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(a)||(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)}Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=d},function(a,b,c){"use strict";function d(a){return"string"!=typeof a||""===a?(console.error("The namespace must be a non-empty string."),!1):/^[a-zA-Z][a-zA-Z0-9_.-\/]*$/.test(a)?!!/^[a-zA-Z][a-zA-Z0-9_.-]*\/[a-zA-Z][a-zA-Z0-9_.-]*\/[a-zA-Z][a-zA-Z0-9_.-]*$/.test(a)||(console.error("The namespace must take the form `vendor/plugin/function`."),!1):(console.error("The namespace can only contain numbers, letters, dashes, periods and underscores, plus the forward slash dividing slug and description in the namespace."),!1)}Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=d},,,,,,,,,,,,function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}Object.defineProperty(b,"__esModule",{value:!0}),b.didFilter=b.didAction=b.doingFilter=b.doingAction=b.currentFilter=b.currentAction=b.applyFilters=b.doAction=b.removeAllFilters=b.removeAllActions=b.hasFilter=b.hasAction=b.removeFilter=b.removeAction=b.addFilter=b.addAction=void 0;var e=c(14),f=d(e),g=c(15),h=d(g),i=c(16),j=d(i),k=c(17),l=d(k),m=c(18),n=d(m),o=c(19),p=d(o),q=c(20),r=d(q),s=c(21),t=d(s);b.addAction=(0,h["default"])(f["default"].actions),b.addFilter=(0,h["default"])(f["default"].filters),b.removeAction=(0,j["default"])(f["default"].actions),b.removeFilter=(0,j["default"])(f["default"].filters),b.hasAction=(0,l["default"])(f["default"].actions),b.hasFilter=(0,l["default"])(f["default"].filters),b.removeAllActions=(0,j["default"])(f["default"].actions,!0),b.removeAllFilters=(0,j["default"])(f["default"].filters,!0),b.doAction=(0,n["default"])(f["default"].actions),b.applyFilters=(0,n["default"])(f["default"].filters,!0),b.currentAction=(0,p["default"])(f["default"].actions),b.currentFilter=(0,p["default"])(f["default"].filters),b.doingAction=(0,r["default"])(f["default"].actions),b.doingFilter=(0,r["default"])(f["default"].filters),b.didAction=(0,t["default"])(f["default"].actions),b.didFilter=(0,t["default"])(f["default"].filters)},function(a,b,c){"use strict";Object.defineProperty(b,"__esModule",{value:!0});var d={actions:{},filters:{}};b["default"]=d},function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(a){return function(b,c,d){var e=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10;if((0,i["default"])(b)&&(0,g["default"])(c)){if("function"!=typeof d)return void console.error("The hook callback must be a function.");if("number"!=typeof e)return void console.error("If specified, the hook priority must be a number.");var f={callback:d,priority:e,namespace:c};if(a.hasOwnProperty(b)){for(var h=a[b].handlers,j=0;j<h.length&&!(h[j].priority>e);)j++;h.splice(j,0,f),(a.__current||[]).forEach(function(a){a.name===b&&a.currentIndex>=j&&a.currentIndex++})}else a[b]={handlers:[f],runs:0}}}}Object.defineProperty(b,"__esModule",{value:!0});var f=c(1),g=d(f),h=c(0),i=d(h);b["default"]=e},function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(a,b){return function(c,d){if((0,i["default"])(c)&&(b||(0,g["default"])(d))){if(!a.hasOwnProperty(c))return 0;var e=0;if(b)e=a[c].handlers.length,a[c]={runs:a[c].runs,handlers:[]};else for(var f=a[c].handlers,h=function(b){f[b].namespace===d&&(f.splice(b,1),e++,(a.__current||[]).forEach(function(a){a.name===c&&a.currentIndex>=b&&a.currentIndex--}))},j=f.length-1;j>=0;j--)h(j);return e}}}Object.defineProperty(b,"__esModule",{value:!0});var f=c(1),g=d(f),h=c(0),i=d(h);b["default"]=e},function(a,b,c){"use strict";function d(a){return function(b){return a.hasOwnProperty(b)?a[b].handlers.length:0}}Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=d},function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(a,b){return function(c){if((0,g["default"])(c)){a.hasOwnProperty(c)||(a[c]={runs:0,handlers:[]});for(var d=a[c].handlers,e=arguments.length,f=Array(e>1?e-1:0),h=1;h<e;h++)f[h-1]=arguments[h];if(!d.length)return b?f[0]:void 0;var i={name:c,currentIndex:0};a.__current=a.__current||[],a.__current.push(i),a[c].runs++;for(var j=f[0];i.currentIndex<d.length;){var k=d[i.currentIndex];j=k.callback.apply(null,f),b&&(f[0]=j),i.currentIndex++}return a.__current.pop(),b?j:void 0}}}Object.defineProperty(b,"__esModule",{value:!0});var f=c(0),g=d(f);b["default"]=e},function(a,b,c){"use strict";function d(a,b){return function(){return a.__current&&a.__current.length?a.__current[a.__current.length-1].name:null}}Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=d},function(a,b,c){"use strict";function d(a){return function(b){return"undefined"==typeof b?"undefined"!=typeof a.__current[0]:!!a.__current[0]&&b===a.__current[0].name}}Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=d},function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(a){return function(b){if((0,g["default"])(b))return a.hasOwnProperty(b)&&a[b].runs?a[b].runs:0}}Object.defineProperty(b,"__esModule",{value:!0});var f=c(0),g=d(f);b["default"]=e}]); |