common.js 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080
  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.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. });
  580. $document.trigger( 'screen:options:close' );
  581. }
  582. };
  583. /**
  584. * Initializes the help tabs in the help panel.
  585. *
  586. * @param {Event} e The event object.
  587. *
  588. * @return {void}
  589. */
  590. $('.contextual-help-tabs').on( 'click', 'a', function(e) {
  591. var link = $(this),
  592. panel;
  593. e.preventDefault();
  594. // Don't do anything if the click is for the tab already showing.
  595. if ( link.is('.active a') )
  596. return false;
  597. // Links.
  598. $('.contextual-help-tabs .active').removeClass('active');
  599. link.parent('li').addClass('active');
  600. panel = $( link.attr('href') );
  601. // Panels.
  602. $('.help-tab-content').not( panel ).removeClass('active').hide();
  603. panel.addClass('active').show();
  604. });
  605. /**
  606. * Update custom permalink structure via buttons.
  607. */
  608. var permalinkStructureFocused = false,
  609. $permalinkStructure = $( '#permalink_structure' ),
  610. $permalinkStructureInputs = $( '.permalink-structure input:radio' ),
  611. $permalinkCustomSelection = $( '#custom_selection' ),
  612. $availableStructureTags = $( '.form-table.permalink-structure .available-structure-tags button' );
  613. // Change permalink structure input when selecting one of the common structures.
  614. $permalinkStructureInputs.on( 'change', function() {
  615. if ( 'custom' === this.value ) {
  616. return;
  617. }
  618. $permalinkStructure.val( this.value );
  619. // Update button states after selection.
  620. $availableStructureTags.each( function() {
  621. changeStructureTagButtonState( $( this ) );
  622. } );
  623. } );
  624. $permalinkStructure.on( 'click input', function() {
  625. $permalinkCustomSelection.prop( 'checked', true );
  626. } );
  627. // Check if the permalink structure input field has had focus at least once.
  628. $permalinkStructure.on( 'focus', function( event ) {
  629. permalinkStructureFocused = true;
  630. $( this ).off( event );
  631. } );
  632. /**
  633. * Enables or disables a structure tag button depending on its usage.
  634. *
  635. * If the structure is already used in the custom permalink structure,
  636. * it will be disabled.
  637. *
  638. * @param {Object} button Button jQuery object.
  639. */
  640. function changeStructureTagButtonState( button ) {
  641. if ( -1 !== $permalinkStructure.val().indexOf( button.text().trim() ) ) {
  642. button.attr( 'data-label', button.attr( 'aria-label' ) );
  643. button.attr( 'aria-label', button.attr( 'data-used' ) );
  644. button.attr( 'aria-pressed', true );
  645. button.addClass( 'active' );
  646. } else if ( button.attr( 'data-label' ) ) {
  647. button.attr( 'aria-label', button.attr( 'data-label' ) );
  648. button.attr( 'aria-pressed', false );
  649. button.removeClass( 'active' );
  650. }
  651. }
  652. // Check initial button state.
  653. $availableStructureTags.each( function() {
  654. changeStructureTagButtonState( $( this ) );
  655. } );
  656. // Observe permalink structure field and disable buttons of tags that are already present.
  657. $permalinkStructure.on( 'change', function() {
  658. $availableStructureTags.each( function() {
  659. changeStructureTagButtonState( $( this ) );
  660. } );
  661. } );
  662. $availableStructureTags.on( 'click', function() {
  663. var permalinkStructureValue = $permalinkStructure.val(),
  664. selectionStart = $permalinkStructure[ 0 ].selectionStart,
  665. selectionEnd = $permalinkStructure[ 0 ].selectionEnd,
  666. textToAppend = $( this ).text().trim(),
  667. textToAnnounce = $( this ).attr( 'data-added' ),
  668. newSelectionStart;
  669. // Remove structure tag if already part of the structure.
  670. if ( -1 !== permalinkStructureValue.indexOf( textToAppend ) ) {
  671. permalinkStructureValue = permalinkStructureValue.replace( textToAppend + '/', '' );
  672. $permalinkStructure.val( '/' === permalinkStructureValue ? '' : permalinkStructureValue );
  673. // Announce change to screen readers.
  674. $( '#custom_selection_updated' ).text( textToAnnounce );
  675. // Disable button.
  676. changeStructureTagButtonState( $( this ) );
  677. return;
  678. }
  679. // Input field never had focus, move selection to end of input.
  680. if ( ! permalinkStructureFocused && 0 === selectionStart && 0 === selectionEnd ) {
  681. selectionStart = selectionEnd = permalinkStructureValue.length;
  682. }
  683. $permalinkCustomSelection.prop( 'checked', true );
  684. // Prepend and append slashes if necessary.
  685. if ( '/' !== permalinkStructureValue.substr( 0, selectionStart ).substr( -1 ) ) {
  686. textToAppend = '/' + textToAppend;
  687. }
  688. if ( '/' !== permalinkStructureValue.substr( selectionEnd, 1 ) ) {
  689. textToAppend = textToAppend + '/';
  690. }
  691. // Insert structure tag at the specified position.
  692. $permalinkStructure.val( permalinkStructureValue.substr( 0, selectionStart ) + textToAppend + permalinkStructureValue.substr( selectionEnd ) );
  693. // Announce change to screen readers.
  694. $( '#custom_selection_updated' ).text( textToAnnounce );
  695. // Disable button.
  696. changeStructureTagButtonState( $( this ) );
  697. // If input had focus give it back with cursor right after appended text.
  698. if ( permalinkStructureFocused && $permalinkStructure[0].setSelectionRange ) {
  699. newSelectionStart = ( permalinkStructureValue.substr( 0, selectionStart ) + textToAppend ).length;
  700. $permalinkStructure[0].setSelectionRange( newSelectionStart, newSelectionStart );
  701. $permalinkStructure.trigger( 'focus' );
  702. }
  703. } );
  704. $( function() {
  705. var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions,
  706. lastClicked = false,
  707. pageInput = $('input.current-page'),
  708. currentPage = pageInput.val(),
  709. isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ),
  710. isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1,
  711. $adminMenuWrap = $( '#adminmenuwrap' ),
  712. $wpwrap = $( '#wpwrap' ),
  713. $adminmenu = $( '#adminmenu' ),
  714. $overlay = $( '#wp-responsive-overlay' ),
  715. $toolbar = $( '#wp-toolbar' ),
  716. $toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ),
  717. $sortables = $('.meta-box-sortables'),
  718. wpResponsiveActive = false,
  719. $adminbar = $( '#wpadminbar' ),
  720. lastScrollPosition = 0,
  721. pinnedMenuTop = false,
  722. pinnedMenuBottom = false,
  723. menuTop = 0,
  724. menuState,
  725. menuIsPinned = false,
  726. height = {
  727. window: $window.height(),
  728. wpwrap: $wpwrap.height(),
  729. adminbar: $adminbar.height(),
  730. menu: $adminMenuWrap.height()
  731. },
  732. $headerEnd = $( '.wp-header-end' );
  733. /**
  734. * Makes the fly-out submenu header clickable, when the menu is folded.
  735. *
  736. * @param {Event} e The event object.
  737. *
  738. * @return {void}
  739. */
  740. $adminmenu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){
  741. $(e.target).parent().siblings('a').get(0).click();
  742. });
  743. /**
  744. * Collapses the admin menu.
  745. *
  746. * @return {void}
  747. */
  748. $( '#collapse-button' ).on( 'click.collapse-menu', function() {
  749. var viewportWidth = getViewportWidth() || 961;
  750. // Reset any compensation for submenus near the bottom of the screen.
  751. $('#adminmenu div.wp-submenu').css('margin-top', '');
  752. if ( viewportWidth <= 960 ) {
  753. if ( $body.hasClass('auto-fold') ) {
  754. $body.removeClass('auto-fold').removeClass('folded');
  755. setUserSetting('unfold', 1);
  756. setUserSetting('mfold', 'o');
  757. menuState = 'open';
  758. } else {
  759. $body.addClass('auto-fold');
  760. setUserSetting('unfold', 0);
  761. menuState = 'folded';
  762. }
  763. } else {
  764. if ( $body.hasClass('folded') ) {
  765. $body.removeClass('folded');
  766. setUserSetting('mfold', 'o');
  767. menuState = 'open';
  768. } else {
  769. $body.addClass('folded');
  770. setUserSetting('mfold', 'f');
  771. menuState = 'folded';
  772. }
  773. }
  774. $document.trigger( 'wp-collapse-menu', { state: menuState } );
  775. });
  776. /**
  777. * Handles the `aria-haspopup` attribute on the current menu item when it has a submenu.
  778. *
  779. * @since 4.4.0
  780. *
  781. * @return {void}
  782. */
  783. function currentMenuItemHasPopup() {
  784. var $current = $( 'a.wp-has-current-submenu' );
  785. if ( 'folded' === menuState ) {
  786. // When folded or auto-folded and not responsive view, the current menu item does have a fly-out sub-menu.
  787. $current.attr( 'aria-haspopup', 'true' );
  788. } else {
  789. // When expanded or in responsive view, reset aria-haspopup.
  790. $current.attr( 'aria-haspopup', 'false' );
  791. }
  792. }
  793. $document.on( 'wp-menu-state-set wp-collapse-menu wp-responsive-activate wp-responsive-deactivate', currentMenuItemHasPopup );
  794. /**
  795. * Ensures an admin submenu is within the visual viewport.
  796. *
  797. * @since 4.1.0
  798. *
  799. * @param {jQuery} $menuItem The parent menu item containing the submenu.
  800. *
  801. * @return {void}
  802. */
  803. function adjustSubmenu( $menuItem ) {
  804. var bottomOffset, pageHeight, adjustment, theFold, menutop, wintop, maxtop,
  805. $submenu = $menuItem.find( '.wp-submenu' );
  806. menutop = $menuItem.offset().top;
  807. wintop = $window.scrollTop();
  808. maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar.
  809. bottomOffset = menutop + $submenu.height() + 1; // Bottom offset of the menu.
  810. pageHeight = $wpwrap.height(); // Height of the entire page.
  811. adjustment = 60 + bottomOffset - pageHeight;
  812. theFold = $window.height() + wintop - 50; // The fold.
  813. if ( theFold < ( bottomOffset - adjustment ) ) {
  814. adjustment = bottomOffset - theFold;
  815. }
  816. if ( adjustment > maxtop ) {
  817. adjustment = maxtop;
  818. }
  819. if ( adjustment > 1 ) {
  820. $submenu.css( 'margin-top', '-' + adjustment + 'px' );
  821. } else {
  822. $submenu.css( 'margin-top', '' );
  823. }
  824. }
  825. if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // Touch screen device.
  826. // iOS Safari works with touchstart, the rest work with click.
  827. mobileEvent = isIOS ? 'touchstart' : 'click';
  828. /**
  829. * Closes any open submenus when touch/click is not on the menu.
  830. *
  831. * @param {Event} e The event object.
  832. *
  833. * @return {void}
  834. */
  835. $body.on( mobileEvent+'.wp-mobile-hover', function(e) {
  836. if ( $adminmenu.data('wp-responsive') ) {
  837. return;
  838. }
  839. if ( ! $( e.target ).closest( '#adminmenu' ).length ) {
  840. $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' );
  841. }
  842. });
  843. /**
  844. * Handles the opening or closing the submenu based on the mobile click|touch event.
  845. *
  846. * @param {Event} event The event object.
  847. *
  848. * @return {void}
  849. */
  850. $adminmenu.find( 'a.wp-has-submenu' ).on( mobileEvent + '.wp-mobile-hover', function( event ) {
  851. var $menuItem = $(this).parent();
  852. if ( $adminmenu.data( 'wp-responsive' ) ) {
  853. return;
  854. }
  855. /*
  856. * Show the sub instead of following the link if:
  857. * - the submenu is not open.
  858. * - the submenu is not shown inline or the menu is not folded.
  859. */
  860. if ( ! $menuItem.hasClass( 'opensub' ) && ( ! $menuItem.hasClass( 'wp-menu-open' ) || $menuItem.width() < 40 ) ) {
  861. event.preventDefault();
  862. adjustSubmenu( $menuItem );
  863. $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' );
  864. $menuItem.addClass('opensub');
  865. }
  866. });
  867. }
  868. if ( ! isIOS && ! isAndroid ) {
  869. $adminmenu.find( 'li.wp-has-submenu' ).hoverIntent({
  870. /**
  871. * Opens the submenu when hovered over the menu item for desktops.
  872. *
  873. * @return {void}
  874. */
  875. over: function() {
  876. var $menuItem = $( this ),
  877. $submenu = $menuItem.find( '.wp-submenu' ),
  878. top = parseInt( $submenu.css( 'top' ), 10 );
  879. if ( isNaN( top ) || top > -5 ) { // The submenu is visible.
  880. return;
  881. }
  882. if ( $adminmenu.data( 'wp-responsive' ) ) {
  883. // The menu is in responsive mode, bail.
  884. return;
  885. }
  886. adjustSubmenu( $menuItem );
  887. $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' );
  888. $menuItem.addClass( 'opensub' );
  889. },
  890. /**
  891. * Closes the submenu when no longer hovering the menu item.
  892. *
  893. * @return {void}
  894. */
  895. out: function(){
  896. if ( $adminmenu.data( 'wp-responsive' ) ) {
  897. // The menu is in responsive mode, bail.
  898. return;
  899. }
  900. $( this ).removeClass( 'opensub' ).find( '.wp-submenu' ).css( 'margin-top', '' );
  901. },
  902. timeout: 200,
  903. sensitivity: 7,
  904. interval: 90
  905. });
  906. /**
  907. * Opens the submenu on when focused on the menu item.
  908. *
  909. * @param {Event} event The event object.
  910. *
  911. * @return {void}
  912. */
  913. $adminmenu.on( 'focus.adminmenu', '.wp-submenu a', function( event ) {
  914. if ( $adminmenu.data( 'wp-responsive' ) ) {
  915. // The menu is in responsive mode, bail.
  916. return;
  917. }
  918. $( event.target ).closest( 'li.menu-top' ).addClass( 'opensub' );
  919. /**
  920. * Closes the submenu on blur from the menu item.
  921. *
  922. * @param {Event} event The event object.
  923. *
  924. * @return {void}
  925. */
  926. }).on( 'blur.adminmenu', '.wp-submenu a', function( event ) {
  927. if ( $adminmenu.data( 'wp-responsive' ) ) {
  928. return;
  929. }
  930. $( event.target ).closest( 'li.menu-top' ).removeClass( 'opensub' );
  931. /**
  932. * Adjusts the size for the submenu.
  933. *
  934. * @return {void}
  935. */
  936. }).find( 'li.wp-has-submenu.wp-not-current-submenu' ).on( 'focusin.adminmenu', function() {
  937. adjustSubmenu( $( this ) );
  938. });
  939. }
  940. /*
  941. * The `.below-h2` class is here just for backward compatibility with plugins
  942. * that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570.
  943. * If '.wp-header-end' is found, append the notices after it otherwise
  944. * after the first h1 or h2 heading found within the main content.
  945. */
  946. if ( ! $headerEnd.length ) {
  947. $headerEnd = $( '.wrap h1, .wrap h2' ).first();
  948. }
  949. $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $headerEnd );
  950. /**
  951. * Makes notices dismissible.
  952. *
  953. * @since 4.4.0
  954. *
  955. * @return {void}
  956. */
  957. function makeNoticesDismissible() {
  958. $( '.notice.is-dismissible' ).each( function() {
  959. var $el = $( this ),
  960. $button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' );
  961. if ( $el.find( '.notice-dismiss' ).length ) {
  962. return;
  963. }
  964. // Ensure plain text.
  965. $button.find( '.screen-reader-text' ).text( __( 'Dismiss this notice.' ) );
  966. $button.on( 'click.wp-dismiss-notice', function( event ) {
  967. event.preventDefault();
  968. $el.fadeTo( 100, 0, function() {
  969. $el.slideUp( 100, function() {
  970. $el.remove();
  971. });
  972. });
  973. });
  974. $el.append( $button );
  975. });
  976. }
  977. $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 );
  978. // Init screen meta.
  979. screenMeta.init();
  980. /**
  981. * Checks a checkbox.
  982. *
  983. * This event needs to be delegated. Ticket #37973.
  984. *
  985. * @return {boolean} Returns whether a checkbox is checked or not.
  986. */
  987. $body.on( 'click', 'tbody > tr > .check-column :checkbox', function( event ) {
  988. // Shift click to select a range of checkboxes.
  989. if ( 'undefined' == event.shiftKey ) { return true; }
  990. if ( event.shiftKey ) {
  991. if ( !lastClicked ) { return true; }
  992. checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' ).filter( ':visible:enabled' );
  993. first = checks.index( lastClicked );
  994. last = checks.index( this );
  995. checked = $(this).prop('checked');
  996. if ( 0 < first && 0 < last && first != last ) {
  997. sliced = ( last > first ) ? checks.slice( first, last ) : checks.slice( last, first );
  998. sliced.prop( 'checked', function() {
  999. if ( $(this).closest('tr').is(':visible') )
  1000. return checked;
  1001. return false;
  1002. });
  1003. }
  1004. }
  1005. lastClicked = this;
  1006. // Toggle the "Select all" checkboxes depending if the other ones are all checked or not.
  1007. var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible:enabled').not(':checked');
  1008. /**
  1009. * Determines if all checkboxes are checked.
  1010. *
  1011. * @return {boolean} Returns true if there are no unchecked checkboxes.
  1012. */
  1013. $(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() {
  1014. return ( 0 === unchecked.length );
  1015. });
  1016. return true;
  1017. });
  1018. /**
  1019. * Controls all the toggles on bulk toggle change.
  1020. *
  1021. * When the bulk checkbox is changed, all the checkboxes in the tables are changed accordingly.
  1022. * When the shift-button is pressed while changing the bulk checkbox the checkboxes in the table are inverted.
  1023. *
  1024. * This event needs to be delegated. Ticket #37973.
  1025. *
  1026. * @param {Event} event The event object.
  1027. *
  1028. * @return {boolean}
  1029. */
  1030. $body.on( 'click.wp-toggle-checkboxes', 'thead .check-column :checkbox, tfoot .check-column :checkbox', function( event ) {
  1031. var $this = $(this),
  1032. $table = $this.closest( 'table' ),
  1033. controlChecked = $this.prop('checked'),
  1034. toggle = event.shiftKey || $this.data('wp-toggle');
  1035. $table.children( 'tbody' ).filter(':visible')
  1036. .children().children('.check-column').find(':checkbox')
  1037. /**
  1038. * Updates the checked state on the checkbox in the table.
  1039. *
  1040. * @return {boolean} True checks the checkbox, False unchecks the checkbox.
  1041. */
  1042. .prop('checked', function() {
  1043. if ( $(this).is(':hidden,:disabled') ) {
  1044. return false;
  1045. }
  1046. if ( toggle ) {
  1047. return ! $(this).prop( 'checked' );
  1048. } else if ( controlChecked ) {
  1049. return true;
  1050. }
  1051. return false;
  1052. });
  1053. $table.children('thead, tfoot').filter(':visible')
  1054. .children().children('.check-column').find(':checkbox')
  1055. /**
  1056. * Syncs the bulk checkboxes on the top and bottom of the table.
  1057. *
  1058. * @return {boolean} True checks the checkbox, False unchecks the checkbox.
  1059. */
  1060. .prop('checked', function() {
  1061. if ( toggle ) {
  1062. return false;
  1063. } else if ( controlChecked ) {
  1064. return true;
  1065. }
  1066. return false;
  1067. });
  1068. });
  1069. /**
  1070. * Marries a secondary control to its primary control.
  1071. *
  1072. * @param {jQuery} topSelector The top selector element.
  1073. * @param {jQuery} topSubmit The top submit element.
  1074. * @param {jQuery} bottomSelector The bottom selector element.
  1075. * @param {jQuery} bottomSubmit The bottom submit element.
  1076. * @return {void}
  1077. */
  1078. function marryControls( topSelector, topSubmit, bottomSelector, bottomSubmit ) {
  1079. /**
  1080. * Updates the primary selector when the secondary selector is changed.
  1081. *
  1082. * @since 5.7.0
  1083. *
  1084. * @return {void}
  1085. */
  1086. function updateTopSelector() {
  1087. topSelector.val($(this).val());
  1088. }
  1089. bottomSelector.on('change', updateTopSelector);
  1090. /**
  1091. * Updates the secondary selector when the primary selector is changed.
  1092. *
  1093. * @since 5.7.0
  1094. *
  1095. * @return {void}
  1096. */
  1097. function updateBottomSelector() {
  1098. bottomSelector.val($(this).val());
  1099. }
  1100. topSelector.on('change', updateBottomSelector);
  1101. /**
  1102. * Triggers the primary submit when then secondary submit is clicked.
  1103. *
  1104. * @since 5.7.0
  1105. *
  1106. * @return {void}
  1107. */
  1108. function triggerSubmitClick(e) {
  1109. e.preventDefault();
  1110. e.stopPropagation();
  1111. topSubmit.trigger('click');
  1112. }
  1113. bottomSubmit.on('click', triggerSubmitClick);
  1114. }
  1115. // Marry the secondary "Bulk actions" controls to the primary controls:
  1116. marryControls( $('#bulk-action-selector-top'), $('#doaction'), $('#bulk-action-selector-bottom'), $('#doaction2') );
  1117. // Marry the secondary "Change role to" controls to the primary controls:
  1118. marryControls( $('#new_role'), $('#changeit'), $('#new_role2'), $('#changeit2') );
  1119. /**
  1120. * Shows row actions on focus of its parent container element or any other elements contained within.
  1121. *
  1122. * @return {void}
  1123. */
  1124. $( '#wpbody-content' ).on({
  1125. focusin: function() {
  1126. clearTimeout( transitionTimeout );
  1127. focusedRowActions = $( this ).find( '.row-actions' );
  1128. // transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help.
  1129. $( '.row-actions' ).not( this ).removeClass( 'visible' );
  1130. focusedRowActions.addClass( 'visible' );
  1131. },
  1132. focusout: function() {
  1133. // Tabbing between post title and .row-actions links needs a brief pause, otherwise
  1134. // the .row-actions div gets hidden in transit in some browsers (ahem, Firefox).
  1135. transitionTimeout = setTimeout( function() {
  1136. focusedRowActions.removeClass( 'visible' );
  1137. }, 30 );
  1138. }
  1139. }, '.table-view-list .has-row-actions' );
  1140. // Toggle list table rows on small screens.
  1141. $( 'tbody' ).on( 'click', '.toggle-row', function() {
  1142. $( this ).closest( 'tr' ).toggleClass( 'is-expanded' );
  1143. });
  1144. $('#default-password-nag-no').on( 'click', function() {
  1145. setUserSetting('default_password_nag', 'hide');
  1146. $('div.default-password-nag').hide();
  1147. return false;
  1148. });
  1149. /**
  1150. * Handles tab keypresses in theme and plugin file editor textareas.
  1151. *
  1152. * @param {Event} e The event object.
  1153. *
  1154. * @return {void}
  1155. */
  1156. $('#newcontent').on('keydown.wpevent_InsertTab', function(e) {
  1157. var el = e.target, selStart, selEnd, val, scroll, sel;
  1158. // After pressing escape key (keyCode: 27), the tab key should tab out of the textarea.
  1159. if ( e.keyCode == 27 ) {
  1160. // When pressing Escape: Opera 12 and 27 blur form fields, IE 8 clears them.
  1161. e.preventDefault();
  1162. $(el).data('tab-out', true);
  1163. return;
  1164. }
  1165. // Only listen for plain tab key (keyCode: 9) without any modifiers.
  1166. if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey )
  1167. return;
  1168. // After tabbing out, reset it so next time the tab key can be used again.
  1169. if ( $(el).data('tab-out') ) {
  1170. $(el).data('tab-out', false);
  1171. return;
  1172. }
  1173. selStart = el.selectionStart;
  1174. selEnd = el.selectionEnd;
  1175. val = el.value;
  1176. // If any text is selected, replace the selection with a tab character.
  1177. if ( document.selection ) {
  1178. el.focus();
  1179. sel = document.selection.createRange();
  1180. sel.text = '\t';
  1181. } else if ( selStart >= 0 ) {
  1182. scroll = this.scrollTop;
  1183. el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) );
  1184. el.selectionStart = el.selectionEnd = selStart + 1;
  1185. this.scrollTop = scroll;
  1186. }
  1187. // Cancel the regular tab functionality, to prevent losing focus of the textarea.
  1188. if ( e.stopPropagation )
  1189. e.stopPropagation();
  1190. if ( e.preventDefault )
  1191. e.preventDefault();
  1192. });
  1193. // Reset page number variable for new filters/searches but not for bulk actions. See #17685.
  1194. if ( pageInput.length ) {
  1195. /**
  1196. * Handles pagination variable when filtering the list table.
  1197. *
  1198. * Set the pagination argument to the first page when the post-filter form is submitted.
  1199. * This happens when pressing the 'filter' button on the list table page.
  1200. *
  1201. * The pagination argument should not be touched when the bulk action dropdowns are set to do anything.
  1202. *
  1203. * The form closest to the pageInput is the post-filter form.
  1204. *
  1205. * @return {void}
  1206. */
  1207. pageInput.closest('form').on( 'submit', function() {
  1208. /*
  1209. * action = bulk action dropdown at the top of the table
  1210. */
  1211. if ( $('select[name="action"]').val() == -1 && pageInput.val() == currentPage )
  1212. pageInput.val('1');
  1213. });
  1214. }
  1215. /**
  1216. * Resets the bulk actions when the search button is clicked.
  1217. *
  1218. * @return {void}
  1219. */
  1220. $('.search-box input[type="search"], .search-box input[type="submit"]').on( 'mousedown', function () {
  1221. $('select[name^="action"]').val('-1');
  1222. });
  1223. /**
  1224. * Scrolls into view when focus.scroll-into-view is triggered.
  1225. *
  1226. * @param {Event} e The event object.
  1227. *
  1228. * @return {void}
  1229. */
  1230. $('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){
  1231. if ( e.target.scrollIntoView )
  1232. e.target.scrollIntoView(false);
  1233. });
  1234. /**
  1235. * Disables the submit upload buttons when no data is entered.
  1236. *
  1237. * @return {void}
  1238. */
  1239. (function(){
  1240. var button, input, form = $('form.wp-upload-form');
  1241. // Exit when no upload form is found.
  1242. if ( ! form.length )
  1243. return;
  1244. button = form.find('input[type="submit"]');
  1245. input = form.find('input[type="file"]');
  1246. /**
  1247. * Determines if any data is entered in any file upload input.
  1248. *
  1249. * @since 3.5.0
  1250. *
  1251. * @return {void}
  1252. */
  1253. function toggleUploadButton() {
  1254. // When no inputs have a value, disable the upload buttons.
  1255. button.prop('disabled', '' === input.map( function() {
  1256. return $(this).val();
  1257. }).get().join(''));
  1258. }
  1259. // Update the status initially.
  1260. toggleUploadButton();
  1261. // Update the status when any file input changes.
  1262. input.on('change', toggleUploadButton);
  1263. })();
  1264. /**
  1265. * Pins the menu while distraction-free writing is enabled.
  1266. *
  1267. * @param {Event} event Event data.
  1268. *
  1269. * @since 4.1.0
  1270. *
  1271. * @return {void}
  1272. */
  1273. function pinMenu( event ) {
  1274. var windowPos = $window.scrollTop(),
  1275. resizing = ! event || event.type !== 'scroll';
  1276. if ( isIOS || $adminmenu.data( 'wp-responsive' ) ) {
  1277. return;
  1278. }
  1279. /*
  1280. * When the menu is higher than the window and smaller than the entire page.
  1281. * It should be adjusted to be able to see the entire menu.
  1282. *
  1283. * Otherwise it can be accessed normally.
  1284. */
  1285. if ( height.menu + height.adminbar < height.window ||
  1286. height.menu + height.adminbar + 20 > height.wpwrap ) {
  1287. unpinMenu();
  1288. return;
  1289. }
  1290. menuIsPinned = true;
  1291. // If the menu is higher than the window, compensate on scroll.
  1292. if ( height.menu + height.adminbar > height.window ) {
  1293. // Check for overscrolling, this happens when swiping up at the top of the document in modern browsers.
  1294. if ( windowPos < 0 ) {
  1295. // Stick the menu to the top.
  1296. if ( ! pinnedMenuTop ) {
  1297. pinnedMenuTop = true;
  1298. pinnedMenuBottom = false;
  1299. $adminMenuWrap.css({
  1300. position: 'fixed',
  1301. top: '',
  1302. bottom: ''
  1303. });
  1304. }
  1305. return;
  1306. } else if ( windowPos + height.window > $document.height() - 1 ) {
  1307. // When overscrolling at the bottom, stick the menu to the bottom.
  1308. if ( ! pinnedMenuBottom ) {
  1309. pinnedMenuBottom = true;
  1310. pinnedMenuTop = false;
  1311. $adminMenuWrap.css({
  1312. position: 'fixed',
  1313. top: '',
  1314. bottom: 0
  1315. });
  1316. }
  1317. return;
  1318. }
  1319. if ( windowPos > lastScrollPosition ) {
  1320. // When a down scroll has been detected.
  1321. // If it was pinned to the top, unpin and calculate relative scroll.
  1322. if ( pinnedMenuTop ) {
  1323. pinnedMenuTop = false;
  1324. // Calculate new offset position.
  1325. menuTop = $adminMenuWrap.offset().top - height.adminbar - ( windowPos - lastScrollPosition );
  1326. if ( menuTop + height.menu + height.adminbar < windowPos + height.window ) {
  1327. menuTop = windowPos + height.window - height.menu - height.adminbar;
  1328. }
  1329. $adminMenuWrap.css({
  1330. position: 'absolute',
  1331. top: menuTop,
  1332. bottom: ''
  1333. });
  1334. } else if ( ! pinnedMenuBottom && $adminMenuWrap.offset().top + height.menu < windowPos + height.window ) {
  1335. // Pin it to the bottom.
  1336. pinnedMenuBottom = true;
  1337. $adminMenuWrap.css({
  1338. position: 'fixed',
  1339. top: '',
  1340. bottom: 0
  1341. });
  1342. }
  1343. } else if ( windowPos < lastScrollPosition ) {
  1344. // When a scroll up is detected.
  1345. // If it was pinned to the bottom, unpin and calculate relative scroll.
  1346. if ( pinnedMenuBottom ) {
  1347. pinnedMenuBottom = false;
  1348. // Calculate new offset position.
  1349. menuTop = $adminMenuWrap.offset().top - height.adminbar + ( lastScrollPosition - windowPos );
  1350. if ( menuTop + height.menu > windowPos + height.window ) {
  1351. menuTop = windowPos;
  1352. }
  1353. $adminMenuWrap.css({
  1354. position: 'absolute',
  1355. top: menuTop,
  1356. bottom: ''
  1357. });
  1358. } else if ( ! pinnedMenuTop && $adminMenuWrap.offset().top >= windowPos + height.adminbar ) {
  1359. // Pin it to the top.
  1360. pinnedMenuTop = true;
  1361. $adminMenuWrap.css({
  1362. position: 'fixed',
  1363. top: '',
  1364. bottom: ''
  1365. });
  1366. }
  1367. } else if ( resizing ) {
  1368. // Window is being resized.
  1369. pinnedMenuTop = pinnedMenuBottom = false;
  1370. // Calculate the new offset.
  1371. menuTop = windowPos + height.window - height.menu - height.adminbar - 1;
  1372. if ( menuTop > 0 ) {
  1373. $adminMenuWrap.css({
  1374. position: 'absolute',
  1375. top: menuTop,
  1376. bottom: ''
  1377. });
  1378. } else {
  1379. unpinMenu();
  1380. }
  1381. }
  1382. }
  1383. lastScrollPosition = windowPos;
  1384. }
  1385. /**
  1386. * Determines the height of certain elements.
  1387. *
  1388. * @since 4.1.0
  1389. *
  1390. * @return {void}
  1391. */
  1392. function resetHeights() {
  1393. height = {
  1394. window: $window.height(),
  1395. wpwrap: $wpwrap.height(),
  1396. adminbar: $adminbar.height(),
  1397. menu: $adminMenuWrap.height()
  1398. };
  1399. }
  1400. /**
  1401. * Unpins the menu.
  1402. *
  1403. * @since 4.1.0
  1404. *
  1405. * @return {void}
  1406. */
  1407. function unpinMenu() {
  1408. if ( isIOS || ! menuIsPinned ) {
  1409. return;
  1410. }
  1411. pinnedMenuTop = pinnedMenuBottom = menuIsPinned = false;
  1412. $adminMenuWrap.css({
  1413. position: '',
  1414. top: '',
  1415. bottom: ''
  1416. });
  1417. }
  1418. /**
  1419. * Pins and unpins the menu when applicable.
  1420. *
  1421. * @since 4.1.0
  1422. *
  1423. * @return {void}
  1424. */
  1425. function setPinMenu() {
  1426. resetHeights();
  1427. if ( $adminmenu.data('wp-responsive') ) {
  1428. $body.removeClass( 'sticky-menu' );
  1429. unpinMenu();
  1430. } else if ( height.menu + height.adminbar > height.window ) {
  1431. pinMenu();
  1432. $body.removeClass( 'sticky-menu' );
  1433. } else {
  1434. $body.addClass( 'sticky-menu' );
  1435. unpinMenu();
  1436. }
  1437. }
  1438. if ( ! isIOS ) {
  1439. $window.on( 'scroll.pin-menu', pinMenu );
  1440. $document.on( 'tinymce-editor-init.pin-menu', function( event, editor ) {
  1441. editor.on( 'wp-autoresize', resetHeights );
  1442. });
  1443. }
  1444. /**
  1445. * Changes the sortables and responsiveness of metaboxes.
  1446. *
  1447. * @since 3.8.0
  1448. *
  1449. * @return {void}
  1450. */
  1451. window.wpResponsive = {
  1452. /**
  1453. * Initializes the wpResponsive object.
  1454. *
  1455. * @since 3.8.0
  1456. *
  1457. * @return {void}
  1458. */
  1459. init: function() {
  1460. var self = this;
  1461. this.maybeDisableSortables = this.maybeDisableSortables.bind( this );
  1462. // Modify functionality based on custom activate/deactivate event.
  1463. $document.on( 'wp-responsive-activate.wp-responsive', function() {
  1464. self.activate();
  1465. }).on( 'wp-responsive-deactivate.wp-responsive', function() {
  1466. self.deactivate();
  1467. });
  1468. $( '#wp-admin-bar-menu-toggle a' ).attr( 'aria-expanded', 'false' );
  1469. // Toggle sidebar when toggle is clicked.
  1470. $( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) {
  1471. event.preventDefault();
  1472. // Close any open toolbar submenus.
  1473. $adminbar.find( '.hover' ).removeClass( 'hover' );
  1474. $wpwrap.toggleClass( 'wp-responsive-open' );
  1475. if ( $wpwrap.hasClass( 'wp-responsive-open' ) ) {
  1476. $(this).find('a').attr( 'aria-expanded', 'true' );
  1477. $( '#adminmenu a:first' ).trigger( 'focus' );
  1478. } else {
  1479. $(this).find('a').attr( 'aria-expanded', 'false' );
  1480. }
  1481. } );
  1482. // Add menu events.
  1483. $adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) {
  1484. if ( ! $adminmenu.data('wp-responsive') ) {
  1485. return;
  1486. }
  1487. $( this ).parent( 'li' ).toggleClass( 'selected' );
  1488. event.preventDefault();
  1489. });
  1490. self.trigger();
  1491. $document.on( 'wp-window-resized.wp-responsive', this.trigger.bind( this ) );
  1492. // This needs to run later as UI Sortable may be initialized when the document is ready.
  1493. $window.on( 'load.wp-responsive', this.maybeDisableSortables );
  1494. $document.on( 'postbox-toggled', this.maybeDisableSortables );
  1495. // When the screen columns are changed, potentially disable sortables.
  1496. $( '#screen-options-wrap input' ).on( 'click', this.maybeDisableSortables );
  1497. },
  1498. /**
  1499. * Disable sortables if there is only one metabox, or the screen is in one column mode. Otherwise, enable sortables.
  1500. *
  1501. * @since 5.3.0
  1502. *
  1503. * @return {void}
  1504. */
  1505. maybeDisableSortables: function() {
  1506. var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth;
  1507. if (
  1508. ( width <= 782 ) ||
  1509. ( 1 >= $sortables.find( '.ui-sortable-handle:visible' ).length && jQuery( '.columns-prefs-1 input' ).prop( 'checked' ) )
  1510. ) {
  1511. this.disableSortables();
  1512. } else {
  1513. this.enableSortables();
  1514. }
  1515. },
  1516. /**
  1517. * Changes properties of body and admin menu.
  1518. *
  1519. * Pins and unpins the menu and adds the auto-fold class to the body.
  1520. * Makes the admin menu responsive and disables the metabox sortables.
  1521. *
  1522. * @since 3.8.0
  1523. *
  1524. * @return {void}
  1525. */
  1526. activate: function() {
  1527. setPinMenu();
  1528. if ( ! $body.hasClass( 'auto-fold' ) ) {
  1529. $body.addClass( 'auto-fold' );
  1530. }
  1531. $adminmenu.data( 'wp-responsive', 1 );
  1532. this.disableSortables();
  1533. },
  1534. /**
  1535. * Changes properties of admin menu and enables metabox sortables.
  1536. *
  1537. * Pin and unpin the menu.
  1538. * Removes the responsiveness of the admin menu and enables the metabox sortables.
  1539. *
  1540. * @since 3.8.0
  1541. *
  1542. * @return {void}
  1543. */
  1544. deactivate: function() {
  1545. setPinMenu();
  1546. $adminmenu.removeData('wp-responsive');
  1547. this.maybeDisableSortables();
  1548. },
  1549. /**
  1550. * Sets the responsiveness and enables the overlay based on the viewport width.
  1551. *
  1552. * @since 3.8.0
  1553. *
  1554. * @return {void}
  1555. */
  1556. trigger: function() {
  1557. var viewportWidth = getViewportWidth();
  1558. // Exclude IE < 9, it doesn't support @media CSS rules.
  1559. if ( ! viewportWidth ) {
  1560. return;
  1561. }
  1562. if ( viewportWidth <= 782 ) {
  1563. if ( ! wpResponsiveActive ) {
  1564. $document.trigger( 'wp-responsive-activate' );
  1565. wpResponsiveActive = true;
  1566. }
  1567. } else {
  1568. if ( wpResponsiveActive ) {
  1569. $document.trigger( 'wp-responsive-deactivate' );
  1570. wpResponsiveActive = false;
  1571. }
  1572. }
  1573. if ( viewportWidth <= 480 ) {
  1574. this.enableOverlay();
  1575. } else {
  1576. this.disableOverlay();
  1577. }
  1578. this.maybeDisableSortables();
  1579. },
  1580. /**
  1581. * Inserts a responsive overlay and toggles the window.
  1582. *
  1583. * @since 3.8.0
  1584. *
  1585. * @return {void}
  1586. */
  1587. enableOverlay: function() {
  1588. if ( $overlay.length === 0 ) {
  1589. $overlay = $( '<div id="wp-responsive-overlay"></div>' )
  1590. .insertAfter( '#wpcontent' )
  1591. .hide()
  1592. .on( 'click.wp-responsive', function() {
  1593. $toolbar.find( '.menupop.hover' ).removeClass( 'hover' );
  1594. $( this ).hide();
  1595. });
  1596. }
  1597. $toolbarPopups.on( 'click.wp-responsive', function() {
  1598. $overlay.show();
  1599. });
  1600. },
  1601. /**
  1602. * Disables the responsive overlay and removes the overlay.
  1603. *
  1604. * @since 3.8.0
  1605. *
  1606. * @return {void}
  1607. */
  1608. disableOverlay: function() {
  1609. $toolbarPopups.off( 'click.wp-responsive' );
  1610. $overlay.hide();
  1611. },
  1612. /**
  1613. * Disables sortables.
  1614. *
  1615. * @since 3.8.0
  1616. *
  1617. * @return {void}
  1618. */
  1619. disableSortables: function() {
  1620. if ( $sortables.length ) {
  1621. try {
  1622. $sortables.sortable( 'disable' );
  1623. $sortables.find( '.ui-sortable-handle' ).addClass( 'is-non-sortable' );
  1624. } catch ( e ) {}
  1625. }
  1626. },
  1627. /**
  1628. * Enables sortables.
  1629. *
  1630. * @since 3.8.0
  1631. *
  1632. * @return {void}
  1633. */
  1634. enableSortables: function() {
  1635. if ( $sortables.length ) {
  1636. try {
  1637. $sortables.sortable( 'enable' );
  1638. $sortables.find( '.ui-sortable-handle' ).removeClass( 'is-non-sortable' );
  1639. } catch ( e ) {}
  1640. }
  1641. }
  1642. };
  1643. /**
  1644. * Add an ARIA role `button` to elements that behave like UI controls when JavaScript is on.
  1645. *
  1646. * @since 4.5.0
  1647. *
  1648. * @return {void}
  1649. */
  1650. function aria_button_if_js() {
  1651. $( '.aria-button-if-js' ).attr( 'role', 'button' );
  1652. }
  1653. $( document ).on( 'ajaxComplete', function() {
  1654. aria_button_if_js();
  1655. });
  1656. /**
  1657. * Get the viewport width.
  1658. *
  1659. * @since 4.7.0
  1660. *
  1661. * @return {number|boolean} The current viewport width or false if the
  1662. * browser doesn't support innerWidth (IE < 9).
  1663. */
  1664. function getViewportWidth() {
  1665. var viewportWidth = false;
  1666. if ( window.innerWidth ) {
  1667. // On phones, window.innerWidth is affected by zooming.
  1668. viewportWidth = Math.max( window.innerWidth, document.documentElement.clientWidth );
  1669. }
  1670. return viewportWidth;
  1671. }
  1672. /**
  1673. * Sets the admin menu collapsed/expanded state.
  1674. *
  1675. * Sets the global variable `menuState` and triggers a custom event passing
  1676. * the current menu state.
  1677. *
  1678. * @since 4.7.0
  1679. *
  1680. * @return {void}
  1681. */
  1682. function setMenuState() {
  1683. var viewportWidth = getViewportWidth() || 961;
  1684. if ( viewportWidth <= 782 ) {
  1685. menuState = 'responsive';
  1686. } else if ( $body.hasClass( 'folded' ) || ( $body.hasClass( 'auto-fold' ) && viewportWidth <= 960 && viewportWidth > 782 ) ) {
  1687. menuState = 'folded';
  1688. } else {
  1689. menuState = 'open';
  1690. }
  1691. $document.trigger( 'wp-menu-state-set', { state: menuState } );
  1692. }
  1693. // Set the menu state when the window gets resized.
  1694. $document.on( 'wp-window-resized.set-menu-state', setMenuState );
  1695. /**
  1696. * Sets ARIA attributes on the collapse/expand menu button.
  1697. *
  1698. * When the admin menu is open or folded, updates the `aria-expanded` and
  1699. * `aria-label` attributes of the button to give feedback to assistive
  1700. * technologies. In the responsive view, the button is always hidden.
  1701. *
  1702. * @since 4.7.0
  1703. *
  1704. * @return {void}
  1705. */
  1706. $document.on( 'wp-menu-state-set wp-collapse-menu', function( event, eventData ) {
  1707. var $collapseButton = $( '#collapse-button' ),
  1708. ariaExpanded, ariaLabelText;
  1709. if ( 'folded' === eventData.state ) {
  1710. ariaExpanded = 'false';
  1711. ariaLabelText = __( 'Expand Main menu' );
  1712. } else {
  1713. ariaExpanded = 'true';
  1714. ariaLabelText = __( 'Collapse Main menu' );
  1715. }
  1716. $collapseButton.attr({
  1717. 'aria-expanded': ariaExpanded,
  1718. 'aria-label': ariaLabelText
  1719. });
  1720. });
  1721. window.wpResponsive.init();
  1722. setPinMenu();
  1723. setMenuState();
  1724. currentMenuItemHasPopup();
  1725. makeNoticesDismissible();
  1726. aria_button_if_js();
  1727. $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 );
  1728. // Set initial focus on a specific element.
  1729. $( '.wp-initial-focus' ).trigger( 'focus' );
  1730. // Toggle update details on update-core.php.
  1731. $body.on( 'click', '.js-update-details-toggle', function() {
  1732. var $updateNotice = $( this ).closest( '.js-update-details' ),
  1733. $progressDiv = $( '#' + $updateNotice.data( 'update-details' ) );
  1734. /*
  1735. * When clicking on "Show details" move the progress div below the update
  1736. * notice. Make sure it gets moved just the first time.
  1737. */
  1738. if ( ! $progressDiv.hasClass( 'update-details-moved' ) ) {
  1739. $progressDiv.insertAfter( $updateNotice ).addClass( 'update-details-moved' );
  1740. }
  1741. // Toggle the progress div visibility.
  1742. $progressDiv.toggle();
  1743. // Toggle the Show Details button expanded state.
  1744. $( this ).attr( 'aria-expanded', $progressDiv.is( ':visible' ) );
  1745. });
  1746. });
  1747. /**
  1748. * Hides the update button for expired plugin or theme uploads.
  1749. *
  1750. * On the "Update plugin/theme from uploaded zip" screen, once the upload has expired,
  1751. * hides the "Replace current with uploaded" button and displays a warning.
  1752. *
  1753. * @since 5.5.0
  1754. */
  1755. $( function( $ ) {
  1756. var $overwrite, $warning;
  1757. if ( ! $body.hasClass( 'update-php' ) ) {
  1758. return;
  1759. }
  1760. $overwrite = $( 'a.update-from-upload-overwrite' );
  1761. $warning = $( '.update-from-upload-expired' );
  1762. if ( ! $overwrite.length || ! $warning.length ) {
  1763. return;
  1764. }
  1765. window.setTimeout(
  1766. function() {
  1767. $overwrite.hide();
  1768. $warning.removeClass( 'hidden' );
  1769. if ( window.wp && window.wp.a11y ) {
  1770. window.wp.a11y.speak( $warning.text() );
  1771. }
  1772. },
  1773. 7140000 // 119 minutes. The uploaded file is deleted after 2 hours.
  1774. );
  1775. } );
  1776. // Fire a custom jQuery event at the end of window resize.
  1777. ( function() {
  1778. var timeout;
  1779. /**
  1780. * Triggers the WP window-resize event.
  1781. *
  1782. * @since 3.8.0
  1783. *
  1784. * @return {void}
  1785. */
  1786. function triggerEvent() {
  1787. $document.trigger( 'wp-window-resized' );
  1788. }
  1789. /**
  1790. * Fires the trigger event again after 200 ms.
  1791. *
  1792. * @since 3.8.0
  1793. *
  1794. * @return {void}
  1795. */
  1796. function fireOnce() {
  1797. window.clearTimeout( timeout );
  1798. timeout = window.setTimeout( triggerEvent, 200 );
  1799. }
  1800. $window.on( 'resize.wp-fire-once', fireOnce );
  1801. }());
  1802. // Make Windows 8 devices play along nicely.
  1803. (function(){
  1804. if ( '-ms-user-select' in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/) ) {
  1805. var msViewportStyle = document.createElement( 'style' );
  1806. msViewportStyle.appendChild(
  1807. document.createTextNode( '@-ms-viewport{width:auto!important}' )
  1808. );
  1809. document.getElementsByTagName( 'head' )[0].appendChild( msViewportStyle );
  1810. }
  1811. })();
  1812. }( jQuery, window ));