Insert Pages - Version 3.6.0

Version Description

  • Add insert_pages_tinymce_state filter to set TinyMCE modal field defaults. Details
  • Add insert_pages_available_templates filter to customize the list of allowed custom templates. Details
  • Update TinyMCE plugin to match changes in current wp-link dialog in core.
  • Fix TinyMCE modal height on mobile.
  • Ensure scripts/styles are loaded before adding TinyMCE plugin.
Download this release

Release Info

Developer figureone
Plugin Icon wp plugin Insert Pages
Version 3.6.0
Comparing to
See all releases

Code changes from version 3.5.10 to 3.6.0

Files changed (4) hide show
  1. css/wpinsertpages.css +133 -84
  2. insert-pages.php +154 -71
  3. js/wpinsertpages.js +140 -108
  4. readme.txt +7 -0
css/wpinsertpages.css CHANGED
@@ -5,19 +5,18 @@
5
  #wp-insertpage-wrap {
6
  display: none;
7
  background-color: #fff;
8
- -webkit-box-shadow: 0 3px 6px rgba(0,0,0,.3);
9
- box-shadow: 0 3px 6px rgba(0,0,0,.3);
10
  width: 500px;
11
- height: 400px;
12
  overflow: hidden;
13
  margin-left: -250px;
14
- margin-top: -250px;
15
  position: fixed;
16
  top: 50%;
17
  left: 50%;
18
  z-index: 100105;
19
- -webkit-transition: height .2s,margin-top .2s;
20
- transition: height .2s,margin-top .2s;
 
21
  }
22
 
23
  #wp-insertpage-backdrop {
@@ -29,7 +28,7 @@
29
  bottom: 0;
30
  min-height: 360px;
31
  background: #000;
32
- opacity: .7;
33
  filter: alpha(opacity=70);
34
  z-index: 100100;
35
  }
@@ -43,23 +42,29 @@
43
  height: 570px;
44
  margin-top: -250px;
45
  }
 
 
 
 
 
 
 
 
 
46
 
47
  #insertpage-modal-title {
48
- background: #fcfcfc;
49
- border-bottom: 1px solid #dfdfdf;
50
  height: 36px;
51
  font-size: 18px;
52
  font-weight: 600;
53
- line-height: 36px;
 
54
  padding: 0 36px 0 16px;
55
- top: 0;
56
- right: 0;
57
- left: 0;
58
  }
59
 
60
  #wp-insertpage-close {
61
- color: #666;
62
- cursor: pointer;
63
  padding: 0;
64
  position: absolute;
65
  top: 0;
@@ -67,28 +72,42 @@
67
  width: 36px;
68
  height: 36px;
69
  text-align: center;
 
 
 
70
  }
71
 
72
  #wp-insertpage-close:before {
73
- font: normal 20px/36px 'dashicons';
74
  vertical-align: top;
75
- speak: none;
76
  -webkit-font-smoothing: antialiased;
77
  -moz-osx-font-smoothing: grayscale;
78
  width: 36px;
79
  height: 36px;
80
- content: '\f158';
81
  }
82
 
83
  #wp-insertpage-close:hover,
84
  #wp-insertpage-close:focus {
85
- color: #2ea2cc;
 
 
 
 
 
 
 
 
 
 
86
  }
87
 
88
- #insertpage-selector {
 
89
  padding: 0 16px;
90
  position: absolute;
91
- top: 36px;
92
  left: 0;
93
  right: 0;
94
  bottom: 44px;
@@ -101,10 +120,14 @@
101
  padding: 0;
102
  }
103
 
 
 
 
 
104
  #insertpage-options-toggle::after {
105
- font: normal 20px/1 'dashicons';
106
  vertical-align: top;
107
- speak: none;
108
  -webkit-font-smoothing: antialiased;
109
  -moz-osx-font-smoothing: grayscale;
110
  content: '\f140';
@@ -114,9 +137,12 @@
114
  content: '\f142';
115
  }
116
 
 
 
 
 
 
117
  #wp-insertpage input[type="text"] {
118
- -webkit-box-sizing: border-box;
119
- -moz-box-sizing: border-box;
120
  box-sizing: border-box;
121
  }
122
 
@@ -128,15 +154,6 @@
128
  margin: 255px 0 3px;
129
  }
130
 
131
- #insertpage-options-toggle {
132
- cursor: pointer;
133
- }
134
-
135
- #insertpage-options-panel .insertpage-format {
136
- margin-top: 5px;
137
- white-space: nowrap;
138
- }
139
-
140
  #wp-insertpage label input[type="text"] {
141
  margin-top: 5px;
142
  width: 77%;
@@ -154,10 +171,11 @@
154
  text-align: right;
155
  padding-right: 5px;
156
  max-width: 24%;
 
 
157
  }
158
 
159
  #wp-insertpage .insertpage-search-field {
160
- float: left;
161
  width: 250px;
162
  max-width: 70%;
163
  }
@@ -168,62 +186,86 @@
168
  overflow: hidden;
169
  }
170
 
171
- #wp-insertpage .insertpage-search-wrapper span {
172
- float: left;
173
- margin-top: 4px;
174
- }
175
-
176
  #wp-insertpage .insertpage-search-wrapper .spinner {
177
- visibility: visible;
178
- display: none;
179
- vertical-align: text-bottom;
180
  }
181
 
182
  #wp-insertpage .query-results {
183
- border: 1px #dfdfdf solid;
184
- margin: 0;
185
  background: #fff;
186
  overflow: auto;
187
  position: absolute;
188
  left: 16px;
189
  right: 16px;
 
190
  top: 38px;
191
  height: 245px;
192
  }
193
 
194
- #wp-insertpage li,
195
- #wp-insertpage .query-notice {
196
  clear: both;
197
  margin-bottom: 0;
198
- border-bottom: 1px solid #f1f1f1;
199
- color: #333;
200
- padding: 4px 6px;
201
  cursor: pointer;
202
  position: relative;
203
  }
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  #wp-insertpage li:hover {
206
- background: #eaf2fa;
207
- color: #151515;
208
  }
209
 
210
  #wp-insertpage li.unselectable {
211
- border-bottom: 1px solid #dfdfdf;
212
  }
213
 
214
  #wp-insertpage li.unselectable:hover {
215
  background: #fff;
216
  cursor: auto;
217
- color: #333;
218
  }
219
 
220
  #wp-insertpage li.selected {
221
- background: #ddd;
222
- color: #333;
223
  }
224
 
225
  #wp-insertpage li.selected .item-title {
226
- font-weight: bold;
227
  }
228
 
229
  #wp-insertpage li:last-child {
@@ -233,13 +275,13 @@
233
  #wp-insertpage .item-title {
234
  display: inline-block;
235
  width: 80%;
236
- width: -webkit-calc(100% - 68px);
237
  width: calc(100% - 68px);
 
238
  }
239
 
240
  #wp-insertpage .item-info {
241
  text-transform: uppercase;
242
- color: #666;
243
  font-size: 11px;
244
  position: absolute;
245
  right: 5px;
@@ -259,17 +301,10 @@
259
  padding: 10px 0;
260
  }
261
 
262
- #wp-insertpage .river-waiting .spinner {
263
- margin: 0 auto;
264
- display: block;
265
- visibility: visible;
266
- float: none;
267
- }
268
-
269
  #wp-insertpage .submitbox {
270
  padding: 8px 16px;
271
- background: #fcfcfc;
272
- border-top: 1px solid #dfdfdf;
273
  position: absolute;
274
  bottom: 0;
275
  left: 0;
@@ -277,17 +312,17 @@
277
  }
278
 
279
  #wp-insertpage-cancel {
280
- line-height: 25px;
 
281
  }
282
 
283
  #wp-insertpage-update {
284
- line-height: 23px;
285
  float: right;
286
  }
287
 
288
  #wp-insertpage-submit {
289
  float: right;
290
- margin-bottom: 0;
291
  }
292
 
293
  @media screen and ( max-width: 782px ) {
@@ -305,7 +340,16 @@
305
  }
306
 
307
  #wp-insertpage-wrap.options-panel-visible {
308
- height: 575px;
 
 
 
 
 
 
 
 
 
309
  }
310
 
311
  #wp-insertpage-wrap .query-results {
@@ -321,7 +365,11 @@
321
  }
322
 
323
  #wp-insertpage-cancel {
324
- line-height: 32px;
 
 
 
 
325
  }
326
  }
327
 
@@ -347,31 +395,33 @@
347
  }
348
 
349
  #wp-insertpage-wrap.options-panel-visible {
350
- height: 575px;
 
 
 
 
 
 
 
 
 
351
  }
352
  }
353
 
354
  @media screen and ( max-height: 520px ) {
355
  #wp-insertpage-wrap {
356
- -webkit-transition: none;
357
  transition: none;
358
- }
359
-
360
- #wp-insertpage-wrap,
361
- #wp-insertpage-wrap.options-panel-visible {
362
  height: auto;
363
  margin-top: 0;
364
  top: 10px;
365
  bottom: 10px;
366
  }
367
 
368
- #insertpage-selector,
369
- .options-panel-visible #insertpage-selector {
370
  overflow: auto;
371
  }
372
 
373
- #search-panel .query-results,
374
- .options-panel-visible #search-panel .query-results {
375
  position: static;
376
  }
377
  }
@@ -386,7 +436,6 @@
386
 
387
  #insertpage-selector {
388
  overflow: auto;
389
- height: -webkit-calc(100% - 92px);
390
  height: calc(100% - 92px);
391
  padding-bottom: 2px;
392
  }
5
  #wp-insertpage-wrap {
6
  display: none;
7
  background-color: #fff;
8
+ box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
 
9
  width: 500px;
 
10
  overflow: hidden;
11
  margin-left: -250px;
12
+ margin-top: -125px;
13
  position: fixed;
14
  top: 50%;
15
  left: 50%;
16
  z-index: 100105;
17
+ transition: height 0.2s, margin-top 0.2s;
18
+
19
+ height: 400px;
20
  }
21
 
22
  #wp-insertpage-backdrop {
28
  bottom: 0;
29
  min-height: 360px;
30
  background: #000;
31
+ opacity: 0.7;
32
  filter: alpha(opacity=70);
33
  z-index: 100100;
34
  }
42
  height: 570px;
43
  margin-top: -250px;
44
  }
45
+ #wp-insertpage-wrap.options-panel-visible.querystring-hidden {
46
+ height: 530px;
47
+ }
48
+ #wp-insertpage-wrap.options-panel-visible.public-hidden {
49
+ height: 530px;
50
+ }
51
+ #wp-insertpage-wrap.options-panel-visible.querystring-hidden.public-hidden {
52
+ height: 510px;
53
+ }
54
 
55
  #insertpage-modal-title {
56
+ background: #fff;
57
+ border-bottom: 1px solid #dcdcde;
58
  height: 36px;
59
  font-size: 18px;
60
  font-weight: 600;
61
+ line-height: 2;
62
+ margin: 0;
63
  padding: 0 36px 0 16px;
 
 
 
64
  }
65
 
66
  #wp-insertpage-close {
67
+ color: #646970;
 
68
  padding: 0;
69
  position: absolute;
70
  top: 0;
72
  width: 36px;
73
  height: 36px;
74
  text-align: center;
75
+ background: none;
76
+ border: none;
77
+ cursor: pointer;
78
  }
79
 
80
  #wp-insertpage-close:before {
81
+ font: normal 20px/36px dashicons;
82
  vertical-align: top;
83
+ speak: never;
84
  -webkit-font-smoothing: antialiased;
85
  -moz-osx-font-smoothing: grayscale;
86
  width: 36px;
87
  height: 36px;
88
+ content: "\f158";
89
  }
90
 
91
  #wp-insertpage-close:hover,
92
  #wp-insertpage-close:focus {
93
+ color: #135e96;
94
+ }
95
+
96
+ #wp-insertpage-close:focus {
97
+ outline: none;
98
+ box-shadow:
99
+ 0 0 0 1px #4f94d4,
100
+ 0 0 2px 1px rgba(79, 148, 212, 0.8);
101
+ /* Only visible in Windows High Contrast mode */
102
+ outline: 2px solid transparent;
103
+ outline-offset: -2px;
104
  }
105
 
106
+ #wp-insertpage-wrap #insertpage-selector {
107
+ -webkit-overflow-scrolling: touch;
108
  padding: 0 16px;
109
  position: absolute;
110
+ top: 37px;
111
  left: 0;
112
  right: 0;
113
  bottom: 44px;
120
  padding: 0;
121
  }
122
 
123
+ #insertpage-options-toggle {
124
+ cursor: pointer;
125
+ }
126
+
127
  #insertpage-options-toggle::after {
128
+ font: normal 20px/1 dashicons;
129
  vertical-align: top;
130
+ speak: never;
131
  -webkit-font-smoothing: antialiased;
132
  -moz-osx-font-smoothing: grayscale;
133
  content: '\f140';
137
  content: '\f142';
138
  }
139
 
140
+ #insertpage-options-panel .insertpage-format {
141
+ margin-top: 5px;
142
+ white-space: nowrap;
143
+ }
144
+
145
  #wp-insertpage input[type="text"] {
 
 
146
  box-sizing: border-box;
147
  }
148
 
154
  margin: 255px 0 3px;
155
  }
156
 
 
 
 
 
 
 
 
 
 
157
  #wp-insertpage label input[type="text"] {
158
  margin-top: 5px;
159
  width: 77%;
171
  text-align: right;
172
  padding-right: 5px;
173
  max-width: 24%;
174
+ vertical-align: middle;
175
+ word-wrap: break-word;
176
  }
177
 
178
  #wp-insertpage .insertpage-search-field {
 
179
  width: 250px;
180
  max-width: 70%;
181
  }
186
  overflow: hidden;
187
  }
188
 
 
 
 
 
 
189
  #wp-insertpage .insertpage-search-wrapper .spinner {
190
+ float: none;
191
+ margin: -3px 0 0 4px;
 
192
  }
193
 
194
  #wp-insertpage .query-results {
195
+ border: 1px #dcdcde solid;
196
+ margin: 0 0 12px;
197
  background: #fff;
198
  overflow: auto;
199
  position: absolute;
200
  left: 16px;
201
  right: 16px;
202
+
203
  top: 38px;
204
  height: 245px;
205
  }
206
 
207
+ #wp-insertpage li {
 
208
  clear: both;
209
  margin-bottom: 0;
210
+ border-bottom: 1px solid #f0f0f1;
211
+ color: #2c3338;
212
+ padding: 4px 6px 4px 10px;
213
  cursor: pointer;
214
  position: relative;
215
  }
216
 
217
+ #wp-insertpage .query-notice {
218
+ padding: 0;
219
+ border-bottom: 1px solid #dcdcde;
220
+ background-color: #fff;
221
+ color: #000;
222
+ }
223
+
224
+ #wp-insertpage .query-notice .query-notice-default,
225
+ #wp-insertpage .query-notice .query-notice-hint {
226
+ display: block;
227
+ padding: 6px;
228
+ border-left: 4px solid #72aee6;
229
+ }
230
+
231
+ #wp-insertpage .unselectable.no-matches-found {
232
+ padding: 0;
233
+ border-bottom: 1px solid #dcdcde;
234
+ background-color: #f6f7f7;
235
+ }
236
+
237
+ #wp-insertpage .no-matches-found .item-title {
238
+ display: block;
239
+ padding: 6px;
240
+ border-left: 4px solid #d63638;
241
+ }
242
+
243
+ #wp-insertpage .query-results em {
244
+ font-style: normal;
245
+ }
246
+
247
  #wp-insertpage li:hover {
248
+ background: #f0f6fc;
249
+ color: #101517;
250
  }
251
 
252
  #wp-insertpage li.unselectable {
253
+ border-bottom: 1px solid #dcdcde;
254
  }
255
 
256
  #wp-insertpage li.unselectable:hover {
257
  background: #fff;
258
  cursor: auto;
259
+ color: #2c3338;
260
  }
261
 
262
  #wp-insertpage li.selected {
263
+ background: #dcdcde;
264
+ color: #2c3338;
265
  }
266
 
267
  #wp-insertpage li.selected .item-title {
268
+ font-weight: 600;
269
  }
270
 
271
  #wp-insertpage li:last-child {
275
  #wp-insertpage .item-title {
276
  display: inline-block;
277
  width: 80%;
 
278
  width: calc(100% - 68px);
279
+ word-wrap: break-word;
280
  }
281
 
282
  #wp-insertpage .item-info {
283
  text-transform: uppercase;
284
+ color: #646970;
285
  font-size: 11px;
286
  position: absolute;
287
  right: 5px;
301
  padding: 10px 0;
302
  }
303
 
 
 
 
 
 
 
 
304
  #wp-insertpage .submitbox {
305
  padding: 8px 16px;
306
+ background: #fff;
307
+ border-top: 1px solid #dcdcde;
308
  position: absolute;
309
  bottom: 0;
310
  left: 0;
312
  }
313
 
314
  #wp-insertpage-cancel {
315
+ line-height: 1.92307692;
316
+ float: left;
317
  }
318
 
319
  #wp-insertpage-update {
320
+ line-height: 1.76923076;
321
  float: right;
322
  }
323
 
324
  #wp-insertpage-submit {
325
  float: right;
 
326
  }
327
 
328
  @media screen and ( max-width: 782px ) {
340
  }
341
 
342
  #wp-insertpage-wrap.options-panel-visible {
343
+ height: 630px;
344
+ }
345
+ #wp-insertpage-wrap.options-panel-visible.querystring-hidden {
346
+ height: 585px;
347
+ }
348
+ #wp-insertpage-wrap.options-panel-visible.public-hidden {
349
+ height: 585px;
350
+ }
351
+ #wp-insertpage-wrap.options-panel-visible.querystring-hidden.public-hidden {
352
+ height: 560px;
353
  }
354
 
355
  #wp-insertpage-wrap .query-results {
365
  }
366
 
367
  #wp-insertpage-cancel {
368
+ line-height: 2.46153846;
369
+ }
370
+
371
+ #wp-link .submitbox .button {
372
+ margin-bottom: 0;
373
  }
374
  }
375
 
395
  }
396
 
397
  #wp-insertpage-wrap.options-panel-visible {
398
+ height: 630px;
399
+ }
400
+ #wp-insertpage-wrap.options-panel-visible.querystring-hidden {
401
+ height: 585px;
402
+ }
403
+ #wp-insertpage-wrap.options-panel-visible.public-hidden {
404
+ height: 585px;
405
+ }
406
+ #wp-insertpage-wrap.options-panel-visible.querystring-hidden.public-hidden {
407
+ height: 560px;
408
  }
409
  }
410
 
411
  @media screen and ( max-height: 520px ) {
412
  #wp-insertpage-wrap {
 
413
  transition: none;
 
 
 
 
414
  height: auto;
415
  margin-top: 0;
416
  top: 10px;
417
  bottom: 10px;
418
  }
419
 
420
+ #insertpage-selector {
 
421
  overflow: auto;
422
  }
423
 
424
+ #search-panel .query-results {
 
425
  position: static;
426
  }
427
  }
436
 
437
  #insertpage-selector {
438
  overflow: auto;
 
439
  height: calc(100% - 92px);
440
  padding-bottom: 2px;
441
  }
insert-pages.php CHANGED
@@ -7,7 +7,7 @@
7
  * Text Domain: insert-pages
8
  * Domain Path: /languages
9
  * License: GPL2
10
- * Version: 3.5.10
11
  *
12
  * @package insert-pages
13
  */
@@ -46,6 +46,20 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
46
  */
47
  protected $inserted_page_ids;
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  /**
51
  * Singleton plugin instance.
@@ -230,7 +244,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
230
  'wpinsertpages',
231
  plugins_url( '/js/wpinsertpages.js', __FILE__ ),
232
  array( 'wpdialogs' ),
233
- '20210225',
234
  false
235
  );
236
  wp_localize_script(
@@ -244,6 +258,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
244
  'l10n_print_after' => 'try{convertEntities(wpInsertPagesL10n);}catch(e){};',
245
  'format' => $options['wpip_format'],
246
  'private' => __( 'Private' ),
 
247
  )
248
  );
249
 
@@ -252,7 +267,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
252
  'wpinsertpagescss',
253
  plugins_url( '/css/wpinsertpages.css', __FILE__ ),
254
  array( 'wp-jquery-ui-dialog' ),
255
- '20191101'
256
  );
257
 
258
  /**
@@ -273,6 +288,8 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
273
  false,
274
  plugin_basename( dirname( __FILE__ ) ) . '/languages'
275
  );
 
 
276
  }
277
 
278
 
@@ -289,13 +306,13 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
289
  // Shortcode attributes.
290
  $attributes = shortcode_atts(
291
  array(
292
- 'page' => '0',
293
- 'display' => 'all',
294
- 'class' => '',
295
- 'id' => '',
296
- 'inline' => false,
297
- 'public' => false,
298
  'querystring' => '',
 
 
299
  ),
300
  $atts,
301
  'insert'
@@ -1042,7 +1059,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
1042
  * @return array TinyMCE buttons with Insert Pages button.
1043
  */
1044
  public function insert_pages_handle_filter_mce_buttons( $buttons ) {
1045
- if ( ! in_array( 'wpInsertPages_button', $buttons, true ) ) {
1046
  array_push( $buttons, 'wpInsertPages_button' );
1047
  }
1048
  return $buttons;
@@ -1055,7 +1072,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
1055
  * @return array TinyMCE plugins with Insert Pages plugin.
1056
  */
1057
  public function insert_pages_handle_filter_mce_external_plugins( $plugins ) {
1058
- if ( ! array_key_exists( 'wpInsertPages', $plugins ) ) {
1059
  $plugins['wpInsertPages'] = plugins_url( '/js/wpinsertpages_plugin.js', __FILE__ );
1060
  }
1061
  return $plugins;
@@ -1145,120 +1162,140 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
1145
  }
1146
 
1147
  /**
1148
- * Modified from /wp-admin/includes/internal-linking.php, function wp_link_dialog()
 
 
1149
  * Dialog for internal linking.
1150
  *
1151
  * @since 3.1.0
1152
  */
1153
  public function insert_pages_wp_tinymce_dialog() {
1154
- // If wp_editor() is being called outside of an admin context,
1155
- // required dependencies for Insert Pages will be missing (e.g.,
1156
- // wp-admin/includes/template.php will not be loaded, admin_head
1157
- // action will not be fired). If that's the case, just skip loading
1158
- // the Insert Pages tinymce button.
1159
- if ( ! function_exists( 'page_template_dropdown' ) ) {
1160
  return;
1161
  }
1162
 
1163
- // Get user's previously selected display and template to restore (if any).
1164
- $tinymce_state = get_user_meta( get_current_user_id(), 'insert_pages_tinymce_state', true );
1165
- if ( empty( $tinymce_state ) ) {
1166
- $tinymce_state = array(
1167
- 'format' => 'title',
1168
- 'template' => 'all',
1169
- );
1170
  }
1171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1172
  // Get ID of post currently being edited.
1173
  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1174
  $post_id = isset( $_REQUEST['post'] ) && intval( $_REQUEST['post'] ) > 0 ? intval( $_REQUEST['post'] ) : '';
1175
 
1176
  // display: none is required here, see #WP27605.
1177
- ?><div id="wp-insertpage-backdrop" style="display: none"></div>
1178
- <div id="wp-insertpage-wrap" class="wp-core-ui<?php
1179
- if ( 1 === intval( get_user_setting( 'wpinsertpage', 0 ) ) ) :
1180
- ?> options-panel-visible<?php
1181
- endif; ?>" style="display: none">
1182
  <form id="wp-insertpage" tabindex="-1">
1183
  <?php wp_nonce_field( 'internal-inserting', '_ajax_inserting_nonce', false ); ?>
1184
  <input type="hidden" id="insertpage-parent-page-id" value="<?php echo esc_attr( $post_id ); ?>" />
1185
- <div id="insertpage-modal-title">
1186
- <?php esc_html_e( 'Insert page', 'insert-pages' ); ?>
1187
- <div id="wp-insertpage-close" tabindex="0"></div>
1188
- </div>
1189
  <div id="insertpage-selector">
1190
  <div id="insertpage-search-panel">
1191
  <div class="insertpage-search-wrapper">
1192
  <label>
1193
- <span class="search-label"><?php esc_html_e( 'Search', 'insert-pages' ); ?></span>
1194
  <input type="search" id="insertpage-search-field" class="insertpage-search-field" autocomplete="off" />
1195
  <span class="spinner"></span>
1196
  </label>
1197
  </div>
1198
- <div id="insertpage-search-results" class="query-results">
1199
  <ul></ul>
1200
  <div class="river-waiting">
1201
  <span class="spinner"></span>
1202
  </div>
1203
  </div>
1204
- <div id="insertpage-most-recent-results" class="query-results">
1205
- <div class="query-notice"><em><?php esc_html_e( 'No search term specified. Showing recent items.', 'insert-pages' ); ?></em></div>
 
 
 
1206
  <ul></ul>
1207
  <div class="river-waiting">
1208
  <span class="spinner"></span>
1209
  </div>
1210
  </div>
1211
  </div>
1212
- <p class="howto" id="insertpage-options-toggle"><?php esc_html_e( 'Options', 'insert-pages' ); ?></p>
1213
  <div id="insertpage-options-panel">
1214
  <div class="insertpage-options-wrapper">
1215
  <label for="insertpage-slug-field">
1216
- <span><?php esc_html_e( 'Slug or ID', 'insert-pages' ); ?></span>
1217
  <input id="insertpage-slug-field" type="text" autocomplete="off" />
1218
  <input id="insertpage-page-id" type="hidden" />
1219
  </label>
1220
  </div>
1221
  <div class="insertpage-format">
1222
  <label for="insertpage-format-select">
1223
- <?php esc_html_e( 'Display', 'insert-pages' ); ?>
1224
- <select name="insertpage-format-select" id="insertpage-format-select">
1225
- <option value='title' <?php selected( $tinymce_state['format'], 'title' ); ?>><?php esc_html_e( 'Title', 'insert-pages' ); ?></option>
1226
- <option value='link' <?php selected( $tinymce_state['format'], 'link' ); ?>><?php esc_html_e( 'Link', 'insert-pages' ); ?></option>
1227
- <option value='excerpt' <?php selected( $tinymce_state['format'], 'excerpt' ); ?>><?php esc_html_e( 'Excerpt with title', 'insert-pages' ); ?></option>
1228
- <option value='excerpt-only' <?php selected( $tinymce_state['format'], 'excerpt-only' ); ?>><?php esc_html_e( 'Excerpt only (no title)', 'insert-pages' ); ?></option>
1229
- <option value='content' <?php selected( $tinymce_state['format'], 'content' ); ?>><?php esc_html_e( 'Content', 'insert-pages' ); ?></option>
1230
- <option value='post-thumbnail' <?php selected( $tinymce_state['format'], 'post-thumbnail' ); ?>><?php esc_html_e( 'Post Thumbnail', 'insert-pages' ); ?></option>
1231
- <option value='all' <?php selected( $tinymce_state['format'], 'all' ); ?>><?php esc_html_e( 'All (includes custom fields)', 'insert-pages' ); ?></option>
1232
- <option value='template' <?php selected( $tinymce_state['format'], 'template' ); ?>><?php esc_html_e( 'Use a custom template', 'insert-pages' ); ?> &raquo;</option>
1233
- </select>
1234
- <select name="insertpage-template-select" id="insertpage-template-select" disabled="true">
1235
- <option value='all' <?php selected( $tinymce_state['template'], 'all' ); ?>><?php esc_html_e( 'Default Template', 'insert-pages' ); ?></option>
1236
- <?php page_template_dropdown( $tinymce_state['template'] ); ?>
1237
- </select>
1238
  </label>
 
 
 
 
 
 
 
 
 
 
1239
  </div>
1240
  <div class="insertpage-extra">
1241
  <label for="insertpage-extra-classes">
1242
- <?php esc_html_e( 'Extra Classes', 'insert-pages' ); ?>:
1243
- <input id="insertpage-extra-classes" type="text" autocomplete="off" />
1244
  </label>
1245
  <label for="insertpage-extra-id">
1246
- <?php esc_html_e( 'ID', 'insert-pages' ); ?>:
1247
- <input id="insertpage-extra-id" type="text" autocomplete="off" />
1248
  </label>
1249
  <label for="insertpage-extra-inline">
1250
- <?php esc_html_e( 'Inline?', 'insert-pages' ); ?>
1251
- <input id="insertpage-extra-inline" type="checkbox" />
1252
  </label>
1253
- <br />
1254
- <label for="insertpage-extra-querystring">
1255
- <?php esc_html_e( 'Querystring', 'insert-pages' ); ?>
1256
- <input id="insertpage-extra-querystring" type="text" autocomplete="off" />
1257
  </label>
1258
- <br />
1259
- <label for="insertpage-extra-public">
1260
- <input id="insertpage-extra-public" type="checkbox" />
1261
- <?php esc_html_e( 'Anonymous users can see this inserted even if its status is private', 'insert-pages' ); ?>
1262
  </label>
1263
  </div>
1264
  </div>
@@ -1268,7 +1305,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
1268
  <input type="submit" value="<?php esc_attr_e( 'Insert Page', 'insert-pages' ); ?>" class="button button-primary" id="wp-insertpage-submit" name="wp-insertpage-submit">
1269
  </div>
1270
  <div id="wp-insertpage-cancel">
1271
- <a class="submitdelete deletion" href="#"><?php esc_html_e( 'Cancel', 'insert-pages' ); ?></a>
1272
  </div>
1273
  </div>
1274
  </form>
@@ -1386,7 +1423,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
1386
  'order' => 'DESC',
1387
  'orderby' => 'post_date',
1388
  'posts_per_page' => 20,
1389
- 'post__not_in' => array( $args['pageID'] ),
1390
  );
1391
 
1392
  $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
@@ -1473,6 +1510,52 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
1473
  );
1474
  }
1475
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1476
  /**
1477
  * Registers the theme widget for inserting a page into an area.
1478
  *
7
  * Text Domain: insert-pages
8
  * Domain Path: /languages
9
  * License: GPL2
10
+ * Version: 3.6.0
11
  *
12
  * @package insert-pages
13
  */
46
  */
47
  protected $inserted_page_ids;
48
 
49
+ /**
50
+ * Flag to only render the TinyMCE plugin dialog once.
51
+ *
52
+ * @var boolean
53
+ */
54
+ private static $link_dialog_printed = false;
55
+
56
+ /**
57
+ * Flag checked when rendering TinyMCE modal to ensure that required scripts
58
+ * and styles were enqueued (normally done in `admin_init` hook).
59
+ *
60
+ * @var boolean
61
+ */
62
+ private static $is_admin_initialized = false;
63
 
64
  /**
65
  * Singleton plugin instance.
244
  'wpinsertpages',
245
  plugins_url( '/js/wpinsertpages.js', __FILE__ ),
246
  array( 'wpdialogs' ),
247
+ '20210308',
248
  false
249
  );
250
  wp_localize_script(
258
  'l10n_print_after' => 'try{convertEntities(wpInsertPagesL10n);}catch(e){};',
259
  'format' => $options['wpip_format'],
260
  'private' => __( 'Private' ),
261
+ 'tinymce_state' => $this->get_tinymce_state(),
262
  )
263
  );
264
 
267
  'wpinsertpagescss',
268
  plugins_url( '/css/wpinsertpages.css', __FILE__ ),
269
  array( 'wp-jquery-ui-dialog' ),
270
+ '20210408'
271
  );
272
 
273
  /**
288
  false,
289
  plugin_basename( dirname( __FILE__ ) ) . '/languages'
290
  );
291
+
292
+ self::$is_admin_initialized = true;
293
  }
294
 
295
 
306
  // Shortcode attributes.
307
  $attributes = shortcode_atts(
308
  array(
309
+ 'page' => '0',
310
+ 'display' => 'all',
311
+ 'class' => '',
312
+ 'id' => '',
 
 
313
  'querystring' => '',
314
+ 'inline' => false,
315
+ 'public' => false,
316
  ),
317
  $atts,
318
  'insert'
1059
  * @return array TinyMCE buttons with Insert Pages button.
1060
  */
1061
  public function insert_pages_handle_filter_mce_buttons( $buttons ) {
1062
+ if ( self::$is_admin_initialized && ! in_array( 'wpInsertPages_button', $buttons, true ) ) {
1063
  array_push( $buttons, 'wpInsertPages_button' );
1064
  }
1065
  return $buttons;
1072
  * @return array TinyMCE plugins with Insert Pages plugin.
1073
  */
1074
  public function insert_pages_handle_filter_mce_external_plugins( $plugins ) {
1075
+ if ( self::$is_admin_initialized && ! array_key_exists( 'wpInsertPages', $plugins ) ) {
1076
  $plugins['wpInsertPages'] = plugins_url( '/js/wpinsertpages_plugin.js', __FILE__ );
1077
  }
1078
  return $plugins;
1162
  }
1163
 
1164
  /**
1165
+ * Modified from /wp-includes/class-wp-editor.php, function
1166
+ * wp_link_dialog().
1167
+ *
1168
  * Dialog for internal linking.
1169
  *
1170
  * @since 3.1.0
1171
  */
1172
  public function insert_pages_wp_tinymce_dialog() {
1173
+ // Don't run if required scripts and styles weren't enqueued.
1174
+ if ( ! self::$is_admin_initialized ) {
 
 
 
 
1175
  return;
1176
  }
1177
 
1178
+ // Run once.
1179
+ if ( self::$link_dialog_printed ) {
1180
+ return;
 
 
 
 
1181
  }
1182
 
1183
+ self::$link_dialog_printed = true;
1184
+
1185
+ $formats = array(
1186
+ 'title' => __( 'Title', 'insert-pages' ),
1187
+ 'link' => __( 'Link', 'insert-pages' ),
1188
+ 'excerpt' => __( 'Excerpt with title', 'insert-pages' ),
1189
+ 'excerpt-only' => __( 'Excerpt only (no title)', 'insert-pages' ),
1190
+ 'content' => __( 'Content', 'insert-pages' ),
1191
+ 'post-thumbnail' => __( 'Post Thumbnail', 'insert-pages' ),
1192
+ 'all' => __( 'All (includes custom fields)', 'insert-pages' ),
1193
+ 'template' => __( 'Use a custom template', 'insert-pages' ) . ' &raquo;',
1194
+ );
1195
+
1196
+ $templates = array(
1197
+ 'all' => __( 'Default Template', 'insert-pages' ),
1198
+ );
1199
+ foreach ( wp_get_theme()->get_page_templates() as $file => $name ) {
1200
+ $templates[ $file ] = $name;
1201
+ }
1202
+
1203
+ /**
1204
+ * Filter the available templates shown in the template dropdown.
1205
+ *
1206
+ * @param array $templates Array of template names keyed by their filename.
1207
+ */
1208
+ $templates = apply_filters( 'insert_pages_available_templates', $templates );
1209
+
1210
+ // Get default values for the TinyMCE dialog fields. Note: can be
1211
+ // overridden by the `insert_pages_tinymce_state` filter.
1212
+ $tinymce_state = $this->get_tinymce_state();
1213
+
1214
  // Get ID of post currently being edited.
1215
  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1216
  $post_id = isset( $_REQUEST['post'] ) && intval( $_REQUEST['post'] ) > 0 ? intval( $_REQUEST['post'] ) : '';
1217
 
1218
  // display: none is required here, see #WP27605.
1219
+ ?>
1220
+ <div id="wp-insertpage-backdrop" style="display: none"></div>
1221
+ <div id="wp-insertpage-wrap" class="wp-core-ui<?php echo 1 === intval( get_user_setting( 'wpinsertpage', 0 ) ) ? ' options-panel-visible' : ''; ?><?php echo empty( $tinymce_state['hide_querystring'] ) ? '' : ' querystring-hidden'; ?><?php echo empty( $tinymce_state['hide_public'] ) ? '' : ' public-hidden'; ?>" style="display: none;" role="dialog" aria-labelledby="insertpage-modal-title">
 
 
1222
  <form id="wp-insertpage" tabindex="-1">
1223
  <?php wp_nonce_field( 'internal-inserting', '_ajax_inserting_nonce', false ); ?>
1224
  <input type="hidden" id="insertpage-parent-page-id" value="<?php echo esc_attr( $post_id ); ?>" />
1225
+ <h1 id="insertpage-modal-title"><?php _e( 'Insert page', 'insert-pages' ); ?></h1>
1226
+ <button type="button" id="wp-insertpage-close"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
 
 
1227
  <div id="insertpage-selector">
1228
  <div id="insertpage-search-panel">
1229
  <div class="insertpage-search-wrapper">
1230
  <label>
1231
+ <span class="search-label"><?php _e( 'Search', 'insert-pages' ); ?></span>
1232
  <input type="search" id="insertpage-search-field" class="insertpage-search-field" autocomplete="off" />
1233
  <span class="spinner"></span>
1234
  </label>
1235
  </div>
1236
+ <div id="insertpage-search-results" class="query-results" tabindex="0">
1237
  <ul></ul>
1238
  <div class="river-waiting">
1239
  <span class="spinner"></span>
1240
  </div>
1241
  </div>
1242
+ <div id="insertpage-most-recent-results" class="query-results" tabindex="0">
1243
+ <div class="query-notice" id="insertpage-query-notice-message">
1244
+ <em class="query-notice-default"><?php _e( 'No search term specified. Showing recent items.', 'insert-pages' ); ?></em>
1245
+ <em class="query-notice-hint screen-reader-text"><?php _e( 'Search or use up and down arrow keys to select an item.' ); ?></em>
1246
+ </div>
1247
  <ul></ul>
1248
  <div class="river-waiting">
1249
  <span class="spinner"></span>
1250
  </div>
1251
  </div>
1252
  </div>
1253
+ <p class="howto" id="insertpage-options-toggle"><?php _e( 'Options', 'insert-pages' ); ?></p>
1254
  <div id="insertpage-options-panel">
1255
  <div class="insertpage-options-wrapper">
1256
  <label for="insertpage-slug-field">
1257
+ <span><?php _e( 'Slug or ID', 'insert-pages' ); ?></span>
1258
  <input id="insertpage-slug-field" type="text" autocomplete="off" />
1259
  <input id="insertpage-page-id" type="hidden" />
1260
  </label>
1261
  </div>
1262
  <div class="insertpage-format">
1263
  <label for="insertpage-format-select">
1264
+ <?php _e( 'Display', 'insert-pages' ); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1265
  </label>
1266
+ <select name="insertpage-format-select" id="insertpage-format-select">
1267
+ <?php foreach ( $formats as $format => $label ) : ?>
1268
+ <option value='<?php echo esc_attr( $format ); ?>' <?php selected( $tinymce_state['format'], $format ); ?>><?php echo esc_html( $label ); ?></option>
1269
+ <?php endforeach; ?>
1270
+ </select>
1271
+ <select name="insertpage-template-select" id="insertpage-template-select" disabled="true">
1272
+ <?php foreach ( $templates as $template => $label ) : ?>
1273
+ <option value='<?php echo esc_attr( $template ); ?>' <?php selected( $tinymce_state['template'], $template ); ?>><?php echo esc_html( $label ); ?></option>
1274
+ <?php endforeach; ?>
1275
+ </select>
1276
  </div>
1277
  <div class="insertpage-extra">
1278
  <label for="insertpage-extra-classes">
1279
+ <?php _e( 'Extra Classes', 'insert-pages' ); ?>
1280
+ <input id="insertpage-extra-classes" type="text" autocomplete="off" value="<?php echo empty( $tinymce_state['class'] ) ? '' : esc_attr( $tinymce_state['class'] ); ?>" />
1281
  </label>
1282
  <label for="insertpage-extra-id">
1283
+ <?php _e( 'ID', 'insert-pages' ); ?>
1284
+ <input id="insertpage-extra-id" type="text" autocomplete="off" value="<?php echo empty( $tinymce_state['id'] ) ? '' : esc_attr( $tinymce_state['id'] ); ?>" />
1285
  </label>
1286
  <label for="insertpage-extra-inline">
1287
+ <?php _e( 'Inline?', 'insert-pages' ); ?>
1288
+ <input id="insertpage-extra-inline" type="checkbox" <?php checked( $tinymce_state['inline'] ); ?> />
1289
  </label>
1290
+ <br class="<?php echo empty( $tinymce_state['hide_querystring'] ) ? '' : 'hidden'; ?>" />
1291
+ <label for="insertpage-extra-querystring" class="<?php echo empty( $tinymce_state['hide_querystring'] ) ? '' : 'hidden'; ?>">
1292
+ <?php _e( 'Querystring', 'insert-pages' ); ?>
1293
+ <input id="insertpage-extra-querystring" type="text" autocomplete="off" value="<?php echo empty( $tinymce_state['querystring'] ) ? '' : esc_attr( $tinymce_state['querystring'] ); ?>" />
1294
  </label>
1295
+ <br class="<?php echo empty( $tinymce_state['hide_public'] ) ? '' : 'hidden'; ?>" />
1296
+ <label for="insertpage-extra-public" class="<?php echo empty( $tinymce_state['hide_public'] ) ? '' : 'hidden'; ?>">
1297
+ <input id="insertpage-extra-public" type="checkbox" <?php checked( $tinymce_state['public'] ); ?> />
1298
+ <?php _e( 'Anonymous users can see this inserted even if its status is private', 'insert-pages' ); ?>
1299
  </label>
1300
  </div>
1301
  </div>
1305
  <input type="submit" value="<?php esc_attr_e( 'Insert Page', 'insert-pages' ); ?>" class="button button-primary" id="wp-insertpage-submit" name="wp-insertpage-submit">
1306
  </div>
1307
  <div id="wp-insertpage-cancel">
1308
+ <a class="submitdelete deletion" href="#"><?php _e( 'Cancel', 'insert-pages' ); ?></a>
1309
  </div>
1310
  </div>
1311
  </form>
1423
  'order' => 'DESC',
1424
  'orderby' => 'post_date',
1425
  'posts_per_page' => 20,
1426
+ // 'post__not_in' => array( $args['pageID'] ), // Remove?
1427
  );
1428
 
1429
  $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
1510
  );
1511
  }
1512
 
1513
+ /**
1514
+ * Fetch the default values for the TinyMCE modal fields.
1515
+ */
1516
+ private function get_tinymce_state() {
1517
+ // Get user's previously selected display and template to restore (if any).
1518
+ $tinymce_state = get_user_meta( get_current_user_id(), 'insert_pages_tinymce_state', true );
1519
+ if ( empty( $tinymce_state ) ) {
1520
+ $tinymce_state = array();
1521
+ }
1522
+
1523
+ // Merge user's format and template defaults with global defaults.
1524
+ $tinymce_state = wp_parse_args(
1525
+ $tinymce_state,
1526
+ array(
1527
+ 'format' => 'title',
1528
+ 'template' => 'all',
1529
+ 'class' => '',
1530
+ 'id' => '',
1531
+ 'querystring' => '',
1532
+ 'inline' => false,
1533
+ 'public' => false,
1534
+ 'hide_querystring' => false,
1535
+ 'hide_public' => false,
1536
+ )
1537
+ );
1538
+
1539
+ /**
1540
+ * Filter the TinyMCE dialog field defaults.
1541
+ *
1542
+ * @param array $tinymce_state Array of field defaults for the TinyMCE modal.
1543
+ * 'format' (string) Display format. Default 'title'.
1544
+ * 'template' (string) Custom template. Default 'all'.
1545
+ * 'class' (string) HTML wrapper class. Default ''.
1546
+ * 'id' (string) HTML wrapper id. Default ''.
1547
+ * 'querystring' (string) Querystring params. Default ''.
1548
+ * 'inline' (bool) Use <span> element for wrapper. Default false.
1549
+ * 'public' (bool) Whether anonymous users can see this page if
1550
+ * its status is Private. Default false.
1551
+ * 'hide_querystring' (bool) Skip rendering querystring field. Default false.
1552
+ * 'hide_public' (bool) Skip rendering public field. Default false.
1553
+ */
1554
+ $tinymce_state = apply_filters( 'insert_pages_tinymce_state', $tinymce_state );
1555
+
1556
+ return $tinymce_state;
1557
+ }
1558
+
1559
  /**
1560
  * Registers the theme widget for inserting a page into an area.
1561
  *
js/wpinsertpages.js CHANGED
@@ -1,26 +1,27 @@
1
  /**
2
- * Modified from WordPress Advanced Link dialog, wp-includes/js/wplink.js
 
 
3
  */
4
 
5
- /* global ajaxurl, tinymce, wpLinkL10n, setUserSetting, wpActiveEditor */
6
 
7
- var wpInsertPages;
8
-
9
- (function ( $ ) {
10
  var editor, searchTimer, RiverInsertPages, QueryInsertPages, correctedURL,
11
  inputs = {},
12
  rivers = {},
13
  isTouch = ( 'ontouchend' in document );
14
 
15
- wpInsertPages = {
16
  timeToTriggerRiverInsertPages: 150,
17
  minRiverInsertPagesAJAXDuration: 200,
18
  riverBottomThreshold: 5,
19
  keySensitivity: 100,
20
  lastSearch: '',
21
  textarea: '',
 
22
 
23
- init : function() {
24
  inputs.wrap = $( '#wp-insertpage-wrap' );
25
  inputs.dialog = $( '#wp-insertpage' );
26
  inputs.backdrop = $( '#wp-insertpage-backdrop' );
@@ -31,26 +32,31 @@ var wpInsertPages;
31
  inputs.slug = $( '#insertpage-slug-field' );
32
  inputs.pageID = $( '#insertpage-page-id' );
33
  inputs.parentPageID = $( '#insertpage-parent-page-id' );
 
 
 
 
34
 
35
- // Format field (title, link, content, all, choose a custom template ->).
36
  inputs.format = $( '#insertpage-format-select' );
37
 
38
- // Extra fields (wrapper classes, inline checkbox, "visible to all" checkbox).
39
  inputs.extraClasses = $( '#insertpage-extra-classes' );
40
  inputs.extraID = $( '#insertpage-extra-id' );
41
  inputs.extraInline = $( '#insertpage-extra-inline' );
42
  inputs.extraPublic = $( '#insertpage-extra-public' );
43
  inputs.extraQuerystring = $( '#insertpage-extra-querystring' );
44
 
45
- // Custom template select field.
46
- inputs.template = $( '#insertpage-template-select' );
47
- inputs.search = $( '#insertpage-search-field' );
48
-
49
  // Build rivers.
50
  rivers.search = new RiverInsertPages( $( '#insertpage-search-results' ) );
51
  rivers.recent = new RiverInsertPages( $( '#insertpage-most-recent-results' ) );
52
  rivers.elements = inputs.dialog.find( '.query-results' );
53
 
 
 
 
 
 
54
  // Bind event handlers.
55
  inputs.dialog.on( 'keydown', wpInsertPages.keydown );
56
  inputs.dialog.on( 'keyup', wpInsertPages.keyup );
@@ -58,15 +64,35 @@ var wpInsertPages;
58
  event.preventDefault();
59
  wpInsertPages.update();
60
  });
61
- inputs.close.add( inputs.backdrop ).add( '#wp-insertpage-cancel a' ).on( 'click', function( event ) {
 
62
  event.preventDefault();
63
  wpInsertPages.close();
64
  });
65
 
 
66
  $( '#insertpage-options-toggle' ).on( 'click', wpInsertPages.toggleInternalLinking );
67
 
68
  rivers.elements.on('river-select', wpInsertPages.updateFields );
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  inputs.format.on( 'change', function() {
71
  if ( inputs.format.val() == 'template' ) {
72
  inputs.template.removeAttr( 'disabled' );
@@ -74,8 +100,7 @@ var wpInsertPages;
74
  } else {
75
  inputs.template.attr( 'disabled', 'disabled' );
76
  }
77
-
78
- // Save last selected template for this user.
79
  $.post( ajaxurl, {
80
  action : 'insertpage_save_presets',
81
  format : inputs.format.val(),
@@ -83,8 +108,8 @@ var wpInsertPages;
83
  }, function (r) {}, 'json' );
84
  });
85
 
 
86
  inputs.template.on( 'change', function() {
87
- // Save last selected template for this user.
88
  $.post( ajaxurl, {
89
  action : 'insertpage_save_presets',
90
  template : inputs.template.val(),
@@ -98,15 +123,6 @@ var wpInsertPages;
98
  inputs.search.data( 'type', 'text' );
99
  });
100
 
101
- inputs.search.on( 'keyup', function() {
102
- var self = this;
103
-
104
- window.clearTimeout( searchTimer );
105
- searchTimer = window.setTimeout( function() {
106
- wpInsertPages.searchInternalLinks.call( self );
107
- }, 500 );
108
- });
109
-
110
  /* for this to work, inputs.slug needs to populate inputs.pageID with id when it changes
111
  inputs.pageID.change(function() {
112
  if (inputs.pageID.val() == inputs.parentPageID.val()) { // trying to embed a page in itself
@@ -119,7 +135,12 @@ var wpInsertPages;
119
  },
120
 
121
  open: function( editorId ) {
122
- var ed, node, bookmark, cursorPosition = -1;
 
 
 
 
 
123
 
124
  wpInsertPages.range = null;
125
 
@@ -133,26 +154,25 @@ var wpInsertPages;
133
 
134
  this.textarea = $( '#' + window.wpActiveEditor ).get( 0 );
135
 
136
- if ( typeof tinymce !== 'undefined' ) {
137
- ed = tinymce.get( wpActiveEditor );
 
 
 
 
138
 
139
  if ( ed && ! ed.isHidden() ) {
140
  editor = ed;
141
 
142
- // Get cursor state (used later to determine if we're in an existing shortcode)
143
  node = editor.selection.getNode();
144
  bookmark = editor.selection.getBookmark( 0 );
145
  unencodedText = node.innerHTML.replace( /&amp;/g, '&' );
146
  cursorPosition = unencodedText.indexOf( '<span data-mce-type="bookmark"' );
147
  editor.selection.moveToBookmark( bookmark );
148
-
149
  } else {
150
  editor = null;
151
  }
152
-
153
- if ( editor && tinymce.isIE ) {
154
- editor.windowManager.bookmark = editor.selection.getBookmark();
155
- }
156
  }
157
 
158
  if ( ! wpInsertPages.isMCE() && document.selection ) {
@@ -175,15 +195,26 @@ var wpInsertPages;
175
  rivers.search.refresh();
176
  rivers.recent.refresh();
177
 
178
- if ( wpInsertPages.isMCE() )
179
  wpInsertPages.mceRefresh( cursorPosition );
180
- else
181
  wpInsertPages.setDefaultValues();
 
182
 
183
- // Focus the Slug field and highlight its contents.
184
- // If this is moved above the selection changes,
185
- // IE will show a flashing cursor over the dialog.
186
- inputs.slug.focus()[0].select();
 
 
 
 
 
 
 
 
 
 
187
 
188
  // Load the most recent results if this is the first time opening the panel.
189
  if ( ! rivers.recent.ul.children().length )
@@ -245,7 +276,7 @@ var wpInsertPages;
245
 
246
  inputs.slug.val( matches[1] );
247
  inputs.search.val( matches[1] );
248
- inputs.search.keyup();
249
  }
250
 
251
  // Update display dropdown to match the selected shortcode.
@@ -259,7 +290,7 @@ var wpInsertPages;
259
  inputs.format.val( 'template' );
260
  inputs.template.val( matches[1] );
261
  }
262
- inputs.format.change();
263
  }
264
 
265
  // Update extra classes.
@@ -268,7 +299,7 @@ var wpInsertPages;
268
  if ( matches && matches.length > 1 ) {
269
  inputs.extraClasses.val( matches[1] );
270
  } else {
271
- inputs.extraClasses.val( '' );
272
  }
273
 
274
  // Update extra ID.
@@ -277,7 +308,7 @@ var wpInsertPages;
277
  if ( matches && matches.length > 1 ) {
278
  inputs.extraID.val( matches[1] );
279
  } else {
280
- inputs.extraID.val( '' );
281
  }
282
 
283
  // Update extra inline (i.e., use span instead of div for wrapper).
@@ -286,7 +317,7 @@ var wpInsertPages;
286
  if ( matches && matches.length > 0 ) {
287
  inputs.extraInline.attr( 'checked', true );
288
  } else {
289
- inputs.extraInline.attr( 'checked', false );
290
  }
291
 
292
  // If this is a private page, reveal the checkbox "Visible to everyone?"
@@ -295,7 +326,7 @@ var wpInsertPages;
295
  if ( matches && matches.length > 0 ) {
296
  inputs.extraPublic.attr( 'checked', true );
297
  } else {
298
- inputs.extraPublic.attr( 'checked', false );
299
  }
300
 
301
  // Update extra querystring.
@@ -306,7 +337,7 @@ var wpInsertPages;
306
  // closing bracket will terminate the shortcode).
307
  inputs.extraQuerystring.val( matches[1].replace( /&amp;/g, '&' ) );
308
  } else {
309
- inputs.extraQuerystring.val( '' );
310
  }
311
 
312
  // Update save prompt.
@@ -318,30 +349,6 @@ var wpInsertPages;
318
  }
319
  },
320
 
321
- setDefaultValues : function() {
322
- // Set URL and description to defaults.
323
- // Leave the new tab setting as-is.
324
- // Leave the display and template inputs as-is (use values in user meta).
325
- inputs.slug.val('');
326
- inputs.pageID.val('');
327
- inputs.extraClasses.val('');
328
- inputs.extraID.val( '' );
329
- inputs.extraInline.attr( 'checked', false );
330
- inputs.search.val( '' );
331
- inputs.search.data( 'type', 'text' );
332
- inputs.search.keyup();
333
-
334
- // inputs.format.val('title');
335
- // inputs.format.change();
336
- // inputs.template.val('all');
337
- if ( inputs.format.val() == 'template' ) {
338
- inputs.template.removeAttr( 'disabled' );
339
- inputs.template.focus();
340
- } else {
341
- inputs.template.attr( 'disabled', 'disabled' );
342
- }
343
- },
344
-
345
  close: function() {
346
  if ( ! wpInsertPages.isMCE() ) {
347
  wpInsertPages.textarea.focus();
@@ -371,7 +378,7 @@ var wpInsertPages;
371
  };
372
  },
373
 
374
- update : function() {
375
  var link,
376
  attrs = wpInsertPages.getAttrs(),
377
  b;
@@ -409,7 +416,7 @@ var wpInsertPages;
409
  editor.execCommand("mceEndUndoLevel");
410
  },
411
 
412
- updateFields : function( e, li, originalEvent ) {
413
  if ( wpInsertPagesL10n.format === 'post_id' ) {
414
  inputs.slug.val( li.children('.item-id').val() );
415
  } else {
@@ -420,7 +427,32 @@ var wpInsertPages;
420
  inputs.slug.focus();
421
  },
422
 
423
- searchInternalLinks : function() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
  var t = $(this), waiting,
425
  search = t.val(),
426
  type = t.data( 'type' );
@@ -434,11 +466,11 @@ var wpInsertPages;
434
  return;
435
 
436
  wpInsertPages.lastSearch = search;
437
- waiting = t.parent().find( '.spinner' ).show();
438
 
439
  rivers.search.change( search, type );
440
  rivers.search.ajax( function() {
441
- waiting.hide();
442
  });
443
  } else {
444
  rivers.search.hide();
@@ -446,16 +478,16 @@ var wpInsertPages;
446
  }
447
  },
448
 
449
- next : function() {
450
  rivers.search.next();
451
  rivers.recent.next();
452
  },
453
- prev : function() {
454
  rivers.search.prev();
455
  rivers.recent.prev();
456
  },
457
 
458
- keydown : function( event ) {
459
  var fn, key = $.ui.keyCode;
460
 
461
  switch( event.which ) {
@@ -472,12 +504,14 @@ var wpInsertPages;
472
  }
473
  event.preventDefault();
474
  },
 
475
  keyup: function( event ) {
476
  var key = $.ui.keyCode;
477
 
478
  switch( event.which ) {
479
  case key.ESCAPE:
480
- wpInsertPages.cancel();
 
481
  break;
482
  case key.UP:
483
  case key.DOWN:
@@ -489,7 +523,7 @@ var wpInsertPages;
489
  event.preventDefault();
490
  },
491
 
492
- delayedCallback : function( func, delay ) {
493
  var timeoutTriggered, funcTriggered, funcArgs, funcContext;
494
 
495
  if ( ! delay )
@@ -512,7 +546,7 @@ var wpInsertPages;
512
  };
513
  },
514
 
515
- toggleInternalLinking : function( event ) {
516
  var visible = inputs.wrap.hasClass( 'options-panel-visible');
517
 
518
  inputs.wrap.toggleClass( 'options-panel-visible', ! visible );
@@ -543,7 +577,7 @@ var wpInsertPages;
543
  $.extend( RiverInsertPages.prototype, {
544
  refresh: function() {
545
  this.deselect();
546
- this.visible = this.element.is(':visible');
547
  },
548
  show: function() {
549
  if ( ! this.visible ) {
@@ -571,18 +605,18 @@ var wpInsertPages;
571
  liTop = li.position().top;
572
  elTop = this.element.scrollTop();
573
 
574
- if ( liTop < 0 ) { // Make first visible element
575
  this.element.scrollTop( elTop + liTop );
576
- } else if ( liTop + liHeight > elHeight ) { // Make last visible element
577
  this.element.scrollTop( elTop + liTop - elHeight + liHeight );
578
  }
579
 
580
  // Trigger the river-select event
581
- this.element.trigger('river-select', [ li, event, this ]);
582
  },
583
  deselect: function() {
584
  if ( this.selected )
585
- this.selected.removeClass('selected');
586
  this.selected = false;
587
  },
588
  prev: function() {
@@ -591,7 +625,7 @@ var wpInsertPages;
591
 
592
  var to;
593
  if ( this.selected ) {
594
- to = this.selected.prev('li');
595
  if ( to.length )
596
  this.select( to );
597
  }
@@ -600,7 +634,7 @@ var wpInsertPages;
600
  if ( ! this.visible )
601
  return;
602
 
603
- var to = this.selected ? this.selected.next('li') : $('li:not(.unselectable):first', this.element);
604
  if ( to.length )
605
  this.select( to );
606
  },
@@ -621,17 +655,15 @@ var wpInsertPages;
621
 
622
  this._search = search;
623
  this.query = new QueryInsertPages( search, type );
624
- this.element.scrollTop(0);
625
  },
626
  process: function( results, params ) {
627
  var list = '', alt = true, classes = '',
628
  firstPage = params.page == 1;
629
 
630
- if ( !results ) {
631
  if ( firstPage ) {
632
- list += '<li class="unselectable"><span class="item-title"><em>'
633
- + wpInsertPagesL10n.noMatchesFound
634
- + '</em></span></li>';
635
  }
636
  } else {
637
  $.each( results, function() {
@@ -657,21 +689,21 @@ var wpInsertPages;
657
  el = this.element,
658
  bottom = el.scrollTop() + el.height();
659
 
660
- if ( ! this.query.ready() || bottom < this.ul.height() - wpInsertPages.riverBottomThreshold )
661
  return;
662
 
663
- setTimeout(function() {
664
  var newTop = el.scrollTop(),
665
  newBottom = newTop + el.height();
666
 
667
- if ( ! self.query.ready() || newBottom < self.ul.height() - wpInsertPages.riverBottomThreshold )
668
  return;
669
 
670
- self.waiting.show();
671
  el.scrollTop( newTop + self.waiting.outerHeight() );
672
 
673
  self.ajax( function() {
674
- self.waiting.hide();
675
  });
676
  }, wpInsertPages.timeToTriggerRiverInsertPages );
677
  }
@@ -687,7 +719,7 @@ var wpInsertPages;
687
 
688
  $.extend( QueryInsertPages.prototype, {
689
  ready: function() {
690
- return !( this.querying || this.allLoaded );
691
  },
692
  ajax: function( callback ) {
693
  var self = this,
@@ -701,18 +733,18 @@ var wpInsertPages;
701
  if ( this.search )
702
  query.search = this.search;
703
 
704
- query.pageID = inputs.pageID.val();
705
-
706
  this.querying = true;
707
- $.post( ajaxurl, query, function(r) {
 
 
 
708
  self.page++;
709
  self.querying = false;
710
- self.allLoaded = !r;
711
  callback( r, query );
712
- }, "json" );
713
  }
714
  });
715
 
716
  $( document ).ready( wpInsertPages.init );
717
-
718
- })( jQuery );
1
  /**
2
+ * Modified from WordPress Advanced Link dialog.
3
+ *
4
+ * @output wp-includes/js/wplink.js
5
  */
6
 
7
+ /* global wpInsertPages */
8
 
9
+ (function ( $, wpInsertPagesL10n, wp ) {
 
 
10
  var editor, searchTimer, RiverInsertPages, QueryInsertPages, correctedURL,
11
  inputs = {},
12
  rivers = {},
13
  isTouch = ( 'ontouchend' in document );
14
 
15
+ window.wpInsertPages = {
16
  timeToTriggerRiverInsertPages: 150,
17
  minRiverInsertPagesAJAXDuration: 200,
18
  riverBottomThreshold: 5,
19
  keySensitivity: 100,
20
  lastSearch: '',
21
  textarea: '',
22
+ modalOpen: false,
23
 
24
+ init: function() {
25
  inputs.wrap = $( '#wp-insertpage-wrap' );
26
  inputs.dialog = $( '#wp-insertpage' );
27
  inputs.backdrop = $( '#wp-insertpage-backdrop' );
32
  inputs.slug = $( '#insertpage-slug-field' );
33
  inputs.pageID = $( '#insertpage-page-id' );
34
  inputs.parentPageID = $( '#insertpage-parent-page-id' );
35
+ inputs.search = $( '#insertpage-search-field' );
36
+
37
+ // Custom template select field.
38
+ inputs.template = $( '#insertpage-template-select' );
39
 
40
+ // Custom format field (title, link, content, all, choose a custom template ->).
41
  inputs.format = $( '#insertpage-format-select' );
42
 
43
+ // Custom extra fields (wrapper classes, inline checkbox, "visible to all" checkbox).
44
  inputs.extraClasses = $( '#insertpage-extra-classes' );
45
  inputs.extraID = $( '#insertpage-extra-id' );
46
  inputs.extraInline = $( '#insertpage-extra-inline' );
47
  inputs.extraPublic = $( '#insertpage-extra-public' );
48
  inputs.extraQuerystring = $( '#insertpage-extra-querystring' );
49
 
 
 
 
 
50
  // Build rivers.
51
  rivers.search = new RiverInsertPages( $( '#insertpage-search-results' ) );
52
  rivers.recent = new RiverInsertPages( $( '#insertpage-most-recent-results' ) );
53
  rivers.elements = inputs.dialog.find( '.query-results' );
54
 
55
+ // Get search notice text.
56
+ inputs.queryNotice = $( '#insertpage-query-notice-message' );
57
+ inputs.queryNoticeTextDefault = inputs.queryNotice.find( '.query-notice-default' );
58
+ inputs.queryNoticeTextHint = inputs.queryNotice.find( '.query-notice-hint' );
59
+
60
  // Bind event handlers.
61
  inputs.dialog.on( 'keydown', wpInsertPages.keydown );
62
  inputs.dialog.on( 'keyup', wpInsertPages.keyup );
64
  event.preventDefault();
65
  wpInsertPages.update();
66
  });
67
+
68
+ inputs.close.add( inputs.backdrop ).add( '#wp-insertpage-cancel button' ).on( 'click', function( event ) {
69
  event.preventDefault();
70
  wpInsertPages.close();
71
  });
72
 
73
+ // Custom hide/show options toggle.
74
  $( '#insertpage-options-toggle' ).on( 'click', wpInsertPages.toggleInternalLinking );
75
 
76
  rivers.elements.on('river-select', wpInsertPages.updateFields );
77
 
78
+ // Display 'hint' message when search field or 'query-results' box are focused.
79
+ inputs.search.on( 'focus.wplink', function() {
80
+ inputs.queryNoticeTextDefault.hide();
81
+ inputs.queryNoticeTextHint.removeClass( 'screen-reader-text' ).show();
82
+ } ).on( 'blur.wplink', function() {
83
+ inputs.queryNoticeTextDefault.show();
84
+ inputs.queryNoticeTextHint.addClass( 'screen-reader-text' ).hide();
85
+ } );
86
+
87
+ inputs.search.on( 'keyup input', function() {
88
+ var self = this; // Custom reference to field.
89
+ window.clearTimeout( searchTimer );
90
+ searchTimer = window.setTimeout( function() {
91
+ wpInsertPages.searchInternalLinks.call( self );
92
+ }, 500 );
93
+ });
94
+
95
+ // Custom: enable template dropdown if "Custom Template" is chosen as the display.
96
  inputs.format.on( 'change', function() {
97
  if ( inputs.format.val() == 'template' ) {
98
  inputs.template.removeAttr( 'disabled' );
100
  } else {
101
  inputs.template.attr( 'disabled', 'disabled' );
102
  }
103
+ // Save last selected display for this user.
 
104
  $.post( ajaxurl, {
105
  action : 'insertpage_save_presets',
106
  format : inputs.format.val(),
108
  }, function (r) {}, 'json' );
109
  });
110
 
111
+ // Custom: save last selected template for this user.
112
  inputs.template.on( 'change', function() {
 
113
  $.post( ajaxurl, {
114
  action : 'insertpage_save_presets',
115
  template : inputs.template.val(),
123
  inputs.search.data( 'type', 'text' );
124
  });
125
 
 
 
 
 
 
 
 
 
 
126
  /* for this to work, inputs.slug needs to populate inputs.pageID with id when it changes
127
  inputs.pageID.change(function() {
128
  if (inputs.pageID.val() == inputs.parentPageID.val()) { // trying to embed a page in itself
135
  },
136
 
137
  open: function( editorId ) {
138
+ var ed,
139
+ node, bookmark, cursorPosition = -1,
140
+ $body = $( document.body );
141
+
142
+ $body.addClass( 'modal-open' );
143
+ wpInsertPages.modalOpen = true;
144
 
145
  wpInsertPages.range = null;
146
 
154
 
155
  this.textarea = $( '#' + window.wpActiveEditor ).get( 0 );
156
 
157
+ if ( typeof window.tinymce !== 'undefined' ) {
158
+ // Make sure the link wrapper is the last element in the body,
159
+ // or the inline editor toolbar may show above the backdrop.
160
+ $body.append( inputs.backdrop, inputs.wrap );
161
+
162
+ ed = window.tinymce.get( window.wpActiveEditor );
163
 
164
  if ( ed && ! ed.isHidden() ) {
165
  editor = ed;
166
 
167
+ // Custom: get cursor state (used later to determine if we're in an existing shortcode)
168
  node = editor.selection.getNode();
169
  bookmark = editor.selection.getBookmark( 0 );
170
  unencodedText = node.innerHTML.replace( /&amp;/g, '&' );
171
  cursorPosition = unencodedText.indexOf( '<span data-mce-type="bookmark"' );
172
  editor.selection.moveToBookmark( bookmark );
 
173
  } else {
174
  editor = null;
175
  }
 
 
 
 
176
  }
177
 
178
  if ( ! wpInsertPages.isMCE() && document.selection ) {
195
  rivers.search.refresh();
196
  rivers.recent.refresh();
197
 
198
+ if ( wpInsertPages.isMCE() ) {
199
  wpInsertPages.mceRefresh( cursorPosition );
200
+ } else {
201
  wpInsertPages.setDefaultValues();
202
+ }
203
 
204
+ if ( isTouch ) {
205
+ // Close the onscreen keyboard.
206
+ inputs.url.trigger( 'focus' ).trigger( 'blur' );
207
+ } else {
208
+ /**
209
+ * Focus the Slug field and highlight its contents.
210
+ * If this is moved above the selection changes,
211
+ * IE will show a flashing cursor over the dialog.
212
+ */
213
+ window.setTimeout( function() {
214
+ inputs.slug[0].select();
215
+ inputs.slug.trigger( 'focus' );
216
+ } );
217
+ }
218
 
219
  // Load the most recent results if this is the first time opening the panel.
220
  if ( ! rivers.recent.ul.children().length )
276
 
277
  inputs.slug.val( matches[1] );
278
  inputs.search.val( matches[1] );
279
+ inputs.search.trigger( 'keyup' );
280
  }
281
 
282
  // Update display dropdown to match the selected shortcode.
290
  inputs.format.val( 'template' );
291
  inputs.template.val( matches[1] );
292
  }
293
+ inputs.format.trigger( 'change' );
294
  }
295
 
296
  // Update extra classes.
299
  if ( matches && matches.length > 1 ) {
300
  inputs.extraClasses.val( matches[1] );
301
  } else {
302
+ inputs.extraClasses.val( wpInsertPagesL10n.hasOwnProperty( 'tinymce_state' ) ? wpInsertPagesL10n.tinymce_state.class : '' );
303
  }
304
 
305
  // Update extra ID.
308
  if ( matches && matches.length > 1 ) {
309
  inputs.extraID.val( matches[1] );
310
  } else {
311
+ inputs.extraID.val( wpInsertPagesL10n.hasOwnProperty( 'tinymce_state' ) ? wpInsertPagesL10n.tinymce_state.id : '' );
312
  }
313
 
314
  // Update extra inline (i.e., use span instead of div for wrapper).
317
  if ( matches && matches.length > 0 ) {
318
  inputs.extraInline.attr( 'checked', true );
319
  } else {
320
+ inputs.extraInline.attr( 'checked', wpInsertPagesL10n.hasOwnProperty( 'tinymce_state' ) ? wpInsertPagesL10n.tinymce_state.inline : false );
321
  }
322
 
323
  // If this is a private page, reveal the checkbox "Visible to everyone?"
326
  if ( matches && matches.length > 0 ) {
327
  inputs.extraPublic.attr( 'checked', true );
328
  } else {
329
+ inputs.extraPublic.attr( 'checked', wpInsertPagesL10n.hasOwnProperty( 'tinymce_state' ) ? wpInsertPagesL10n.tinymce_state.public : false );
330
  }
331
 
332
  // Update extra querystring.
337
  // closing bracket will terminate the shortcode).
338
  inputs.extraQuerystring.val( matches[1].replace( /&amp;/g, '&' ) );
339
  } else {
340
+ inputs.extraQuerystring.val( wpInsertPagesL10n.hasOwnProperty( 'tinymce_state' ) ? wpInsertPagesL10n.tinymce_state.querystring : '' );
341
  }
342
 
343
  // Update save prompt.
349
  }
350
  },
351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  close: function() {
353
  if ( ! wpInsertPages.isMCE() ) {
354
  wpInsertPages.textarea.focus();
378
  };
379
  },
380
 
381
+ update: function() {
382
  var link,
383
  attrs = wpInsertPages.getAttrs(),
384
  b;
416
  editor.execCommand("mceEndUndoLevel");
417
  },
418
 
419
+ updateFields: function( e, li, originalEvent ) {
420
  if ( wpInsertPagesL10n.format === 'post_id' ) {
421
  inputs.slug.val( li.children('.item-id').val() );
422
  } else {
427
  inputs.slug.focus();
428
  },
429
 
430
+ setDefaultValues: function() {
431
+ // Set inserted page slug/ID and search term to defaults.
432
+ inputs.slug.val('');
433
+ inputs.pageID.val('');
434
+ inputs.search.val( '' );
435
+ inputs.search.data( 'type', 'text' );
436
+ inputs.search.keyup();
437
+
438
+ // Restore field defaults from initial defaults.
439
+ // inputs.format.val('title'); // Leave at last-selected value.
440
+ // inputs.template.val('all'); // Leave at last-selected value.
441
+ inputs.extraClasses.val( wpInsertPagesL10n.hasOwnProperty( 'tinymce_state' ) ? wpInsertPagesL10n.tinymce_state.class : '' );
442
+ inputs.extraID.val( wpInsertPagesL10n.hasOwnProperty( 'tinymce_state' ) ? wpInsertPagesL10n.tinymce_state.id : '' );
443
+ inputs.extraQuerystring.val( wpInsertPagesL10n.hasOwnProperty( 'tinymce_state' ) ? wpInsertPagesL10n.tinymce_state.querystring : '' );
444
+ inputs.extraInline.attr( 'checked', wpInsertPagesL10n.hasOwnProperty( 'tinymce_state' ) ? wpInsertPagesL10n.tinymce_state.inline : false );
445
+ inputs.extraPublic.attr( 'checked', wpInsertPagesL10n.hasOwnProperty( 'tinymce_state' ) ? wpInsertPagesL10n.tinymce_state.public : false );
446
+
447
+ // Enable template dropdown if display format is set to 'template'.
448
+ if ( inputs.format.val() == 'template' ) {
449
+ inputs.template.removeAttr( 'disabled' );
450
+ } else {
451
+ inputs.template.attr( 'disabled', 'disabled' );
452
+ }
453
+ },
454
+
455
+ searchInternalLinks: function() {
456
  var t = $(this), waiting,
457
  search = t.val(),
458
  type = t.data( 'type' );
466
  return;
467
 
468
  wpInsertPages.lastSearch = search;
469
+ waiting = t.parent().find( '.spinner' ).addClass( 'is-active' );
470
 
471
  rivers.search.change( search, type );
472
  rivers.search.ajax( function() {
473
+ waiting.removeClass( 'is-active' );
474
  });
475
  } else {
476
  rivers.search.hide();
478
  }
479
  },
480
 
481
+ next: function() {
482
  rivers.search.next();
483
  rivers.recent.next();
484
  },
485
+ prev: function() {
486
  rivers.search.prev();
487
  rivers.recent.prev();
488
  },
489
 
490
+ keydown: function( event ) {
491
  var fn, key = $.ui.keyCode;
492
 
493
  switch( event.which ) {
504
  }
505
  event.preventDefault();
506
  },
507
+
508
  keyup: function( event ) {
509
  var key = $.ui.keyCode;
510
 
511
  switch( event.which ) {
512
  case key.ESCAPE:
513
+ wpInsertPages.close();
514
+ event.stopImmediatePropagation();
515
  break;
516
  case key.UP:
517
  case key.DOWN:
523
  event.preventDefault();
524
  },
525
 
526
+ delayedCallback: function( func, delay ) {
527
  var timeoutTriggered, funcTriggered, funcArgs, funcContext;
528
 
529
  if ( ! delay )
546
  };
547
  },
548
 
549
+ toggleInternalLinking: function( event ) {
550
  var visible = inputs.wrap.hasClass( 'options-panel-visible');
551
 
552
  inputs.wrap.toggleClass( 'options-panel-visible', ! visible );
577
  $.extend( RiverInsertPages.prototype, {
578
  refresh: function() {
579
  this.deselect();
580
+ this.visible = this.element.is( ':visible' );
581
  },
582
  show: function() {
583
  if ( ! this.visible ) {
605
  liTop = li.position().top;
606
  elTop = this.element.scrollTop();
607
 
608
+ if ( liTop < 0 ) { // Make first visible element.
609
  this.element.scrollTop( elTop + liTop );
610
+ } else if ( liTop + liHeight > elHeight ) { // Make last visible element.
611
  this.element.scrollTop( elTop + liTop - elHeight + liHeight );
612
  }
613
 
614
  // Trigger the river-select event
615
+ this.element.trigger( 'river-select', [ li, event, this ] );
616
  },
617
  deselect: function() {
618
  if ( this.selected )
619
+ this.selected.removeClass( 'selected' );
620
  this.selected = false;
621
  },
622
  prev: function() {
625
 
626
  var to;
627
  if ( this.selected ) {
628
+ to = this.selected.prev( 'li' );
629
  if ( to.length )
630
  this.select( to );
631
  }
634
  if ( ! this.visible )
635
  return;
636
 
637
+ var to = this.selected ? this.selected.next( 'li' ) : $( 'li:not(.unselectable):first', this.element );
638
  if ( to.length )
639
  this.select( to );
640
  },
655
 
656
  this._search = search;
657
  this.query = new QueryInsertPages( search, type );
658
+ this.element.scrollTop( 0 );
659
  },
660
  process: function( results, params ) {
661
  var list = '', alt = true, classes = '',
662
  firstPage = params.page == 1;
663
 
664
+ if ( ! results ) {
665
  if ( firstPage ) {
666
+ list += '<li class="unselectable"><span class="item-title"><em>' + wpInsertPagesL10n.noMatchesFound + '</em></span></li>';
 
 
667
  }
668
  } else {
669
  $.each( results, function() {
689
  el = this.element,
690
  bottom = el.scrollTop() + el.height();
691
 
692
+ if ( ! this.query.ready() || bottom < this.contentHeight.height() - wpInsertPages.riverBottomThreshold )
693
  return;
694
 
695
+ setTimeout( function() {
696
  var newTop = el.scrollTop(),
697
  newBottom = newTop + el.height();
698
 
699
+ if ( ! self.query.ready() || newBottom < self.contentHeight.height() - wpInsertPages.riverBottomThreshold )
700
  return;
701
 
702
+ self.waiting.addClass( 'is-active' );
703
  el.scrollTop( newTop + self.waiting.outerHeight() );
704
 
705
  self.ajax( function() {
706
+ self.waiting.removeClass( 'is-active' );
707
  });
708
  }, wpInsertPages.timeToTriggerRiverInsertPages );
709
  }
719
 
720
  $.extend( QueryInsertPages.prototype, {
721
  ready: function() {
722
+ return ! ( this.querying || this.allLoaded );
723
  },
724
  ajax: function( callback ) {
725
  var self = this,
733
  if ( this.search )
734
  query.search = this.search;
735
 
 
 
736
  this.querying = true;
737
+
738
+ // query.pageID = inputs.pageID.val(); // Remove?
739
+
740
+ $.post( window.ajaxurl, query, function( r ) {
741
  self.page++;
742
  self.querying = false;
743
+ self.allLoaded = ! r;
744
  callback( r, query );
745
+ }, 'json' );
746
  }
747
  });
748
 
749
  $( document ).ready( wpInsertPages.init );
750
+ })( jQuery, window.wpInsertPagesL10n, window.wp );
 
readme.txt CHANGED
@@ -111,6 +111,13 @@ Just one! The plugin prevents you from embedding a page in itself, but you can t
111
 
112
  == Changelog ==
113
 
 
 
 
 
 
 
 
114
  = 3.5.10 =
115
  * Allow Insert Pages TinyMCE widget to run in a front-end wp_editor().
116
 
111
 
112
  == Changelog ==
113
 
114
+ = 3.6.0 =
115
+ * Add `insert_pages_tinymce_state` filter to set TinyMCE modal field defaults. [Details](https://wordpress.org/support/topic/customise-modal-content/)
116
+ * Add `insert_pages_available_templates` filter to customize the list of allowed custom templates. [Details](https://wordpress.org/support/topic/customise-modal-content/)
117
+ * Update TinyMCE plugin to match changes in current wp-link dialog in core.
118
+ * Fix TinyMCE modal height on mobile.
119
+ * Ensure scripts/styles are loaded before adding TinyMCE plugin.
120
+
121
  = 3.5.10 =
122
  * Allow Insert Pages TinyMCE widget to run in a front-end wp_editor().
123