common.js 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086
  1. /**
  2. * @output wp-admin/js/common.js
  3. */
  4. /* global setUserSetting, ajaxurl, alert, confirm, pagenow */
  5. /* global columns, screenMeta */
  6. /**
  7. * Adds common WordPress functionality to the window.
  8. *
  9. * @param {jQuery} $ jQuery object.
  10. * @param {Object} window The window object.
  11. * @param {mixed} undefined Unused.
  12. */
  13. ( function( $, window, undefined ) {
  14. var $document = $( document ),
  15. $window = $( window ),
  16. $body = $( document.body ),
  17. __ = wp.i18n.__,
  18. sprintf = wp.i18n.sprintf;
  19. /**
  20. * Throws an error for a deprecated property.
  21. *
  22. * @since 5.5.1
  23. *
  24. * @param {string} propName The property that was used.
  25. * @param {string} version The version of WordPress that deprecated the property.
  26. * @param {string} replacement The property that should have been used.
  27. */
  28. function deprecatedProperty( propName, version, replacement ) {
  29. var message;
  30. if ( 'undefined' !== typeof replacement ) {
  31. message = sprintf(
  32. /* translators: 1: Deprecated property name, 2: Version number, 3: Alternative property name. */
  33. __( '%1$s is deprecated since version %2$s! Use %3$s instead.' ),
  34. propName,
  35. version,
  36. replacement
  37. );
  38. } else {
  39. message = sprintf(
  40. /* translators: 1: Deprecated property name, 2: Version number. */
  41. __( '%1$s is deprecated since version %2$s with no alternative available.' ),
  42. propName,
  43. version
  44. );
  45. }
  46. window.console.warn( message );
  47. }
  48. /**
  49. * Deprecate all properties on an object.
  50. *
  51. * @since 5.5.1
  52. * @since 5.6.0 Added the `version` parameter.
  53. *
  54. * @param {string} name The name of the object, i.e. commonL10n.
  55. * @param {object} l10nObject The object to deprecate the properties on.
  56. * @param {string} version The version of WordPress that deprecated the property.
  57. *
  58. * @return {object} The object with all its properties deprecated.
  59. */
  60. function deprecateL10nObject( name, l10nObject, version ) {
  61. var deprecatedObject = {};
  62. Object.keys( l10nObject ).forEach( function( key ) {
  63. var prop = l10nObject[ key ];
  64. var propName = name + '.' + key;
  65. if ( 'object' === typeof prop ) {
  66. Object.defineProperty( deprecatedObject, key, { get: function() {
  67. deprecatedProperty( propName, version, prop.alternative );
  68. return prop.func();
  69. } } );
  70. } else {
  71. Object.defineProperty( deprecatedObject, key, { get: function() {
  72. deprecatedProperty( propName, version, 'wp.i18n' );
  73. return prop;
  74. } } );
  75. }
  76. } );
  77. return deprecatedObject;
  78. }
  79. window.wp.deprecateL10nObject = deprecateL10nObject;
  80. /**
  81. * Removed in 5.5.0, needed for back-compatibility.
  82. *
  83. * @since 2.6.0
  84. * @deprecated 5.5.0
  85. */
  86. window.commonL10n = window.commonL10n || {
  87. warnDelete: '',
  88. dismiss: '',
  89. collapseMenu: '',
  90. expandMenu: ''
  91. };
  92. window.commonL10n = deprecateL10nObject( 'commonL10n', window.commonL10n, '5.5.0' );
  93. /**
  94. * Removed in 5.5.0, needed for back-compatibility.
  95. *
  96. * @since 3.3.0
  97. * @deprecated 5.5.0
  98. */
  99. window.wpPointerL10n = window.wpPointerL10n || {
  100. dismiss: ''
  101. };
  102. window.wpPointerL10n = deprecateL10nObject( 'wpPointerL10n', window.wpPointerL10n, '5.5.0' );
  103. /**
  104. * Removed in 5.5.0, needed for back-compatibility.
  105. *
  106. * @since 4.3.0
  107. * @deprecated 5.5.0
  108. */
  109. window.userProfileL10n = window.userProfileL10n || {
  110. warn: '',
  111. warnWeak: '',
  112. show: '',
  113. hide: '',
  114. cancel: '',
  115. ariaShow: '',
  116. ariaHide: ''
  117. };
  118. window.userProfileL10n = deprecateL10nObject( 'userProfileL10n', window.userProfileL10n, '5.5.0' );
  119. /**
  120. * Removed in 5.5.0, needed for back-compatibility.
  121. *
  122. * @since 4.9.6
  123. * @deprecated 5.5.0
  124. */
  125. window.privacyToolsL10n = window.privacyToolsL10n || {
  126. noDataFound: '',
  127. foundAndRemoved: '',
  128. noneRemoved: '',
  129. someNotRemoved: '',
  130. removalError: '',
  131. emailSent: '',
  132. noExportFile: '',
  133. exportError: ''
  134. };
  135. window.privacyToolsL10n = deprecateL10nObject( 'privacyToolsL10n', window.privacyToolsL10n, '5.5.0' );
  136. /**
  137. * Removed in 5.5.0, needed for back-compatibility.
  138. *
  139. * @since 3.6.0
  140. * @deprecated 5.5.0
  141. */
  142. window.authcheckL10n = {
  143. beforeunload: ''
  144. };
  145. window.authcheckL10n = window.authcheckL10n || deprecateL10nObject( 'authcheckL10n', window.authcheckL10n, '5.5.0' );
  146. /**
  147. * Removed in 5.5.0, needed for back-compatibility.
  148. *
  149. * @since 2.8.0
  150. * @deprecated 5.5.0
  151. */
  152. window.tagsl10n = {
  153. noPerm: '',
  154. broken: ''
  155. };
  156. window.tagsl10n = window.tagsl10n || deprecateL10nObject( 'tagsl10n', window.tagsl10n, '5.5.0' );
  157. /**
  158. * Removed in 5.5.0, needed for back-compatibility.
  159. *
  160. * @since 2.5.0
  161. * @deprecated 5.5.0
  162. */
  163. window.adminCommentsL10n = window.adminCommentsL10n || {
  164. hotkeys_highlight_first: {
  165. alternative: 'window.adminCommentsSettings.hotkeys_highlight_first',
  166. func: function() { return window.adminCommentsSettings.hotkeys_highlight_first; }
  167. },
  168. hotkeys_highlight_last: {
  169. alternative: 'window.adminCommentsSettings.hotkeys_highlight_last',
  170. func: function() { return window.adminCommentsSettings.hotkeys_highlight_last; }
  171. },
  172. replyApprove: '',
  173. reply: '',
  174. warnQuickEdit: '',
  175. warnCommentChanges: '',
  176. docTitleComments: '',
  177. docTitleCommentsCount: ''
  178. };
  179. window.adminCommentsL10n = deprecateL10nObject( 'adminCommentsL10n', window.adminCommentsL10n, '5.5.0' );
  180. /**
  181. * Removed in 5.5.0, needed for back-compatibility.
  182. *
  183. * @since 2.5.0
  184. * @deprecated 5.5.0
  185. */
  186. window.tagsSuggestL10n = window.tagsSuggestL10n || {
  187. tagDelimiter: '',
  188. removeTerm: '',
  189. termSelected: '',
  190. termAdded: '',
  191. termRemoved: ''
  192. };
  193. window.tagsSuggestL10n = deprecateL10nObject( 'tagsSuggestL10n', window.tagsSuggestL10n, '5.5.0' );
  194. /**
  195. * Removed in 5.5.0, needed for back-compatibility.
  196. *
  197. * @since 3.5.0
  198. * @deprecated 5.5.0
  199. */
  200. window.wpColorPickerL10n = window.wpColorPickerL10n || {
  201. clear: '',
  202. clearAriaLabel: '',
  203. defaultString: '',
  204. defaultAriaLabel: '',
  205. pick: '',
  206. defaultLabel: ''
  207. };
  208. window.wpColorPickerL10n = deprecateL10nObject( 'wpColorPickerL10n', window.wpColorPickerL10n, '5.5.0' );
  209. /**
  210. * Removed in 5.5.0, needed for back-compatibility.
  211. *
  212. * @since 2.7.0
  213. * @deprecated 5.5.0
  214. */
  215. window.attachMediaBoxL10n = window.attachMediaBoxL10n || {
  216. error: ''
  217. };
  218. window.attachMediaBoxL10n = deprecateL10nObject( 'attachMediaBoxL10n', window.attachMediaBoxL10n, '5.5.0' );
  219. /**
  220. * Removed in 5.5.0, needed for back-compatibility.
  221. *
  222. * @since 2.5.0
  223. * @deprecated 5.5.0
  224. */
  225. window.postL10n = window.postL10n || {
  226. ok: '',
  227. cancel: '',
  228. publishOn: '',
  229. publishOnFuture: '',
  230. publishOnPast: '',
  231. dateFormat: '',
  232. showcomm: '',
  233. endcomm: '',
  234. publish: '',
  235. schedule: '',
  236. update: '',
  237. savePending: '',
  238. saveDraft: '',
  239. 'private': '',
  240. 'public': '',
  241. publicSticky: '',
  242. password: '',
  243. privatelyPublished: '',
  244. published: '',
  245. saveAlert: '',
  246. savingText: '',
  247. permalinkSaved: ''
  248. };
  249. window.postL10n = deprecateL10nObject( 'postL10n', window.postL10n, '5.5.0' );
  250. /**
  251. * Removed in 5.5.0, needed for back-compatibility.
  252. *
  253. * @since 2.7.0
  254. * @deprecated 5.5.0
  255. */
  256. window.inlineEditL10n = window.inlineEditL10n || {
  257. error: '',
  258. ntdeltitle: '',
  259. notitle: '',
  260. comma: '',
  261. saved: ''
  262. };
  263. window.inlineEditL10n = deprecateL10nObject( 'inlineEditL10n', window.inlineEditL10n, '5.5.0' );
  264. /**
  265. * Removed in 5.5.0, needed for back-compatibility.
  266. *
  267. * @since 2.7.0
  268. * @deprecated 5.5.0
  269. */
  270. window.plugininstallL10n = window.plugininstallL10n || {
  271. plugin_information: '',
  272. plugin_modal_label: '',
  273. ays: ''
  274. };
  275. window.plugininstallL10n = deprecateL10nObject( 'plugininstallL10n', window.plugininstallL10n, '5.5.0' );
  276. /**
  277. * Removed in 5.5.0, needed for back-compatibility.
  278. *
  279. * @since 3.0.0
  280. * @deprecated 5.5.0
  281. */
  282. window.navMenuL10n = window.navMenuL10n || {
  283. noResultsFound: '',
  284. warnDeleteMenu: '',
  285. saveAlert: '',
  286. untitled: ''
  287. };
  288. window.navMenuL10n = deprecateL10nObject( 'navMenuL10n', window.navMenuL10n, '5.5.0' );
  289. /**
  290. * Removed in 5.5.0, needed for back-compatibility.
  291. *
  292. * @since 2.5.0
  293. * @deprecated 5.5.0
  294. */
  295. window.commentL10n = window.commentL10n || {
  296. submittedOn: '',
  297. dateFormat: ''
  298. };
  299. window.commentL10n = deprecateL10nObject( 'commentL10n', window.commentL10n, '5.5.0' );
  300. /**
  301. * Removed in 5.5.0, needed for back-compatibility.
  302. *
  303. * @since 2.9.0
  304. * @deprecated 5.5.0
  305. */
  306. window.setPostThumbnailL10n = window.setPostThumbnailL10n || {
  307. setThumbnail: '',
  308. saving: '',
  309. error: '',
  310. done: ''
  311. };
  312. window.setPostThumbnailL10n = deprecateL10nObject( 'setPostThumbnailL10n', window.setPostThumbnailL10n, '5.5.0' );
  313. /**
  314. * Removed in 3.3.0, needed for back-compatibility.
  315. *
  316. * @since 2.7.0
  317. * @deprecated 3.3.0
  318. */
  319. window.adminMenu = {
  320. init : function() {},
  321. fold : function() {},
  322. restoreMenuState : function() {},
  323. toggle : function() {},
  324. favorites : function() {}
  325. };
  326. // Show/hide/save table columns.
  327. window.columns = {
  328. /**
  329. * Initializes the column toggles in the screen options.
  330. *
  331. * Binds an onClick event to the checkboxes to show or hide the table columns
  332. * based on their toggled state. And persists the toggled state.
  333. *
  334. * @since 2.7.0
  335. *
  336. * @return {void}
  337. */
  338. init : function() {
  339. var that = this;
  340. $('.hide-column-tog', '#adv-settings').on( 'click', function() {
  341. var $t = $(this), column = $t.val();
  342. if ( $t.prop('checked') )
  343. that.checked(column);
  344. else
  345. that.unchecked(column);
  346. columns.saveManageColumnsState();
  347. });
  348. },
  349. /**
  350. * Saves the toggled state for the columns.
  351. *
  352. * Saves whether the columns should be shown or hidden on a page.
  353. *
  354. * @since 3.0.0
  355. *
  356. * @return {void}
  357. */
  358. saveManageColumnsState : function() {
  359. var hidden = this.hidden();
  360. $.post(ajaxurl, {
  361. action: 'hidden-columns',
  362. hidden: hidden,
  363. screenoptionnonce: $('#screenoptionnonce').val(),
  364. page: pagenow
  365. });
  366. },
  367. /**
  368. * Makes a column visible and adjusts the column span for the table.
  369. *
  370. * @since 3.0.0
  371. * @param {string} column The column name.
  372. *
  373. * @return {void}
  374. */
  375. checked : function(column) {
  376. $('.column-' + column).removeClass( 'hidden' );
  377. this.colSpanChange(+1);
  378. },
  379. /**
  380. * Hides a column and adjusts the column span for the table.
  381. *
  382. * @since 3.0.0
  383. * @param {string} column The column name.
  384. *
  385. * @return {void}
  386. */
  387. unchecked : function(column) {
  388. $('.column-' + column).addClass( 'hidden' );
  389. this.colSpanChange(-1);
  390. },
  391. /**
  392. * Gets all hidden columns.
  393. *
  394. * @since 3.0.0
  395. *
  396. * @return {string} The hidden column names separated by a comma.
  397. */
  398. hidden : function() {
  399. return $( '.manage-column[id]' ).filter( '.hidden' ).map(function() {
  400. return this.id;
  401. }).get().join( ',' );
  402. },
  403. /**
  404. * Gets the checked column toggles from the screen options.
  405. *
  406. * @since 3.0.0
  407. *
  408. * @return {string} String containing the checked column names.
  409. */
  410. useCheckboxesForHidden : function() {
  411. this.hidden = function(){
  412. return $('.hide-column-tog').not(':checked').map(function() {
  413. var id = this.id;
  414. return id.substring( id, id.length - 5 );
  415. }).get().join(',');
  416. };
  417. },
  418. /**
  419. * Adjusts the column span for the table.
  420. *
  421. * @since 3.1.0
  422. *
  423. * @param {number} diff The modifier for the column span.
  424. */
  425. colSpanChange : function(diff) {
  426. var $t = $('table').find('.colspanchange'), n;
  427. if ( !$t.length )
  428. return;
  429. n = parseInt( $t.attr('colspan'), 10 ) + diff;
  430. $t.attr('colspan', n.toString());
  431. }
  432. };
  433. $( function() { columns.init(); } );
  434. /**
  435. * Validates that the required form fields are not empty.
  436. *
  437. * @since 2.9.0
  438. *
  439. * @param {jQuery} form The form to validate.
  440. *
  441. * @return {boolean} Returns true if all required fields are not an empty string.
  442. */
  443. window.validateForm = function( form ) {
  444. return !$( form )
  445. .find( '.form-required' )
  446. .filter( function() { return $( ':input:visible', this ).val() === ''; } )
  447. .addClass( 'form-invalid' )
  448. .find( ':input:visible' )
  449. .on( 'change', function() { $( this ).closest( '.form-invalid' ).removeClass( 'form-invalid' ); } )
  450. .length;
  451. };
  452. // Stub for doing better warnings.
  453. /**
  454. * Shows message pop-up notice or confirmation message.
  455. *
  456. * @since 2.7.0
  457. *
  458. * @type {{warn: showNotice.warn, note: showNotice.note}}
  459. *
  460. * @return {void}
  461. */
  462. window.showNotice = {
  463. /**
  464. * Shows a delete confirmation pop-up message.
  465. *
  466. * @since 2.7.0
  467. *
  468. * @return {boolean} Returns true if the message is confirmed.
  469. */
  470. warn : function() {
  471. if ( confirm( __( 'You are about to permanently delete these items from your site.\nThis action cannot be undone.\n\'Cancel\' to stop, \'OK\' to delete.' ) ) ) {
  472. return true;
  473. }
  474. return false;
  475. },
  476. /**
  477. * Shows an alert message.
  478. *
  479. * @since 2.7.0
  480. *
  481. * @param text The text to display in the message.
  482. */
  483. note : function(text) {
  484. alert(text);
  485. }
  486. };
  487. /**
  488. * Represents the functions for the meta screen options panel.
  489. *
  490. * @since 3.2.0
  491. *
  492. * @type {{element: null, toggles: null, page: null, init: screenMeta.init,
  493. * toggleEvent: screenMeta.toggleEvent, open: screenMeta.open,
  494. * close: screenMeta.close}}
  495. *
  496. * @return {void}
  497. */
  498. window.screenMeta = {
  499. element: null, // #screen-meta
  500. toggles: null, // .screen-meta-toggle
  501. page: null, // #wpcontent
  502. /**
  503. * Initializes the screen meta options panel.
  504. *
  505. * @since 3.2.0
  506. *
  507. * @return {void}
  508. */
  509. init: function() {
  510. this.element = $('#screen-meta');
  511. this.toggles = $( '#screen-meta-links' ).find( '.show-settings' );
  512. this.page = $('#wpcontent');
  513. this.toggles.on( 'click', this.toggleEvent );
  514. },
  515. /**
  516. * Toggles the screen meta options panel.
  517. *
  518. * @since 3.2.0
  519. *
  520. * @return {void}
  521. */
  522. toggleEvent: function() {
  523. var panel = $( '#' + $( this ).attr( 'aria-controls' ) );
  524. if ( !panel.length )
  525. return;
  526. if ( panel.is(':visible') )
  527. screenMeta.close( panel, $(this) );
  528. else
  529. screenMeta.open( panel, $(this) );
  530. },
  531. /**
  532. * Opens the screen meta options panel.
  533. *
  534. * @since 3.2.0
  535. *
  536. * @param {jQuery} panel The screen meta options panel div.
  537. * @param {jQuery} button The toggle button.
  538. *
  539. * @return {void}
  540. */
  541. open: function( panel, button ) {
  542. $( '#screen-meta-links' ).find( '.screen-meta-toggle' ).not( button.parent() ).css( 'visibility', 'hidden' );
  543. panel.parent().show();
  544. /**
  545. * Sets the focus to the meta options panel and adds the necessary CSS classes.
  546. *
  547. * @since 3.2.0
  548. *
  549. * @return {void}
  550. */
  551. panel.slideDown( 'fast', function() {
  552. panel.removeClass( 'hidden' ).trigger( 'focus' );
  553. button.addClass( 'screen-meta-active' ).attr( 'aria-expanded', true );
  554. });
  555. $document.trigger( 'screen:options:open' );
  556. },
  557. /**
  558. * Closes the screen meta options panel.
  559. *
  560. * @since 3.2.0
  561. *
  562. * @param {jQuery} panel The screen meta options panel div.
  563. * @param {jQuery} button The toggle button.
  564. *
  565. * @return {void}
  566. */
  567. close: function( panel, button ) {
  568. /**
  569. * Hides the screen meta options panel.
  570. *
  571. * @since 3.2.0
  572. *
  573. * @return {void}
  574. */
  575. panel.slideUp( 'fast', function() {
  576. button.removeClass( 'screen-meta-active' ).attr( 'aria-expanded', false );
  577. $('.screen-meta-toggle').css('visibility', '');
  578. panel.parent().hide();
  579. panel.addClass( 'hidden' );
  580. });
  581. $document.trigger( 'screen:options:close' );
  582. }
  583. };
  584. /**
  585. * Initializes the help tabs in the help panel.
  586. *
  587. * @param {Event} e The event object.
  588. *
  589. * @return {void}
  590. */
  591. $('.contextual-help-tabs').on( 'click', 'a', function(e) {
  592. var link = $(this),
  593. panel;
  594. e.preventDefault();
  595. // Don't do anything if the click is for the tab already showing.
  596. if ( link.is('.active a') )
  597. return false;
  598. // Links.
  599. $('.contextual-help-tabs .active').removeClass('active');
  600. link.parent('li').addClass('active');
  601. panel = $( link.attr('href') );
  602. // Panels.
  603. $('.help-tab-content').not( panel ).removeClass('active').hide();
  604. panel.addClass('active').show();
  605. });
  606. /**
  607. * Update custom permalink structure via buttons.
  608. */
  609. var permalinkStructureFocused = false,
  610. $permalinkStructure = $( '#permalink_structure' ),
  611. $permalinkStructureInputs = $( '.permalink-structure input:radio' ),
  612. $permalinkCustomSelection = $( '#custom_selection' ),
  613. $availableStructureTags = $( '.form-table.permalink-structure .available-structure-tags button' );
  614. // Change permalink structure input when selecting one of the common structures.
  615. $permalinkStructureInputs.on( 'change', function() {
  616. if ( 'custom' === this.value ) {
  617. return;
  618. }
  619. $permalinkStructure.val( this.value );
  620. // Update button states after selection.
  621. $availableStructureTags.each( function() {
  622. changeStructureTagButtonState( $( this ) );
  623. } );
  624. } );
  625. $permalinkStructure.on( 'click input', function() {
  626. $permalinkCustomSelection.prop( 'checked', true );
  627. } );
  628. // Check if the permalink structure input field has had focus at least once.
  629. $permalinkStructure.on( 'focus', function( event ) {
  630. permalinkStructureFocused = true;
  631. $( this ).off( event );
  632. } );
  633. /**
  634. * Enables or disables a structure tag button depending on its usage.
  635. *
  636. * If the structure is already used in the custom permalink structure,
  637. * it will be disabled.
  638. *
  639. * @param {Object} button Button jQuery object.
  640. */
  641. function changeStructureTagButtonState( button ) {
  642. if ( -1 !== $permalinkStructure.val().indexOf( button.text().trim() ) ) {
  643. button.attr( 'data-label', button.attr( 'aria-label' ) );
  644. button.attr( 'aria-label', button.attr( 'data-used' ) );
  645. button.attr( 'aria-pressed', true );
  646. button.addClass( 'active' );
  647. } else if ( button.attr( 'data-label' ) ) {
  648. button.attr( 'aria-label', button.attr( 'data-label' ) );
  649. button.attr( 'aria-pressed', false );
  650. button.removeClass( 'active' );
  651. }
  652. }
  653. // Check initial button state.
  654. $availableStructureTags.each( function() {
  655. changeStructureTagButtonState( $( this ) );
  656. } );
  657. // Observe permalink structure field and disable buttons of tags that are already present.
  658. $permalinkStructure.on( 'change', function() {
  659. $availableStructureTags.each( function() {
  660. changeStructureTagButtonState( $( this ) );
  661. } );
  662. } );
  663. $availableStructureTags.on( 'click', function() {
  664. var permalinkStructureValue = $permalinkStructure.val(),
  665. selectionStart = $permalinkStructure[ 0 ].selectionStart,
  666. selectionEnd = $permalinkStructure[ 0 ].selectionEnd,
  667. textToAppend = $( this ).text().trim(),
  668. textToAnnounce,
  669. newSelectionStart;
  670. if ( $( this ).hasClass( 'active' ) ) {
  671. textToAnnounce = $( this ).attr( 'data-removed' );
  672. } else {
  673. textToAnnounce = $( this ).attr( 'data-added' );
  674. }
  675. // Remove structure tag if already part of the structure.
  676. if ( -1 !== permalinkStructureValue.indexOf( textToAppend ) ) {
  677. permalinkStructureValue = permalinkStructureValue.replace( textToAppend + '/', '' );
  678. $permalinkStructure.val( '/' === permalinkStructureValue ? '' : permalinkStructureValue );
  679. // Announce change to screen readers.
  680. $( '#custom_selection_updated' ).text( textToAnnounce );
  681. // Disable button.
  682. changeStructureTagButtonState( $( this ) );
  683. return;
  684. }
  685. // Input field never had focus, move selection to end of input.
  686. if ( ! permalinkStructureFocused && 0 === selectionStart && 0 === selectionEnd ) {
  687. selectionStart = selectionEnd = permalinkStructureValue.length;
  688. }
  689. $permalinkCustomSelection.prop( 'checked', true );
  690. // Prepend and append slashes if necessary.
  691. if ( '/' !== permalinkStructureValue.substr( 0, selectionStart ).substr( -1 ) ) {
  692. textToAppend = '/' + textToAppend;
  693. }
  694. if ( '/' !== permalinkStructureValue.substr( selectionEnd, 1 ) ) {
  695. textToAppend = textToAppend + '/';
  696. }
  697. // Insert structure tag at the specified position.
  698. $permalinkStructure.val( permalinkStructureValue.substr( 0, selectionStart ) + textToAppend + permalinkStructureValue.substr( selectionEnd ) );
  699. // Announce change to screen readers.
  700. $( '#custom_selection_updated' ).text( textToAnnounce );
  701. // Disable button.
  702. changeStructureTagButtonState( $( this ) );
  703. // If input had focus give it back with cursor right after appended text.
  704. if ( permalinkStructureFocused && $permalinkStructure[0].setSelectionRange ) {
  705. newSelectionStart = ( permalinkStructureValue.substr( 0, selectionStart ) + textToAppend ).length;
  706. $permalinkStructure[0].setSelectionRange( newSelectionStart, newSelectionStart );
  707. $permalinkStructure.trigger( 'focus' );
  708. }
  709. } );
  710. $( function() {
  711. var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions,
  712. lastClicked = false,
  713. pageInput = $('input.current-page'),
  714. currentPage = pageInput.val(),
  715. isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ),
  716. isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1,
  717. $adminMenuWrap = $( '#adminmenuwrap' ),
  718. $wpwrap = $( '#wpwrap' ),
  719. $adminmenu = $( '#adminmenu' ),
  720. $overlay = $( '#wp-responsive-overlay' ),
  721. $toolbar = $( '#wp-toolbar' ),
  722. $toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ),
  723. $sortables = $('.meta-box-sortables'),
  724. wpResponsiveActive = false,
  725. $adminbar = $( '#wpadminbar' ),
  726. lastScrollPosition = 0,
  727. pinnedMenuTop = false,
  728. pinnedMenuBottom = false,
  729. menuTop = 0,
  730. menuState,
  731. menuIsPinned = false,
  732. height = {
  733. window: $window.height(),
  734. wpwrap: $wpwrap.height(),
  735. adminbar: $adminbar.height(),
  736. menu: $adminMenuWrap.height()
  737. },
  738. $headerEnd = $( '.wp-header-end' );
  739. /**
  740. * Makes the fly-out submenu header clickable, when the menu is folded.
  741. *
  742. * @param {Event} e The event object.
  743. *
  744. * @return {void}
  745. */
  746. $adminmenu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){
  747. $(e.target).parent().siblings('a').get(0).click();
  748. });
  749. /**
  750. * Collapses the admin menu.
  751. *
  752. * @return {void}
  753. */
  754. $( '#collapse-button' ).on( 'click.collapse-menu', function() {
  755. var viewportWidth = getViewportWidth() || 961;
  756. // Reset any compensation for submenus near the bottom of the screen.
  757. $('#adminmenu div.wp-submenu').css('margin-top', '');
  758. if ( viewportWidth <= 960 ) {
  759. if ( $body.hasClass('auto-fold') ) {
  760. $body.removeClass('auto-fold').removeClass('folded');
  761. setUserSetting('unfold', 1);
  762. setUserSetting('mfold', 'o');
  763. menuState = 'open';
  764. } else {
  765. $body.addClass('auto-fold');
  766. setUserSetting('unfold', 0);
  767. menuState = 'folded';
  768. }
  769. } else {
  770. if ( $body.hasClass('folded') ) {
  771. $body.removeClass('folded');
  772. setUserSetting('mfold', 'o');
  773. menuState = 'open';
  774. } else {
  775. $body.addClass('folded');
  776. setUserSetting('mfold', 'f');
  777. menuState = 'folded';
  778. }
  779. }
  780. $document.trigger( 'wp-collapse-menu', { state: menuState } );
  781. });
  782. /**
  783. * Handles the `aria-haspopup` attribute on the current menu item when it has a submenu.
  784. *
  785. * @since 4.4.0
  786. *
  787. * @return {void}
  788. */
  789. function currentMenuItemHasPopup() {
  790. var $current = $( 'a.wp-has-current-submenu' );
  791. if ( 'folded' === menuState ) {
  792. // When folded or auto-folded and not responsive view, the current menu item does have a fly-out sub-menu.
  793. $current.attr( 'aria-haspopup', 'true' );
  794. } else {
  795. // When expanded or in responsive view, reset aria-haspopup.
  796. $current.attr( 'aria-haspopup', 'false' );
  797. }
  798. }
  799. $document.on( 'wp-menu-state-set wp-collapse-menu wp-responsive-activate wp-responsive-deactivate', currentMenuItemHasPopup );
  800. /**
  801. * Ensures an admin submenu is within the visual viewport.
  802. *
  803. * @since 4.1.0
  804. *
  805. * @param {jQuery} $menuItem The parent menu item containing the submenu.
  806. *
  807. * @return {void}
  808. */
  809. function adjustSubmenu( $menuItem ) {
  810. var bottomOffset, pageHeight, adjustment, theFold, menutop, wintop, maxtop,
  811. $submenu = $menuItem.find( '.wp-submenu' );
  812. menutop = $menuItem.offset().top;
  813. wintop = $window.scrollTop();
  814. maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar.
  815. bottomOffset = menutop + $submenu.height() + 1; // Bottom offset of the menu.
  816. pageHeight = $wpwrap.height(); // Height of the entire page.
  817. adjustment = 60 + bottomOffset - pageHeight;
  818. theFold = $window.height() + wintop - 50; // The fold.
  819. if ( theFold < ( bottomOffset - adjustment ) ) {
  820. adjustment = bottomOffset - theFold;
  821. }
  822. if ( adjustment > maxtop ) {
  823. adjustment = maxtop;
  824. }
  825. if ( adjustment > 1 && $('#wp-admin-bar-menu-toggle').is(':hidden') ) {
  826. $submenu.css( 'margin-top', '-' + adjustment + 'px' );
  827. } else {
  828. $submenu.css( 'margin-top', '' );
  829. }
  830. }
  831. if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // Touch screen device.
  832. // iOS Safari works with touchstart, the rest work with click.
  833. mobileEvent = isIOS ? 'touchstart' : 'click';
  834. /**
  835. * Closes any open submenus when touch/click is not on the menu.
  836. *
  837. * @param {Event} e The event object.
  838. *
  839. * @return {void}
  840. */
  841. $body.on( mobileEvent+'.wp-mobile-hover', function(e) {
  842. if ( $adminmenu.data('wp-responsive') ) {
  843. return;
  844. }
  845. if ( ! $( e.target ).closest( '#adminmenu' ).length ) {
  846. $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' );
  847. }
  848. });
  849. /**
  850. * Handles the opening or closing the submenu based on the mobile click|touch event.
  851. *
  852. * @param {Event} event The event object.
  853. *
  854. * @return {void}
  855. */
  856. $adminmenu.find( 'a.wp-has-submenu' ).on( mobileEvent + '.wp-mobile-hover', function( event ) {
  857. var $menuItem = $(this).parent();
  858. if ( $adminmenu.data( 'wp-responsive' ) ) {
  859. return;
  860. }
  861. /*
  862. * Show the sub instead of following the link if:
  863. * - the submenu is not open.
  864. * - the submenu is not shown inline or the menu is not folded.
  865. */
  866. if ( ! $menuItem.hasClass( 'opensub' ) && ( ! $menuItem.hasClass( 'wp-menu-open' ) || $menuItem.width() < 40 ) ) {
  867. event.preventDefault();
  868. adjustSubmenu( $menuItem );
  869. $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' );
  870. $menuItem.addClass('opensub');
  871. }
  872. });
  873. }
  874. if ( ! isIOS && ! isAndroid ) {
  875. $adminmenu.find( 'li.wp-has-submenu' ).hoverIntent({
  876. /**
  877. * Opens the submenu when hovered over the menu item for desktops.
  878. *
  879. * @return {void}
  880. */
  881. over: function() {
  882. var $menuItem = $( this ),
  883. $submenu = $menuItem.find( '.wp-submenu' ),
  884. top = parseInt( $submenu.css( 'top' ), 10 );
  885. if ( isNaN( top ) || top > -5 ) { // The submenu is visible.
  886. return;
  887. }
  888. if ( $adminmenu.data( 'wp-responsive' ) ) {
  889. // The menu is in responsive mode, bail.
  890. return;
  891. }
  892. adjustSubmenu( $menuItem );
  893. $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' );
  894. $menuItem.addClass( 'opensub' );
  895. },
  896. /**
  897. * Closes the submenu when no longer hovering the menu item.
  898. *
  899. * @return {void}
  900. */
  901. out: function(){
  902. if ( $adminmenu.data( 'wp-responsive' ) ) {
  903. // The menu is in responsive mode, bail.
  904. return;
  905. }
  906. $( this ).removeClass( 'opensub' ).find( '.wp-submenu' ).css( 'margin-top', '' );
  907. },
  908. timeout: 200,
  909. sensitivity: 7,
  910. interval: 90
  911. });
  912. /**
  913. * Opens the submenu on when focused on the menu item.
  914. *
  915. * @param {Event} event The event object.
  916. *
  917. * @return {void}
  918. */
  919. $adminmenu.on( 'focus.adminmenu', '.wp-submenu a', function( event ) {
  920. if ( $adminmenu.data( 'wp-responsive' ) ) {
  921. // The menu is in responsive mode, bail.
  922. return;
  923. }
  924. $( event.target ).closest( 'li.menu-top' ).addClass( 'opensub' );
  925. /**
  926. * Closes the submenu on blur from the menu item.
  927. *
  928. * @param {Event} event The event object.
  929. *
  930. * @return {void}
  931. */
  932. }).on( 'blur.adminmenu', '.wp-submenu a', function( event ) {
  933. if ( $adminmenu.data( 'wp-responsive' ) ) {
  934. return;
  935. }
  936. $( event.target ).closest( 'li.menu-top' ).removeClass( 'opensub' );
  937. /**
  938. * Adjusts the size for the submenu.
  939. *
  940. * @return {void}
  941. */
  942. }).find( 'li.wp-has-submenu.wp-not-current-submenu' ).on( 'focusin.adminmenu', function() {
  943. adjustSubmenu( $( this ) );
  944. });
  945. }
  946. /*
  947. * The `.below-h2` class is here just for backward compatibility with plugins
  948. * that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570.
  949. * If '.wp-header-end' is found, append the notices after it otherwise
  950. * after the first h1 or h2 heading found within the main content.
  951. */
  952. if ( ! $headerEnd.length ) {
  953. $headerEnd = $( '.wrap h1, .wrap h2' ).first();
  954. }
  955. $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $headerEnd );
  956. /**
  957. * Makes notices dismissible.
  958. *
  959. * @since 4.4.0
  960. *
  961. * @return {void}
  962. */
  963. function makeNoticesDismissible() {
  964. $( '.notice.is-dismissible' ).each( function() {
  965. var $el = $( this ),
  966. $button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' );
  967. if ( $el.find( '.notice-dismiss' ).length ) {
  968. return;
  969. }
  970. // Ensure plain text.
  971. $button.find( '.screen-reader-text' ).text( __( 'Dismiss this notice.' ) );
  972. $button.on( 'click.wp-dismiss-notice', function( event ) {
  973. event.preventDefault();
  974. $el.fadeTo( 100, 0, function() {
  975. $el.slideUp( 100, function() {
  976. $el.remove();
  977. });
  978. });
  979. });
  980. $el.append( $button );
  981. });
  982. }
  983. $document.on( 'wp-updates-notice-added wp-plugin-install-error wp-plugin-update-error wp-plugin-delete-error wp-theme-install-error wp-theme-delete-error', makeNoticesDismissible );
  984. // Init screen meta.
  985. screenMeta.init();
  986. /**
  987. * Checks a checkbox.
  988. *
  989. * This event needs to be delegated. Ticket #37973.
  990. *
  991. * @return {boolean} Returns whether a checkbox is checked or not.
  992. */
  993. $body.on( 'click', 'tbody > tr > .check-column :checkbox', function( event ) {
  994. // Shift click to select a range of checkboxes.
  995. if ( 'undefined' == event.shiftKey ) { return true; }
  996. if ( event.shiftKey ) {
  997. if ( !lastClicked ) { return true; }
  998. checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' ).filter( ':visible:enabled' );
  999. first = checks.index( lastClicked );
  1000. last = checks.index( this );
  1001. checked = $(this).prop('checked');
  1002. if ( 0 < first && 0 < last && first != last ) {
  1003. sliced = ( last > first ) ? checks.slice( first, last ) : checks.slice( last, first );
  1004. sliced.prop( 'checked', function() {
  1005. if ( $(this).closest('tr').is(':visible') )
  1006. return checked;
  1007. return false;
  1008. });
  1009. }
  1010. }
  1011. lastClicked = this;
  1012. // Toggle the "Select all" checkboxes depending if the other ones are all checked or not.
  1013. var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible:enabled').not(':checked');
  1014. /**
  1015. * Determines if all checkboxes are checked.
  1016. *
  1017. * @return {boolean} Returns true if there are no unchecked checkboxes.
  1018. */
  1019. $(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() {
  1020. return ( 0 === unchecked.length );
  1021. });
  1022. return true;
  1023. });
  1024. /**
  1025. * Controls all the toggles on bulk toggle change.
  1026. *
  1027. * When the bulk checkbox is changed, all the checkboxes in the tables are changed accordingly.
  1028. * When the shift-button is pressed while changing the bulk checkbox the checkboxes in the table are inverted.
  1029. *
  1030. * This event needs to be delegated. Ticket #37973.
  1031. *
  1032. * @param {Event} event The event object.
  1033. *
  1034. * @return {boolean}
  1035. */
  1036. $body.on( 'click.wp-toggle-checkboxes', 'thead .check-column :checkbox, tfoot .check-column :checkbox', function( event ) {
  1037. var $this = $(this),
  1038. $table = $this.closest( 'table' ),
  1039. controlChecked = $this.prop('checked'),
  1040. toggle = event.shiftKey || $this.data('wp-toggle');
  1041. $table.children( 'tbody' ).filter(':visible')
  1042. .children().children('.check-column').find(':checkbox')
  1043. /**
  1044. * Updates the checked state on the checkbox in the table.
  1045. *
  1046. * @return {boolean} True checks the checkbox, False unchecks the checkbox.
  1047. */
  1048. .prop('checked', function() {
  1049. if ( $(this).is(':hidden,:disabled') ) {
  1050. return false;
  1051. }
  1052. if ( toggle ) {
  1053. return ! $(this).prop( 'checked' );
  1054. } else if ( controlChecked ) {
  1055. return true;
  1056. }
  1057. return false;
  1058. });
  1059. $table.children('thead, tfoot').filter(':visible')
  1060. .children().children('.check-column').find(':checkbox')
  1061. /**
  1062. * Syncs the bulk checkboxes on the top and bottom of the table.
  1063. *
  1064. * @return {boolean} True checks the checkbox, False unchecks the checkbox.
  1065. */
  1066. .prop('checked', function() {
  1067. if ( toggle ) {
  1068. return false;
  1069. } else if ( controlChecked ) {
  1070. return true;
  1071. }
  1072. return false;
  1073. });
  1074. });
  1075. /**
  1076. * Marries a secondary control to its primary control.
  1077. *
  1078. * @param {jQuery} topSelector The top selector element.
  1079. * @param {jQuery} topSubmit The top submit element.
  1080. * @param {jQuery} bottomSelector The bottom selector element.
  1081. * @param {jQuery} bottomSubmit The bottom submit element.
  1082. * @return {void}
  1083. */
  1084. function marryControls( topSelector, topSubmit, bottomSelector, bottomSubmit ) {
  1085. /**
  1086. * Updates the primary selector when the secondary selector is changed.
  1087. *
  1088. * @since 5.7.0
  1089. *
  1090. * @return {void}
  1091. */
  1092. function updateTopSelector() {
  1093. topSelector.val($(this).val());
  1094. }
  1095. bottomSelector.on('change', updateTopSelector);
  1096. /**
  1097. * Updates the secondary selector when the primary selector is changed.
  1098. *
  1099. * @since 5.7.0
  1100. *
  1101. * @return {void}
  1102. */
  1103. function updateBottomSelector() {
  1104. bottomSelector.val($(this).val());
  1105. }
  1106. topSelector.on('change', updateBottomSelector);
  1107. /**
  1108. * Triggers the primary submit when then secondary submit is clicked.
  1109. *
  1110. * @since 5.7.0
  1111. *
  1112. * @return {void}
  1113. */
  1114. function triggerSubmitClick(e) {
  1115. e.preventDefault();
  1116. e.stopPropagation();
  1117. topSubmit.trigger('click');
  1118. }
  1119. bottomSubmit.on('click', triggerSubmitClick);
  1120. }
  1121. // Marry the secondary "Bulk actions" controls to the primary controls:
  1122. marryControls( $('#bulk-action-selector-top'), $('#doaction'), $('#bulk-action-selector-bottom'), $('#doaction2') );
  1123. // Marry the secondary "Change role to" controls to the primary controls:
  1124. marryControls( $('#new_role'), $('#changeit'), $('#new_role2'), $('#changeit2') );
  1125. /**
  1126. * Shows row actions on focus of its parent container element or any other elements contained within.
  1127. *
  1128. * @return {void}
  1129. */
  1130. $( '#wpbody-content' ).on({
  1131. focusin: function() {
  1132. clearTimeout( transitionTimeout );
  1133. focusedRowActions = $( this ).find( '.row-actions' );
  1134. // transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help.
  1135. $( '.row-actions' ).not( this ).removeClass( 'visible' );
  1136. focusedRowActions.addClass( 'visible' );
  1137. },
  1138. focusout: function() {
  1139. // Tabbing between post title and .row-actions links needs a brief pause, otherwise
  1140. // the .row-actions div gets hidden in transit in some browsers (ahem, Firefox).
  1141. transitionTimeout = setTimeout( function() {
  1142. focusedRowActions.removeClass( 'visible' );
  1143. }, 30 );
  1144. }
  1145. }, '.table-view-list .has-row-actions' );
  1146. // Toggle list table rows on small screens.
  1147. $( 'tbody' ).on( 'click', '.toggle-row', function() {
  1148. $( this ).closest( 'tr' ).toggleClass( 'is-expanded' );
  1149. });
  1150. $('#default-password-nag-no').on( 'click', function() {
  1151. setUserSetting('default_password_nag', 'hide');
  1152. $('div.default-password-nag').hide();
  1153. return false;
  1154. });
  1155. /**
  1156. * Handles tab keypresses in theme and plugin file editor textareas.
  1157. *
  1158. * @param {Event} e The event object.
  1159. *
  1160. * @return {void}
  1161. */
  1162. $('#newcontent').on('keydown.wpevent_InsertTab', function(e) {
  1163. var el = e.target, selStart, selEnd, val, scroll, sel;
  1164. // After pressing escape key (keyCode: 27), the tab key should tab out of the textarea.
  1165. if ( e.keyCode == 27 ) {
  1166. // When pressing Escape: Opera 12 and 27 blur form fields, IE 8 clears them.
  1167. e.preventDefault();
  1168. $(el).data('tab-out', true);
  1169. return;
  1170. }
  1171. // Only listen for plain tab key (keyCode: 9) without any modifiers.
  1172. if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey )
  1173. return;
  1174. // After tabbing out, reset it so next time the tab key can be used again.
  1175. if ( $(el).data('tab-out') ) {
  1176. $(el).data('tab-out', false);
  1177. return;
  1178. }
  1179. selStart = el.selectionStart;
  1180. selEnd = el.selectionEnd;
  1181. val = el.value;
  1182. // If any text is selected, replace the selection with a tab character.
  1183. if ( document.selection ) {
  1184. el.focus();
  1185. sel = document.selection.createRange();
  1186. sel.text = '\t';
  1187. } else if ( selStart >= 0 ) {
  1188. scroll = this.scrollTop;
  1189. el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) );
  1190. el.selectionStart = el.selectionEnd = selStart + 1;
  1191. this.scrollTop = scroll;
  1192. }
  1193. // Cancel the regular tab functionality, to prevent losing focus of the textarea.
  1194. if ( e.stopPropagation )
  1195. e.stopPropagation();
  1196. if ( e.preventDefault )
  1197. e.preventDefault();
  1198. });
  1199. // Reset page number variable for new filters/searches but not for bulk actions. See #17685.
  1200. if ( pageInput.length ) {
  1201. /**
  1202. * Handles pagination variable when filtering the list table.
  1203. *
  1204. * Set the pagination argument to the first page when the post-filter form is submitted.
  1205. * This happens when pressing the 'filter' button on the list table page.
  1206. *
  1207. * The pagination argument should not be touched when the bulk action dropdowns are set to do anything.
  1208. *
  1209. * The form closest to the pageInput is the post-filter form.
  1210. *
  1211. * @return {void}
  1212. */
  1213. pageInput.closest('form').on( 'submit', function() {
  1214. /*
  1215. * action = bulk action dropdown at the top of the table
  1216. */
  1217. if ( $('select[name="action"]').val() == -1 && pageInput.val() == currentPage )
  1218. pageInput.val('1');
  1219. });
  1220. }
  1221. /**
  1222. * Resets the bulk actions when the search button is clicked.
  1223. *
  1224. * @return {void}
  1225. */
  1226. $('.search-box input[type="search"], .search-box input[type="submit"]').on( 'mousedown', function () {
  1227. $('select[name^="action"]').val('-1');
  1228. });
  1229. /**
  1230. * Scrolls into view when focus.scroll-into-view is triggered.
  1231. *
  1232. * @param {Event} e The event object.
  1233. *
  1234. * @return {void}
  1235. */
  1236. $('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){
  1237. if ( e.target.scrollIntoView )
  1238. e.target.scrollIntoView(false);
  1239. });
  1240. /**
  1241. * Disables the submit upload buttons when no data is entered.
  1242. *
  1243. * @return {void}
  1244. */
  1245. (function(){
  1246. var button, input, form = $('form.wp-upload-form');
  1247. // Exit when no upload form is found.
  1248. if ( ! form.length )
  1249. return;
  1250. button = form.find('input[type="submit"]');
  1251. input = form.find('input[type="file"]');
  1252. /**
  1253. * Determines if any data is entered in any file upload input.
  1254. *
  1255. * @since 3.5.0
  1256. *
  1257. * @return {void}
  1258. */
  1259. function toggleUploadButton() {
  1260. // When no inputs have a value, disable the upload buttons.
  1261. button.prop('disabled', '' === input.map( function() {
  1262. return $(this).val();
  1263. }).get().join(''));
  1264. }
  1265. // Update the status initially.
  1266. toggleUploadButton();
  1267. // Update the status when any file input changes.
  1268. input.on('change', toggleUploadButton);
  1269. })();
  1270. /**
  1271. * Pins the menu while distraction-free writing is enabled.
  1272. *
  1273. * @param {Event} event Event data.
  1274. *
  1275. * @since 4.1.0
  1276. *
  1277. * @return {void}
  1278. */
  1279. function pinMenu( event ) {
  1280. var windowPos = $window.scrollTop(),
  1281. resizing = ! event || event.type !== 'scroll';
  1282. if ( isIOS || $adminmenu.data( 'wp-responsive' ) ) {
  1283. return;
  1284. }
  1285. /*
  1286. * When the menu is higher than the window and smaller than the entire page.
  1287. * It should be adjusted to be able to see the entire menu.
  1288. *
  1289. * Otherwise it can be accessed normally.
  1290. */
  1291. if ( height.menu + height.adminbar < height.window ||
  1292. height.menu + height.adminbar + 20 > height.wpwrap ) {
  1293. unpinMenu();
  1294. return;
  1295. }
  1296. menuIsPinned = true;
  1297. // If the menu is higher than the window, compensate on scroll.
  1298. if ( height.menu + height.adminbar > height.window ) {
  1299. // Check for overscrolling, this happens when swiping up at the top of the document in modern browsers.
  1300. if ( windowPos < 0 ) {
  1301. // Stick the menu to the top.
  1302. if ( ! pinnedMenuTop ) {
  1303. pinnedMenuTop = true;
  1304. pinnedMenuBottom = false;
  1305. $adminMenuWrap.css({
  1306. position: 'fixed',
  1307. top: '',
  1308. bottom: ''
  1309. });
  1310. }
  1311. return;
  1312. } else if ( windowPos + height.window > $document.height() - 1 ) {
  1313. // When overscrolling at the bottom, stick the menu to the bottom.
  1314. if ( ! pinnedMenuBottom ) {
  1315. pinnedMenuBottom = true;
  1316. pinnedMenuTop = false;
  1317. $adminMenuWrap.css({
  1318. position: 'fixed',
  1319. top: '',
  1320. bottom: 0
  1321. });
  1322. }
  1323. return;
  1324. }
  1325. if ( windowPos > lastScrollPosition ) {
  1326. // When a down scroll has been detected.
  1327. // If it was pinned to the top, unpin and calculate relative scroll.
  1328. if ( pinnedMenuTop ) {
  1329. pinnedMenuTop = false;
  1330. // Calculate new offset position.
  1331. menuTop = $adminMenuWrap.offset().top - height.adminbar - ( windowPos - lastScrollPosition );
  1332. if ( menuTop + height.menu + height.adminbar < windowPos + height.window ) {
  1333. menuTop = windowPos + height.window - height.menu - height.adminbar;
  1334. }
  1335. $adminMenuWrap.css({
  1336. position: 'absolute',
  1337. top: menuTop,
  1338. bottom: ''
  1339. });
  1340. } else if ( ! pinnedMenuBottom && $adminMenuWrap.offset().top + height.menu < windowPos + height.window ) {
  1341. // Pin it to the bottom.
  1342. pinnedMenuBottom = true;
  1343. $adminMenuWrap.css({
  1344. position: 'fixed',
  1345. top: '',
  1346. bottom: 0
  1347. });
  1348. }
  1349. } else if ( windowPos < lastScrollPosition ) {
  1350. // When a scroll up is detected.
  1351. // If it was pinned to the bottom, unpin and calculate relative scroll.
  1352. if ( pinnedMenuBottom ) {
  1353. pinnedMenuBottom = false;
  1354. // Calculate new offset position.
  1355. menuTop = $adminMenuWrap.offset().top - height.adminbar + ( lastScrollPosition - windowPos );
  1356. if ( menuTop + height.menu > windowPos + height.window ) {
  1357. menuTop = windowPos;
  1358. }
  1359. $adminMenuWrap.css({
  1360. position: 'absolute',
  1361. top: menuTop,
  1362. bottom: ''
  1363. });
  1364. } else if ( ! pinnedMenuTop && $adminMenuWrap.offset().top >= windowPos + height.adminbar ) {
  1365. // Pin it to the top.
  1366. pinnedMenuTop = true;
  1367. $adminMenuWrap.css({
  1368. position: 'fixed',
  1369. top: '',
  1370. bottom: ''
  1371. });
  1372. }
  1373. } else if ( resizing ) {
  1374. // Window is being resized.
  1375. pinnedMenuTop = pinnedMenuBottom = false;
  1376. // Calculate the new offset.
  1377. menuTop = windowPos + height.window - height.menu - height.adminbar - 1;
  1378. if ( menuTop > 0 ) {
  1379. $adminMenuWrap.css({
  1380. position: 'absolute',
  1381. top: menuTop,
  1382. bottom: ''
  1383. });
  1384. } else {
  1385. unpinMenu();
  1386. }
  1387. }
  1388. }
  1389. lastScrollPosition = windowPos;
  1390. }
  1391. /**
  1392. * Determines the height of certain elements.
  1393. *
  1394. * @since 4.1.0
  1395. *
  1396. * @return {void}
  1397. */
  1398. function resetHeights() {
  1399. height = {
  1400. window: $window.height(),
  1401. wpwrap: $wpwrap.height(),
  1402. adminbar: $adminbar.height(),
  1403. menu: $adminMenuWrap.height()
  1404. };
  1405. }
  1406. /**
  1407. * Unpins the menu.
  1408. *
  1409. * @since 4.1.0
  1410. *
  1411. * @return {void}
  1412. */
  1413. function unpinMenu() {
  1414. if ( isIOS || ! menuIsPinned ) {
  1415. return;
  1416. }
  1417. pinnedMenuTop = pinnedMenuBottom = menuIsPinned = false;
  1418. $adminMenuWrap.css({
  1419. position: '',
  1420. top: '',
  1421. bottom: ''
  1422. });
  1423. }
  1424. /**
  1425. * Pins and unpins the menu when applicable.
  1426. *
  1427. * @since 4.1.0
  1428. *
  1429. * @return {void}
  1430. */
  1431. function setPinMenu() {
  1432. resetHeights();
  1433. if ( $adminmenu.data('wp-responsive') ) {
  1434. $body.removeClass( 'sticky-menu' );
  1435. unpinMenu();
  1436. } else if ( height.menu + height.adminbar > height.window ) {
  1437. pinMenu();
  1438. $body.removeClass( 'sticky-menu' );
  1439. } else {
  1440. $body.addClass( 'sticky-menu' );
  1441. unpinMenu();
  1442. }
  1443. }
  1444. if ( ! isIOS ) {
  1445. $window.on( 'scroll.pin-menu', pinMenu );
  1446. $document.on( 'tinymce-editor-init.pin-menu', function( event, editor ) {
  1447. editor.on( 'wp-autoresize', resetHeights );
  1448. });
  1449. }
  1450. /**
  1451. * Changes the sortables and responsiveness of metaboxes.
  1452. *
  1453. * @since 3.8.0
  1454. *
  1455. * @return {void}
  1456. */
  1457. window.wpResponsive = {
  1458. /**
  1459. * Initializes the wpResponsive object.
  1460. *
  1461. * @since 3.8.0
  1462. *
  1463. * @return {void}
  1464. */
  1465. init: function() {
  1466. var self = this;
  1467. this.maybeDisableSortables = this.maybeDisableSortables.bind( this );
  1468. // Modify functionality based on custom activate/deactivate event.
  1469. $document.on( 'wp-responsive-activate.wp-responsive', function() {
  1470. self.activate();
  1471. }).on( 'wp-responsive-deactivate.wp-responsive', function() {
  1472. self.deactivate();
  1473. });
  1474. $( '#wp-admin-bar-menu-toggle a' ).attr( 'aria-expanded', 'false' );
  1475. // Toggle sidebar when toggle is clicked.
  1476. $( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) {
  1477. event.preventDefault();
  1478. // Close any open toolbar submenus.
  1479. $adminbar.find( '.hover' ).removeClass( 'hover' );
  1480. $wpwrap.toggleClass( 'wp-responsive-open' );
  1481. if ( $wpwrap.hasClass( 'wp-responsive-open' ) ) {
  1482. $(this).find('a').attr( 'aria-expanded', 'true' );
  1483. $( '#adminmenu a:first' ).trigger( 'focus' );
  1484. } else {
  1485. $(this).find('a').attr( 'aria-expanded', 'false' );
  1486. }
  1487. } );
  1488. // Add menu events.
  1489. $adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) {
  1490. if ( ! $adminmenu.data('wp-responsive') ) {
  1491. return;
  1492. }
  1493. $( this ).parent( 'li' ).toggleClass( 'selected' );
  1494. event.preventDefault();
  1495. });
  1496. self.trigger();
  1497. $document.on( 'wp-window-resized.wp-responsive', this.trigger.bind( this ) );
  1498. // This needs to run later as UI Sortable may be initialized when the document is ready.
  1499. $window.on( 'load.wp-responsive', this.maybeDisableSortables );
  1500. $document.on( 'postbox-toggled', this.maybeDisableSortables );
  1501. // When the screen columns are changed, potentially disable sortables.
  1502. $( '#screen-options-wrap input' ).on( 'click', this.maybeDisableSortables );
  1503. },
  1504. /**
  1505. * Disable sortables if there is only one metabox, or the screen is in one column mode. Otherwise, enable sortables.
  1506. *
  1507. * @since 5.3.0
  1508. *
  1509. * @return {void}
  1510. */
  1511. maybeDisableSortables: function() {
  1512. var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth;
  1513. if (
  1514. ( width <= 782 ) ||
  1515. ( 1 >= $sortables.find( '.ui-sortable-handle:visible' ).length && jQuery( '.columns-prefs-1 input' ).prop( 'checked' ) )
  1516. ) {
  1517. this.disableSortables();
  1518. } else {
  1519. this.enableSortables();
  1520. }
  1521. },
  1522. /**
  1523. * Changes properties of body and admin menu.
  1524. *
  1525. * Pins and unpins the menu and adds the auto-fold class to the body.
  1526. * Makes the admin menu responsive and disables the metabox sortables.
  1527. *
  1528. * @since 3.8.0
  1529. *
  1530. * @return {void}
  1531. */
  1532. activate: function() {
  1533. setPinMenu();
  1534. if ( ! $body.hasClass( 'auto-fold' ) ) {
  1535. $body.addClass( 'auto-fold' );
  1536. }
  1537. $adminmenu.data( 'wp-responsive', 1 );
  1538. this.disableSortables();
  1539. },
  1540. /**
  1541. * Changes properties of admin menu and enables metabox sortables.
  1542. *
  1543. * Pin and unpin the menu.
  1544. * Removes the responsiveness of the admin menu and enables the metabox sortables.
  1545. *
  1546. * @since 3.8.0
  1547. *
  1548. * @return {void}
  1549. */
  1550. deactivate: function() {
  1551. setPinMenu();
  1552. $adminmenu.removeData('wp-responsive');
  1553. this.maybeDisableSortables();
  1554. },
  1555. /**
  1556. * Sets the responsiveness and enables the overlay based on the viewport width.
  1557. *
  1558. * @since 3.8.0
  1559. *
  1560. * @return {void}
  1561. */
  1562. trigger: function() {
  1563. var viewportWidth = getViewportWidth();
  1564. // Exclude IE < 9, it doesn't support @media CSS rules.
  1565. if ( ! viewportWidth ) {
  1566. return;
  1567. }
  1568. if ( viewportWidth <= 782 ) {
  1569. if ( ! wpResponsiveActive ) {
  1570. $document.trigger( 'wp-responsive-activate' );
  1571. wpResponsiveActive = true;
  1572. }
  1573. } else {
  1574. if ( wpResponsiveActive ) {
  1575. $document.trigger( 'wp-responsive-deactivate' );
  1576. wpResponsiveActive = false;
  1577. }
  1578. }
  1579. if ( viewportWidth <= 480 ) {
  1580. this.enableOverlay();
  1581. } else {
  1582. this.disableOverlay();
  1583. }
  1584. this.maybeDisableSortables();
  1585. },
  1586. /**
  1587. * Inserts a responsive overlay and toggles the window.
  1588. *
  1589. * @since 3.8.0
  1590. *
  1591. * @return {void}
  1592. */
  1593. enableOverlay: function() {
  1594. if ( $overlay.length === 0 ) {
  1595. $overlay = $( '<div id="wp-responsive-overlay"></div>' )
  1596. .insertAfter( '#wpcontent' )
  1597. .hide()
  1598. .on( 'click.wp-responsive', function() {
  1599. $toolbar.find( '.menupop.hover' ).removeClass( 'hover' );
  1600. $( this ).hide();
  1601. });
  1602. }
  1603. $toolbarPopups.on( 'click.wp-responsive', function() {
  1604. $overlay.show();
  1605. });
  1606. },
  1607. /**
  1608. * Disables the responsive overlay and removes the overlay.
  1609. *
  1610. * @since 3.8.0
  1611. *
  1612. * @return {void}
  1613. */
  1614. disableOverlay: function() {
  1615. $toolbarPopups.off( 'click.wp-responsive' );
  1616. $overlay.hide();
  1617. },
  1618. /**
  1619. * Disables sortables.
  1620. *
  1621. * @since 3.8.0
  1622. *
  1623. * @return {void}
  1624. */
  1625. disableSortables: function() {
  1626. if ( $sortables.length ) {
  1627. try {
  1628. $sortables.sortable( 'disable' );
  1629. $sortables.find( '.ui-sortable-handle' ).addClass( 'is-non-sortable' );
  1630. } catch ( e ) {}
  1631. }
  1632. },
  1633. /**
  1634. * Enables sortables.
  1635. *
  1636. * @since 3.8.0
  1637. *
  1638. * @return {void}
  1639. */
  1640. enableSortables: function() {
  1641. if ( $sortables.length ) {
  1642. try {
  1643. $sortables.sortable( 'enable' );
  1644. $sortables.find( '.ui-sortable-handle' ).removeClass( 'is-non-sortable' );
  1645. } catch ( e ) {}
  1646. }
  1647. }
  1648. };
  1649. /**
  1650. * Add an ARIA role `button` to elements that behave like UI controls when JavaScript is on.
  1651. *
  1652. * @since 4.5.0
  1653. *
  1654. * @return {void}
  1655. */
  1656. function aria_button_if_js() {
  1657. $( '.aria-button-if-js' ).attr( 'role', 'button' );
  1658. }
  1659. $( document ).on( 'ajaxComplete', function() {
  1660. aria_button_if_js();
  1661. });
  1662. /**
  1663. * Get the viewport width.
  1664. *
  1665. * @since 4.7.0
  1666. *
  1667. * @return {number|boolean} The current viewport width or false if the
  1668. * browser doesn't support innerWidth (IE < 9).
  1669. */
  1670. function getViewportWidth() {
  1671. var viewportWidth = false;
  1672. if ( window.innerWidth ) {
  1673. // On phones, window.innerWidth is affected by zooming.
  1674. viewportWidth = Math.max( window.innerWidth, document.documentElement.clientWidth );
  1675. }
  1676. return viewportWidth;
  1677. }
  1678. /**
  1679. * Sets the admin menu collapsed/expanded state.
  1680. *
  1681. * Sets the global variable `menuState` and triggers a custom event passing
  1682. * the current menu state.
  1683. *
  1684. * @since 4.7.0
  1685. *
  1686. * @return {void}
  1687. */
  1688. function setMenuState() {
  1689. var viewportWidth = getViewportWidth() || 961;
  1690. if ( viewportWidth <= 782 ) {
  1691. menuState = 'responsive';
  1692. } else if ( $body.hasClass( 'folded' ) || ( $body.hasClass( 'auto-fold' ) && viewportWidth <= 960 && viewportWidth > 782 ) ) {
  1693. menuState = 'folded';
  1694. } else {
  1695. menuState = 'open';
  1696. }
  1697. $document.trigger( 'wp-menu-state-set', { state: menuState } );
  1698. }
  1699. // Set the menu state when the window gets resized.
  1700. $document.on( 'wp-window-resized.set-menu-state', setMenuState );
  1701. /**
  1702. * Sets ARIA attributes on the collapse/expand menu button.
  1703. *
  1704. * When the admin menu is open or folded, updates the `aria-expanded` and
  1705. * `aria-label` attributes of the button to give feedback to assistive
  1706. * technologies. In the responsive view, the button is always hidden.
  1707. *
  1708. * @since 4.7.0
  1709. *
  1710. * @return {void}
  1711. */
  1712. $document.on( 'wp-menu-state-set wp-collapse-menu', function( event, eventData ) {
  1713. var $collapseButton = $( '#collapse-button' ),
  1714. ariaExpanded, ariaLabelText;
  1715. if ( 'folded' === eventData.state ) {
  1716. ariaExpanded = 'false';
  1717. ariaLabelText = __( 'Expand Main menu' );
  1718. } else {
  1719. ariaExpanded = 'true';
  1720. ariaLabelText = __( 'Collapse Main menu' );
  1721. }
  1722. $collapseButton.attr({
  1723. 'aria-expanded': ariaExpanded,
  1724. 'aria-label': ariaLabelText
  1725. });
  1726. });
  1727. window.wpResponsive.init();
  1728. setPinMenu();
  1729. setMenuState();
  1730. currentMenuItemHasPopup();
  1731. makeNoticesDismissible();
  1732. aria_button_if_js();
  1733. $document.on( 'wp-pin-menu wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu );
  1734. // Set initial focus on a specific element.
  1735. $( '.wp-initial-focus' ).trigger( 'focus' );
  1736. // Toggle update details on update-core.php.
  1737. $body.on( 'click', '.js-update-details-toggle', function() {
  1738. var $updateNotice = $( this ).closest( '.js-update-details' ),
  1739. $progressDiv = $( '#' + $updateNotice.data( 'update-details' ) );
  1740. /*
  1741. * When clicking on "Show details" move the progress div below the update
  1742. * notice. Make sure it gets moved just the first time.
  1743. */
  1744. if ( ! $progressDiv.hasClass( 'update-details-moved' ) ) {
  1745. $progressDiv.insertAfter( $updateNotice ).addClass( 'update-details-moved' );
  1746. }
  1747. // Toggle the progress div visibility.
  1748. $progressDiv.toggle();
  1749. // Toggle the Show Details button expanded state.
  1750. $( this ).attr( 'aria-expanded', $progressDiv.is( ':visible' ) );
  1751. });
  1752. });
  1753. /**
  1754. * Hides the update button for expired plugin or theme uploads.
  1755. *
  1756. * On the "Update plugin/theme from uploaded zip" screen, once the upload has expired,
  1757. * hides the "Replace current with uploaded" button and displays a warning.
  1758. *
  1759. * @since 5.5.0
  1760. */
  1761. $( function( $ ) {
  1762. var $overwrite, $warning;
  1763. if ( ! $body.hasClass( 'update-php' ) ) {
  1764. return;
  1765. }
  1766. $overwrite = $( 'a.update-from-upload-overwrite' );
  1767. $warning = $( '.update-from-upload-expired' );
  1768. if ( ! $overwrite.length || ! $warning.length ) {
  1769. return;
  1770. }
  1771. window.setTimeout(
  1772. function() {
  1773. $overwrite.hide();
  1774. $warning.removeClass( 'hidden' );
  1775. if ( window.wp && window.wp.a11y ) {
  1776. window.wp.a11y.speak( $warning.text() );
  1777. }
  1778. },
  1779. 7140000 // 119 minutes. The uploaded file is deleted after 2 hours.
  1780. );
  1781. } );
  1782. // Fire a custom jQuery event at the end of window resize.
  1783. ( function() {
  1784. var timeout;
  1785. /**
  1786. * Triggers the WP window-resize event.
  1787. *
  1788. * @since 3.8.0
  1789. *
  1790. * @return {void}
  1791. */
  1792. function triggerEvent() {
  1793. $document.trigger( 'wp-window-resized' );
  1794. }
  1795. /**
  1796. * Fires the trigger event again after 200 ms.
  1797. *
  1798. * @since 3.8.0
  1799. *
  1800. * @return {void}
  1801. */
  1802. function fireOnce() {
  1803. window.clearTimeout( timeout );
  1804. timeout = window.setTimeout( triggerEvent, 200 );
  1805. }
  1806. $window.on( 'resize.wp-fire-once', fireOnce );
  1807. }());
  1808. // Make Windows 8 devices play along nicely.
  1809. (function(){
  1810. if ( '-ms-user-select' in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/) ) {
  1811. var msViewportStyle = document.createElement( 'style' );
  1812. msViewportStyle.appendChild(
  1813. document.createTextNode( '@-ms-viewport{width:auto!important}' )
  1814. );
  1815. document.getElementsByTagName( 'head' )[0].appendChild( msViewportStyle );
  1816. }
  1817. })();
  1818. }( jQuery, window ));