Shortcake (Shortcode UI) - Version 0.2.0

Version Description

(March 18, 2015) =

  • JS abstracted using Browserify.
  • Enhancements to "Add Post Element" UI: shortcodes sorted alphabetically; search based on label.
  • Much easier to select shortcode previews that include iframes.
  • WordPress 4.2 compatibility.
  • Added color picker to list of potential fields.
  • Bug fix: IE11 compatibility.
  • Bug fix: Checkbox field can now be unchecked.
  • Full release notes.
Download this release

Release Info

Developer danielbachhuber
Plugin Icon 128x128 Shortcake (Shortcode UI)
Version 0.2.0
Comparing to
See all releases

Version 0.2.0

Files changed (51) hide show
  1. Gruntfile.js +164 -0
  2. LICENSE +340 -0
  3. composer.json +13 -0
  4. css/sass/_field-image.scss +77 -0
  5. css/sass/shortcode-ui-editor-styles.scss +54 -0
  6. css/sass/shortcode-ui.scss +144 -0
  7. css/shortcode-ui-editor-styles.css +38 -0
  8. css/shortcode-ui-editor-styles.css.map +10 -0
  9. css/shortcode-ui.css +147 -0
  10. css/shortcode-ui.css.map +11 -0
  11. inc/class-shortcode-ui.php +237 -0
  12. inc/fields/class-field-attachment.php +74 -0
  13. inc/fields/class-field-color.php +99 -0
  14. inc/fields/class-shortcode-ui-fields.php +81 -0
  15. inc/templates/edit-form.tpl.php +134 -0
  16. inc/templates/list-item.tpl.php +13 -0
  17. inc/templates/media-frame.tpl.php +14 -0
  18. js/build/field-attachment.js +385 -0
  19. js/build/field-color.js +256 -0
  20. js/build/shortcode-ui.js +1393 -0
  21. js/collections/shortcode-attributes.js +17 -0
  22. js/collections/shortcodes.js +9 -0
  23. js/controllers/media-controller.js +51 -0
  24. js/field-attachment.js +148 -0
  25. js/field-color.js +19 -0
  26. js/models/inner-content.js +10 -0
  27. js/models/shortcode-attribute.js +13 -0
  28. js/models/shortcode.js +97 -0
  29. js/shortcode-ui.js +27 -0
  30. js/utils/shortcode-view-constructor.js +304 -0
  31. js/utils/sui.js +9 -0
  32. js/views/edit-attribute-field.js +51 -0
  33. js/views/edit-shortcode-form.js +53 -0
  34. js/views/insert-shortcode-list-item.js +30 -0
  35. js/views/insert-shortcode-list.js +42 -0
  36. js/views/media-frame.js +109 -0
  37. js/views/media-toolbar.js +28 -0
  38. js/views/search-shortcode.js +44 -0
  39. js/views/shortcode-preview.js +180 -0
  40. js/views/shortcode-ui.js +124 -0
  41. js/views/tabbed-view.js +121 -0
  42. languages/shortcode-ui-pt_PT.mo +0 -0
  43. languages/shortcode-ui-pt_PT.po +73 -0
  44. languages/shortcode-ui.pot +90 -0
  45. package.json +36 -0
  46. readme.txt +49 -0
  47. screenshot-1.png +0 -0
  48. screenshot-2.png +0 -0
  49. screenshot-3.png +0 -0
  50. screenshot-4.png +0 -0
  51. shortcode-ui.php +74 -0
Gruntfile.js ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports = function( grunt ) {
2
+
3
+ 'use strict';
4
+ var remapify = require('remapify');
5
+ var banner = '/**\n * <%= pkg.homepage %>\n * Copyright (c) <%= grunt.template.today("yyyy") %>\n * This file is generated automatically. Do not edit.\n */\n';
6
+ // Project configuration
7
+ grunt.initConfig( {
8
+
9
+ pkg: grunt.file.readJSON( 'package.json' ),
10
+
11
+ sass: {
12
+ dist: {
13
+ files: {
14
+ 'css/shortcode-ui.css' : 'css/sass/shortcode-ui.scss',
15
+ 'css/shortcode-ui-editor-styles.css' : 'css/sass/shortcode-ui-editor-styles.scss',
16
+ },
17
+ options: {
18
+ sourceMap: true
19
+ }
20
+ }
21
+ },
22
+
23
+ watch: {
24
+
25
+ styles: {
26
+ files: ['css/**/*.scss'],
27
+ tasks: ['styles'],
28
+ options: {
29
+ debounceDelay: 500,
30
+ livereload: true,
31
+ sourceMap: true
32
+ }
33
+ },
34
+
35
+ scripts: {
36
+ files: ['js/**/*.js', 'js-tests/src/**/*.js', '!js/build/**/*'],
37
+ tasks: ['scripts'],
38
+ options: {
39
+ debounceDelay: 500,
40
+ livereload: true,
41
+ sourceMap: true
42
+ }
43
+ }
44
+
45
+ },
46
+
47
+ browserify : {
48
+
49
+ options: {
50
+ preBundleCB: function(b) {
51
+
52
+ b.plugin(remapify, [
53
+ {
54
+ cwd: 'js/models',
55
+ src: '**/*.js',
56
+ expose: 'sui-models'
57
+ },
58
+ {
59
+ cwd: 'js/controllers',
60
+ src: '**/*.js',
61
+ expose: 'sui-controllers'
62
+ },
63
+ {
64
+ cwd: 'js/collections',
65
+ src: '**/*.js',
66
+ expose: 'sui-collections'
67
+ },
68
+ {
69
+ cwd: 'js/views',
70
+ src: '**/*.js',
71
+ expose: 'sui-views'
72
+ },
73
+ {
74
+ cwd: 'js/utils',
75
+ src: '**/*.js',
76
+ expose: 'sui-utils'
77
+ }
78
+ ]);
79
+
80
+ }
81
+ },
82
+
83
+ dist: {
84
+ files : {
85
+ 'js/build/shortcode-ui.js' : ['js/shortcode-ui.js'],
86
+ 'js/build/field-attachment.js' : ['js/field-attachment.js'],
87
+ 'js/build/field-color.js' : ['js/field-color.js'],
88
+ },
89
+ options: {
90
+ transform: ['browserify-shim']
91
+ }
92
+ },
93
+
94
+ // Proccess Jasmine Tests.
95
+ specs: {
96
+ files : {
97
+ 'js-tests/build/specs.js' : ['js-tests/src/**/*Spec.js'],
98
+ 'js-tests/build/helpers.js' : ['js-tests/src/**/*Helper.js'],
99
+ },
100
+ options: {
101
+ transform: ['browserify-shim']
102
+ }
103
+ }
104
+
105
+ },
106
+
107
+ jasmine: {
108
+ shortcodeUI: {
109
+ options: {
110
+ specs: 'js-tests/build/specs.js',
111
+ helpers: 'js-tests/build/helpers.js',
112
+ vendor: [
113
+ 'js-tests/vendor/jquery.js',
114
+ 'js-tests/vendor/underscore.js',
115
+ 'js-tests/vendor/backbone.js',
116
+ 'js-tests/vendor/wp-util.js',
117
+ 'js-tests/vendor/mock-ajax.js',
118
+ ],
119
+ }
120
+ }
121
+ },
122
+
123
+ addtextdomain: {
124
+ options: {
125
+ textdomain: 'shortcode-ui', // Project text domain.
126
+ },
127
+ target: {
128
+ files: {
129
+ src: [ '*.php', '**/*.php', '!node_modules/**', '!php-tests/**', '!bin/**' ]
130
+ }
131
+ }
132
+ }, //addtextdomain
133
+
134
+ makepot: {
135
+ target: {
136
+ options: {
137
+ domainPath: '/languages',
138
+ mainFile: 'shortcode-ui.php',
139
+ potFilename: 'shortcode-ui.pot',
140
+ potHeaders: {
141
+ poedit: true,
142
+ 'x-poedit-keywordslist': true
143
+ },
144
+ type: 'wp-plugin',
145
+ updateTimestamp: true
146
+ }
147
+ }
148
+ }, //makepot
149
+ } );
150
+
151
+ grunt.loadNpmTasks( 'grunt-sass' );
152
+ grunt.loadNpmTasks( 'grunt-contrib-watch' );
153
+ grunt.loadNpmTasks( 'grunt-browserify' );
154
+ grunt.loadNpmTasks( 'grunt-wp-i18n' );
155
+ grunt.loadNpmTasks( 'grunt-contrib-jasmine' );
156
+
157
+ grunt.registerTask( 'scripts', [ 'browserify', 'jasmine' ] );
158
+ grunt.registerTask( 'styles', [ 'sass' ] );
159
+ grunt.registerTask( 'default', [ 'scripts', 'styles' ] );
160
+ grunt.registerTask( 'i18n', ['addtextdomain', 'makepot'] );
161
+
162
+ grunt.util.linefeed = '\n';
163
+
164
+ };
LICENSE ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ {description}
294
+ Copyright (C) {year} {fullname}
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ {signature of Ty Coon}, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
340
+
composer.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "fusioneng/Shortcake",
3
+ "description": "Shortcake makes using WordPress shortcodes a piece of cake.",
4
+ "type": "wordpress-plugin",
5
+ "homepage": "https://github.com/fusioneng/Shortcake",
6
+ "authors": [
7
+ {
8
+ "name": "Fusion",
9
+ "email": "tech@fusion.net",
10
+ "homepage": "http://fusion.net"
11
+ }
12
+ ]
13
+ }
css/sass/_field-image.scss ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .edit-shortcode-form .shortcake-attachment-preview {
2
+
3
+ width: 150px;
4
+ height: 150px;
5
+ margin: 0 10px 10px 0;
6
+ line-height: 150px;
7
+ text-align: center;
8
+ padding: 0;
9
+
10
+ &:before {
11
+ display: none;
12
+ }
13
+
14
+ &:not( .has-attachment ) {
15
+ border: 2px dashed #DDD;
16
+ border-radius: 2px;
17
+ background: transparent;
18
+ box-shadow: none;
19
+ }
20
+
21
+ .button.add {
22
+ vertical-align: middle;
23
+ z-index: 1;
24
+ }
25
+
26
+ .button.remove {
27
+
28
+ z-index: 1;
29
+ display: none;
30
+ position: absolute;
31
+ top: 5px;
32
+ right: 5px;
33
+ border: 1px solid #aaa;
34
+ box-shadow: 0 1px 3px rgba( 0, 0, 0, 0.15 );
35
+ text-indent: 100%;
36
+ whitespace: nowrap;
37
+ width: 24px;
38
+ height: 24px;
39
+ padding: 0;
40
+
41
+ &:after {
42
+ content: "\00d7";
43
+ position: absolute;
44
+ top: -1px;
45
+ left: 5px;
46
+ font-size: 22px;
47
+ text-indent: 0;
48
+ }
49
+ }
50
+
51
+ .loading-indicator,
52
+ &.loading .button.add {
53
+ display: none;
54
+ }
55
+
56
+ &.loading .loading-indicator {
57
+ display: block;
58
+ position: absolute;
59
+ top: 50%;
60
+ left: 50%;
61
+ margin: -10px 0 0 -10px;
62
+ }
63
+
64
+ .filename {
65
+ line-height: 1.4em
66
+ }
67
+
68
+ &.has-attachment {
69
+ .button.add {
70
+ display: none;
71
+ }
72
+ .button.remove {
73
+ display: block;
74
+ }
75
+ }
76
+
77
+ }
css/sass/shortcode-ui-editor-styles.scss ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wpview-wrap {
2
+ min-height: 48px;
3
+
4
+ &.wp-mce-view-show-toolbar {
5
+
6
+ .toolbar {
7
+ display: block;
8
+ }
9
+ }
10
+
11
+ .shortcake-error {
12
+ color: red;
13
+ font-weight: bold;
14
+ }
15
+
16
+ }
17
+
18
+ .shortcake-preview .loading-placeholder {
19
+ .wpview-loading {
20
+ width: 60px;
21
+ height: 5px;
22
+ overflow: hidden;
23
+ background-color: transparent;
24
+ margin: 10px auto 0;
25
+
26
+ ins {
27
+ background-color: #333;
28
+ margin: 0 0 0 -60px;
29
+ width: 60px;
30
+ height: 5px;
31
+ display: block;
32
+ -webkit-animation: preview-loading 1.3s infinite 1s linear;
33
+ animation: preview-loading 1.3s infinite 1s linear;
34
+ }
35
+ }
36
+ }
37
+
38
+ @-webkit-keyframes preview-loading {
39
+ 0% {
40
+ margin-left: -60px;
41
+ }
42
+ 100% {
43
+ margin-left: 60px;
44
+ }
45
+ }
46
+
47
+ @keyframes preview-loading {
48
+ 0% {
49
+ margin-left: -60px;
50
+ }
51
+ 100% {
52
+ margin-left: 60px;
53
+ }
54
+ }
css/sass/shortcode-ui.scss ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wp-core-ui .button.shortcode-editor-open-insert-modal {
2
+ margin-right: 10px;
3
+ }
4
+
5
+ .shortcode-ui-insert-modal {
6
+
7
+ .media-modal {
8
+ max-width: 800px;
9
+ max-height: 800px;
10
+ margin: auto;
11
+ }
12
+
13
+ .media-frame-content {
14
+ top: 54px;
15
+ }
16
+
17
+ }
18
+
19
+ .add-shortcode-list {
20
+ padding: 0 10px;
21
+
22
+ .shortcode-list-item {
23
+
24
+ margin: 10px;
25
+ float: left;
26
+
27
+ -webkit-box-shadow: inset 0 0 15px rgba( 0, 0, 0, 0.1 ), inset 0 0 0 1px rgba( 0, 0, 0, 0.1 );
28
+ box-shadow: inset 0 0 15px rgba( 0, 0, 0, 0.1 ), inset 0 0 0 1px rgba( 0, 0, 0, 0.1 );
29
+ background: #eee;
30
+ cursor: pointer;
31
+ position: relative;
32
+ text-align: center;
33
+ width: 150px;
34
+ height: 150px;
35
+
36
+ .add-shortcode-list-item-icon {
37
+
38
+ font-size: 64px;
39
+ line-height: 150px;
40
+ vertical-align: middle;
41
+
42
+ .dashicons {
43
+ display: inline-block;
44
+ font-size: inherit;
45
+ line-height: inherit;
46
+ width: auto;
47
+ height: auto;
48
+ position: relative;
49
+ top: -14px;
50
+ }
51
+
52
+ }
53
+
54
+ .add-shortcode-list-item-title {
55
+ margin: 0;
56
+ padding: 5px;
57
+ position: absolute;
58
+ left: 0;
59
+ right: 0;
60
+ bottom: 0;
61
+ overflow: hidden;
62
+ max-height: 100%;
63
+ word-wrap: break-word;
64
+ text-align: center;
65
+ font-weight: bold;
66
+ background: rgba( 255, 255, 255, 0.8 );
67
+ -webkit-box-shadow: inset 0 0 0 1px rgba( 0, 0, 0, 0.15 );
68
+ box-shadow: inset 0 0 0 1px rgba( 0, 0, 0, 0.15 );
69
+ }
70
+ }
71
+
72
+ }
73
+
74
+ .shortcode-ui-content {
75
+ .edit-shortcode-tabs {
76
+ height: 34px;
77
+ padding: 10px 10px 0;
78
+ }
79
+
80
+ .edit-shortcode-tabs-content {
81
+ padding: 10px;
82
+ border-top: 1px solid #ddd;
83
+ }
84
+
85
+ a.wp-color-result {
86
+ border-bottom: 1px solid #ccc;
87
+ }
88
+
89
+ .media-toolbar {
90
+ position: relative;
91
+ height: auto;
92
+ }
93
+ }
94
+
95
+ .edit-shortcode-form {
96
+
97
+ padding: 5px 20px;
98
+
99
+ label {
100
+ display: block;
101
+ clear: both;
102
+ }
103
+
104
+ input,
105
+ textarea {
106
+ border: 1px solid #ddd;
107
+ -webkit-box-shadow: inset 0 1px 2px rgba( 0, 0, 0, 0.07 );
108
+ box-shadow: inset 0 1px 2px rgba( 0, 0, 0, 0.07 );
109
+ background-color: #fff;
110
+ color: #333;
111
+ outline: none;
112
+ -webkit-transition: 0.05s border-color ease-in-out;
113
+ transition: 0.05s border-color ease-in-out;
114
+ max-width: 100%;
115
+ }
116
+
117
+ textarea {
118
+ width: 100%;
119
+ max-width: 100%;
120
+ min-height: 100px;
121
+ }
122
+
123
+ .edit-shortcode-form-fields {
124
+ > div { margin-bottom: 10px; }
125
+ }
126
+
127
+ .field-block {
128
+ padding: 1em 0;
129
+ label {
130
+ display: block;
131
+ margin-bottom: 10px;
132
+ }
133
+ }
134
+
135
+ .field-inline {
136
+ label {
137
+ display: inline-block;
138
+ }
139
+ padding-top: 10px;
140
+ }
141
+
142
+ }
143
+
144
+ @import 'field-image';
css/shortcode-ui-editor-styles.css ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wpview-wrap {
2
+ min-height: 48px; }
3
+ .wpview-wrap.wp-mce-view-show-toolbar .toolbar {
4
+ display: block; }
5
+ .wpview-wrap .shortcake-error {
6
+ color: red;
7
+ font-weight: bold; }
8
+
9
+ .shortcake-preview .loading-placeholder .wpview-loading {
10
+ width: 60px;
11
+ height: 5px;
12
+ overflow: hidden;
13
+ background-color: transparent;
14
+ margin: 10px auto 0; }
15
+ .shortcake-preview .loading-placeholder .wpview-loading ins {
16
+ background-color: #333;
17
+ margin: 0 0 0 -60px;
18
+ width: 60px;
19
+ height: 5px;
20
+ display: block;
21
+ -webkit-animation: preview-loading 1.3s infinite 1s linear;
22
+ animation: preview-loading 1.3s infinite 1s linear; }
23
+
24
+ @-webkit-keyframes preview-loading {
25
+ 0% {
26
+ margin-left: -60px; }
27
+
28
+ 100% {
29
+ margin-left: 60px; } }
30
+
31
+ @keyframes preview-loading {
32
+ 0% {
33
+ margin-left: -60px; }
34
+
35
+ 100% {
36
+ margin-left: 60px; } }
37
+
38
+ /*# sourceMappingURL=shortcode-ui-editor-styles.css.map */
css/shortcode-ui-editor-styles.css.map ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": 3,
3
+ "file": "shortcode-ui-editor-styles.css",
4
+ "sources": [
5
+ "../shortcode-ui-editor-styles.scss"
6
+ ],
7
+ "sourcesContent": [],
8
+ "mappings": "AAAA;EACC,AAAY;EAIb,AAAY,AAA0B;IACnC,AAAS;EAIZ,AAAa;IACX,AAAO;IACP,AAAa;;AAMf,AAAmB,AAAqB;EACtC,AAAO;EACP,AAAQ;EACR,AAAU;EACV,AAAkB;EAClB,AAAQ;EAEV,AAAmB,AAAqB,AAAgB;IACrD,AAAkB;IAClB,AAAQ;IACR,AAAO;IACP,AAAQ;IACR,AAAS;IACT,AAAmB;IACnB,AAAW;;mBAKK;EACnB;IACE,AAAa;;EAEf;IACE,AAAa;;WAIJ;EACX;IACE,AAAa;;EAEf;IACE,AAAa",
9
+ "names": []
10
+ }
css/shortcode-ui.css ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wp-core-ui .button.shortcode-editor-open-insert-modal {
2
+ margin-right: 10px; }
3
+
4
+ .shortcode-ui-insert-modal .media-modal {
5
+ max-width: 800px;
6
+ max-height: 800px;
7
+ margin: auto; }
8
+ .shortcode-ui-insert-modal .media-frame-content {
9
+ top: 54px; }
10
+
11
+ .add-shortcode-list {
12
+ padding: 0 10px; }
13
+ .add-shortcode-list .shortcode-list-item {
14
+ margin: 10px;
15
+ float: left;
16
+ -webkit-box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(0, 0, 0, 0.1);
17
+ box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(0, 0, 0, 0.1);
18
+ background: #eee;
19
+ cursor: pointer;
20
+ position: relative;
21
+ text-align: center;
22
+ width: 150px;
23
+ height: 150px; }
24
+ .add-shortcode-list .shortcode-list-item .add-shortcode-list-item-icon {
25
+ font-size: 64px;
26
+ line-height: 150px;
27
+ vertical-align: middle; }
28
+ .add-shortcode-list .shortcode-list-item .add-shortcode-list-item-icon .dashicons {
29
+ display: inline-block;
30
+ font-size: inherit;
31
+ line-height: inherit;
32
+ width: auto;
33
+ height: auto;
34
+ position: relative;
35
+ top: -14px; }
36
+ .add-shortcode-list .shortcode-list-item .add-shortcode-list-item-title {
37
+ margin: 0;
38
+ padding: 5px;
39
+ position: absolute;
40
+ left: 0;
41
+ right: 0;
42
+ bottom: 0;
43
+ overflow: hidden;
44
+ max-height: 100%;
45
+ word-wrap: break-word;
46
+ text-align: center;
47
+ font-weight: bold;
48
+ background: rgba(255, 255, 255, 0.8);
49
+ -webkit-box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
50
+ box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
51
+
52
+ .shortcode-ui-content .edit-shortcode-tabs {
53
+ height: 34px;
54
+ padding: 10px 10px 0; }
55
+ .shortcode-ui-content .edit-shortcode-tabs-content {
56
+ padding: 10px;
57
+ border-top: 1px solid #ddd; }
58
+ .shortcode-ui-content a.wp-color-result {
59
+ border-bottom: 1px solid #ccc; }
60
+ .shortcode-ui-content .media-toolbar {
61
+ position: relative;
62
+ height: auto; }
63
+
64
+ .edit-shortcode-form {
65
+ padding: 5px 20px; }
66
+ .edit-shortcode-form label {
67
+ display: block;
68
+ clear: both; }
69
+ .edit-shortcode-form input, .edit-shortcode-form textarea {
70
+ border: 1px solid #ddd;
71
+ -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07);
72
+ box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07);
73
+ background-color: #fff;
74
+ color: #333;
75
+ outline: none;
76
+ -webkit-transition: 0.05s border-color ease-in-out;
77
+ transition: 0.05s border-color ease-in-out;
78
+ max-width: 100%; }
79
+ .edit-shortcode-form textarea {
80
+ width: 100%;
81
+ max-width: 100%;
82
+ min-height: 100px; }
83
+ .edit-shortcode-form .edit-shortcode-form-fields > div {
84
+ margin-bottom: 10px; }
85
+ .edit-shortcode-form .field-block {
86
+ padding: 1em 0; }
87
+ .edit-shortcode-form .field-block label {
88
+ display: block;
89
+ margin-bottom: 10px; }
90
+ .edit-shortcode-form .field-inline {
91
+ padding-top: 10px; }
92
+ .edit-shortcode-form .field-inline label {
93
+ display: inline-block; }
94
+
95
+ .edit-shortcode-form .shortcake-attachment-preview {
96
+ width: 150px;
97
+ height: 150px;
98
+ margin: 0 10px 10px 0;
99
+ line-height: 150px;
100
+ text-align: center;
101
+ padding: 0; }
102
+ .edit-shortcode-form .shortcake-attachment-preview:before {
103
+ display: none; }
104
+ .edit-shortcode-form .shortcake-attachment-preview:not(.has-attachment) {
105
+ border: 2px dashed #DDD;
106
+ border-radius: 2px;
107
+ background: transparent;
108
+ box-shadow: none; }
109
+ .edit-shortcode-form .shortcake-attachment-preview .button.add {
110
+ vertical-align: middle;
111
+ z-index: 1; }
112
+ .edit-shortcode-form .shortcake-attachment-preview .button.remove {
113
+ z-index: 1;
114
+ display: none;
115
+ position: absolute;
116
+ top: 5px;
117
+ right: 5px;
118
+ border: 1px solid #aaa;
119
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
120
+ text-indent: 100%;
121
+ whitespace: nowrap;
122
+ width: 24px;
123
+ height: 24px;
124
+ padding: 0; }
125
+ .edit-shortcode-form .shortcake-attachment-preview .button.remove:after {
126
+ content: "\00d7";
127
+ position: absolute;
128
+ top: -1px;
129
+ left: 5px;
130
+ font-size: 22px;
131
+ text-indent: 0; }
132
+ .edit-shortcode-form .shortcake-attachment-preview .loading-indicator, .edit-shortcode-form .shortcake-attachment-preview.loading .button.add {
133
+ display: none; }
134
+ .edit-shortcode-form .shortcake-attachment-preview.loading .loading-indicator {
135
+ display: block;
136
+ position: absolute;
137
+ top: 50%;
138
+ left: 50%;
139
+ margin: -10px 0 0 -10px; }
140
+ .edit-shortcode-form .shortcake-attachment-preview .filename {
141
+ line-height: 1.4em; }
142
+ .edit-shortcode-form .shortcake-attachment-preview.has-attachment .button.add {
143
+ display: none; }
144
+ .edit-shortcode-form .shortcake-attachment-preview.has-attachment .button.remove {
145
+ display: block; }
146
+
147
+ /*# sourceMappingURL=shortcode-ui.css.map */
css/shortcode-ui.css.map ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": 3,
3
+ "file": "shortcode-ui.css",
4
+ "sources": [
5
+ "../shortcode-ui.scss",
6
+ "../_field-image.scss"
7
+ ],
8
+ "sourcesContent": [],
9
+ "mappings": "AAAA,AAAY,AAAO;EAClB,AAAc;;AAKf,AAA2B;EACzB,AAAW;EACX,AAAY;EACZ,AAAQ;AAGV,AAA2B;EACzB,AAAK;;AAKP;EACC,AAAS;EAEV,AAAoB;IAElB,AAAQ;IACR,AAAO;IAEP,AAAsD;IACtD,AAA8C;IAC9C,AAAY;IACZ,AAAQ;IACR,AAAU;IACV,AAAY;IACZ,AAAO;IACP,AAAQ;IAEV,AAAoB,AAAqB;MAEtC,AAAW;MACX,AAAa;MACb,AAAgB;MAEnB,AAAoB,AAAqB,AAA8B;QACnE,AAAS;QACT,AAAW;QACX,AAAa;QACb,AAAO;QACP,AAAQ;QACR,AAAU;QACV,AAAK;IAKT,AAAoB,AAAqB;MACtC,AAAQ;MACR,AAAS;MACT,AAAU;MACV,AAAM;MACN,AAAO;MACP,AAAQ;MACR,AAAU;MACV,AAAY;MACZ,AAAW;MACX,AAAY;MACZ,AAAa;MACb,AAAY;MACZ,AAAoB;MACpB,AAAY;;AAOf,AAAsB;EACpB,AAAQ;EACR,AAAS;AAGX,AAAsB;EACpB,AAAS;EACT,AAAY;AAGd,AAAsB,AAAC;EACrB,AAAe;AAGjB,AAAsB;EACpB,AAAU;EACV,AAAQ;;AAIV;EAEC,AAAS;EAEV,AAAqB;IACnB,AAAS;IACT,AAAO;EAGT,AAAqB,AAAO,AAAqB;IAE/C,AAAQ;IACR,AAAoB;IACpB,AAAY;IACZ,AAAkB;IAClB,AAAO;IACP,AAAS;IACT,AAAoB;IACpB,AAAY;IACZ,AAAW;EAGb,AAAqB;IACnB,AAAO;IACP,AAAW;IACX,AAAY;EAId,AAAqB,AAA8B;IAAzC,AAAe;EAGzB,AAAqB;IACnB,AAAS;IACX,AAAqB,AAAa;MAC/B,AAAS;MACT,AAAe;EAIlB,AAAqB;IAInB,AAAa;IAHf,AAAqB,AAAc;MAChC,AAAS;;ACxIZ,AAAqB;EAEpB,AAAO;EACP,AAAQ;EACR,AAAQ;EACR,AAAa;EACb,AAAY;EACZ,AAAS;EAEV,AAAqB,AAA6B;IAChD,AAAS;EAGX,AAAqB,AAA6B,AAAK;IACrD,AAAQ;IACR,AAAe;IACf,AAAY;IACZ,AAAY;EAGd,AAAqB,AAA8B,AAAO;IACxD,AAAgB;IAChB,AAAS;EAGX,AAAqB,AAA8B,AAAO;IAExD,AAAS;IACT,AAAS;IACT,AAAU;IACV,AAAK;IACL,AAAO;IACP,AAAQ;IACR,AAAY;IACZ,AAAa;IACb,AAAY;IACZ,AAAO;IACP,AAAQ;IACR,AAAS;IAEX,AAAqB,AAA8B,AAAO,AAAO;MAC9D,AAAS;MACT,AAAU;MACV,AAAK;MACL,AAAM;MACN,AAAW;MACX,AAAa;EAIhB,AAAqB,AAA8B,AAAoB,AAAqB,AAA6B,AAAS,AAAO;IAEvI,AAAS;EAGX,AAAqB,AAA6B,AAAS;IACzD,AAAS;IACT,AAAU;IACV,AAAK;IACL,AAAM;IACN,AAAQ;EAGV,AAAqB,AAA8B;IACjD,AAAa;EAIf,AAAqB,AAA6B,AAAgB,AAAO;IACtE,AAAS;EAEZ,AAAqB,AAA6B,AAAgB,AAAO;IACtE,AAAS",
10
+ "names": []
11
+ }
inc/class-shortcode-ui.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shortcode_UI {
4
+
5
+ private $plugin_dir;
6
+ private $plugin_url;
7
+
8
+ private $shortcodes = array();
9
+
10
+ private static $instance = null;
11
+
12
+ public static function get_instance() {
13
+ if ( null == self::$instance ) {
14
+ self::$instance = new self;
15
+ self::$instance->setup_actions();
16
+ }
17
+
18
+ return self::$instance;
19
+ }
20
+
21
+ function __construct() {
22
+
23
+ $this->plugin_version = '0.1';
24
+ $this->plugin_dir = plugin_dir_path( dirname( __FILE__ ) );
25
+ $this->plugin_url = plugin_dir_url( dirname( __FILE__ ) );
26
+
27
+ }
28
+
29
+ private function setup_actions() {
30
+ $this->add_editor_style();
31
+ add_action( 'wp_enqueue_editor', array( $this, 'action_wp_enqueue_editor' ) );
32
+ add_action( 'wp_ajax_do_shortcode', array( $this, 'handle_ajax_do_shortcode' ) );
33
+ }
34
+
35
+ public function register_shortcode_ui( $shortcode_tag, $args = array() ) {
36
+
37
+ $defaults = array(
38
+ 'label' => '',
39
+ 'attrs' => array(),
40
+ 'listItemImage' => '', // src or 'dashicons-' - used in insert list.
41
+ 'inner_content' => false,
42
+ );
43
+
44
+ $args = wp_parse_args( $args, $defaults );
45
+
46
+
47
+ // inner_content=true is a valid argument, but we want more detail
48
+ if ( is_bool( $args['inner_content'] ) && true === $args['inner_content'] ) {
49
+ $args['inner_content'] = array(
50
+ 'label' => esc_html__( 'Inner Content', 'shortcode-ui' ),
51
+ 'description' => '',
52
+ 'placeholder' => '',
53
+ );
54
+ }
55
+
56
+ //following code is for backward compatibility
57
+ //which will be removed in the next version. (to supports 'attr' => 'content' special case)
58
+ $num_attrs = count( $args['attrs'] );
59
+ for ( $i = 0; $i < $num_attrs; $i++ ) {
60
+ if ( ! isset( $args['attrs'][ $i ]['attr'] ) || $args['attrs'][ $i ]['attr'] !== 'content' ) {
61
+ continue;
62
+ }
63
+
64
+ $args['inner_content'] = array();
65
+ foreach ( $args['attrs'][ $i ] as $key => $value ) {
66
+ if ( $key == 'attr' ) {
67
+ continue;
68
+ }
69
+ $args['inner_content'][ $key ] = $value;
70
+ }
71
+
72
+ $index = $i;
73
+ }
74
+ if ( isset( $index ) ) {
75
+ array_splice( $args['attrs'], $index, 1 );
76
+ }
77
+
78
+ // strip invalid
79
+ foreach ( $args as $key => $value ) {
80
+ if ( ! array_key_exists( $key, $defaults ) ) {
81
+ unset( $args[ $key ] );
82
+ }
83
+ }
84
+
85
+ $args['shortcode_tag'] = $shortcode_tag;
86
+ $this->shortcodes[ $shortcode_tag ] = $args;
87
+
88
+ }
89
+
90
+ public function get_shortcodes() {
91
+ return $this->shortcodes;
92
+ }
93
+
94
+ public function get_shortcode( $shortcode_tag ) {
95
+
96
+ if ( isset( $this->shortcodes[ $shortcode_tag ] ) ) {
97
+ return $this->shortcodes[ $shortcode_tag ];
98
+ }
99
+
100
+ }
101
+
102
+ public function add_editor_style() {
103
+ add_editor_style( $this->plugin_url . '/css/shortcode-ui-editor-styles.css' );
104
+ }
105
+
106
+ public function enqueue() {
107
+
108
+ if ( did_action( 'enqueue_shortcode_ui' ) ) {
109
+ return;
110
+ }
111
+
112
+ // make sure media library is queued
113
+ wp_enqueue_media();
114
+
115
+ $shortcodes = array_values( $this->shortcodes );
116
+ usort( $shortcodes, array( $this, 'compare_shortcodes_by_label' ) );
117
+
118
+ wp_enqueue_script( 'shortcode-ui', $this->plugin_url . 'js/build/shortcode-ui.js', array( 'jquery', 'backbone', 'mce-view' ), $this->plugin_version );
119
+ wp_enqueue_style( 'shortcode-ui', $this->plugin_url . 'css/shortcode-ui.css', array(), $this->plugin_version );
120
+ wp_localize_script( 'shortcode-ui', ' shortcodeUIData', array(
121
+ 'shortcodes' => $shortcodes,
122
+ 'strings' => array(
123
+ 'media_frame_title' => esc_html__( 'Insert Post Element', 'shortcode-ui' ),
124
+ 'media_frame_menu_insert_label' => esc_html__( 'Insert Post Element', 'shortcode-ui' ),
125
+ 'media_frame_menu_update_label' => esc_html__( 'Post Element Details', 'shortcode-ui' ),
126
+ 'media_frame_toolbar_insert_label' => esc_html__( 'Insert Element', 'shortcode-ui' ),
127
+ 'media_frame_toolbar_update_label' => esc_html__( 'Update', 'shortcode-ui' ),
128
+ 'edit_tab_label' => esc_html__( 'Edit', 'shortcode-ui' ),
129
+ 'preview_tab_label' => esc_html__( 'Preview', 'shortcode-ui' ),
130
+ 'mce_view_error' => esc_html__( 'Failed to load preview', 'shortcode-ui' ),
131
+ 'search_placeholder' => esc_html__( 'Search', 'shortcode-ui' ),
132
+ ),
133
+ 'nonces' => array(
134
+ 'preview' => wp_create_nonce( 'shortcode-ui-preview' ),
135
+ 'thumbnailImage' => wp_create_nonce( 'shortcode-ui-get-thumbnail-image' ),
136
+ )
137
+ ) );
138
+
139
+ // queue templates
140
+ add_action( 'admin_print_footer_scripts', array( $this, 'action_admin_print_footer_scripts' ) );
141
+
142
+ do_action( 'enqueue_shortcode_ui' );
143
+ }
144
+
145
+ /**
146
+ * Default hook to queue shortcake from
147
+ */
148
+ public function action_wp_enqueue_editor() {
149
+ // queue scripts & templates
150
+ $this->enqueue();
151
+
152
+ do_action( 'shortcode_ui_loaded_editor' );
153
+ }
154
+
155
+ /**
156
+ * Output required underscore.js templates
157
+ *
158
+ * @return null
159
+ */
160
+ public function action_admin_print_footer_scripts() {
161
+ echo $this->get_view( 'media-frame' );
162
+ echo $this->get_view( 'list-item' );
163
+ echo $this->get_view( 'edit-form' );
164
+
165
+ do_action( 'print_shortcode_ui_templates' );
166
+ }
167
+
168
+ /**
169
+ * Helper function for displaying a PHP template file.
170
+ * Template args array is extracted and passed to the template file.
171
+ *
172
+ * @param string $template full template file path. Or name of template file in inc/templates.
173
+ * @return string the template contents
174
+ */
175
+ public function get_view( $template ) {
176
+
177
+ if ( ! file_exists( $template ) ) {
178
+
179
+ $template_dir = $this->plugin_dir . 'inc/templates/';
180
+ $template = $template_dir . $template . '.tpl.php';
181
+
182
+ if ( ! file_exists( $template ) ) {
183
+ return '';
184
+ }
185
+
186
+ }
187
+
188
+ ob_start();
189
+ include $template;
190
+
191
+ return ob_get_clean();
192
+ }
193
+
194
+ /**
195
+ * Compare shortcodes by label
196
+ *
197
+ * @param array $a
198
+ * @param array $b
199
+ * @return int
200
+ */
201
+ private function compare_shortcodes_by_label( $a, $b ) {
202
+ return strcmp( $a['label'], $b['label'] );
203
+ }
204
+
205
+ /**
206
+ * Output a shortcode.
207
+ * ajax callback for displaying the shortcode in the TinyMCE editor.
208
+ *
209
+ * @return null
210
+ */
211
+ public function handle_ajax_do_shortcode() {
212
+
213
+ // Don't sanitize shortcodes — can contain HTML kses doesn't allow (e.g. sourcecode shortcode)
214
+ $shortcode = ! empty( $_POST['shortcode'] ) ? stripslashes( $_POST['shortcode'] ) : null;
215
+ $post_id = ! empty( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : null;
216
+
217
+ if ( ! current_user_can( 'edit_post', $post_id ) || ! wp_verify_nonce( $_POST['nonce'], 'shortcode-ui-preview' ) ) {
218
+ echo esc_html__( "Something's rotten in the state of Denmark", 'shortcode-ui' );
219
+ exit;
220
+ }
221
+
222
+ if ( ! empty( $post_id ) ) {
223
+ global $post;
224
+ $post = get_post( $post_id );
225
+ setup_postdata( $post );
226
+ }
227
+
228
+ ob_start();
229
+ do_action( 'shortcode_ui_before_do_shortcode', $shortcode );
230
+ echo do_shortcode( $shortcode );
231
+ do_action( 'shortcode_ui_after_do_shortcode', $shortcode );
232
+
233
+ wp_send_json_success( ob_get_clean() );
234
+
235
+ }
236
+
237
+ }
inc/fields/class-field-attachment.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shortcake_Field_Attachment {
4
+
5
+ private static $instance = null;
6
+
7
+ // All registered post fields.
8
+ private $post_fields = array();
9
+
10
+ // Field Settings.
11
+ private $fields = array(
12
+ 'attachment' => array(
13
+ 'template' => 'fusion-shortcake-field-attachment',
14
+ 'view' => 'editAttributeFieldAttachment',
15
+ ),
16
+ );
17
+
18
+ public static function get_instance() {
19
+ if ( null == self::$instance ) {
20
+ self::$instance = new self;
21
+ self::$instance->setup_actions();
22
+ }
23
+ return self::$instance;
24
+ }
25
+
26
+ private function setup_actions() {
27
+
28
+ add_filter( 'shortcode_ui_fields', array( $this, 'filter_shortcode_ui_fields' ) );
29
+ add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ), 100 );
30
+ add_action( 'shortcode_ui_loaded_editor', array( $this, 'action_shortcode_ui_loaded_editor' ) );
31
+
32
+ }
33
+
34
+ public function filter_shortcode_ui_fields( $fields ) {
35
+ return array_merge( $fields, $this->fields );
36
+ }
37
+
38
+ public function action_admin_enqueue_scripts() {
39
+
40
+ $script = plugins_url( '/js/build/field-attachment.js', dirname( dirname( __FILE__ ) ) );
41
+
42
+ wp_enqueue_script( 'shortcake-field-attachment', $script, array( 'shortcode-ui' ) );
43
+
44
+ wp_localize_script( 'shortcake-field-attachment', 'ShorcakeImageFieldData', array(
45
+ 'defaultArgs' => array(
46
+ 'libraryType' => null, // array of mime types. eg image, image/jpg, application, application/pdf.
47
+ 'addButton' => __( 'Select Attachment', 'shortcode-ui' ),
48
+ 'frameTitle' => __( 'Select Attachment', 'shortcode-ui' ),
49
+ ),
50
+ ) );
51
+ }
52
+
53
+ /**
54
+ * Output templates used by post select field.
55
+ */
56
+ public function action_shortcode_ui_loaded_editor() {
57
+
58
+ ?>
59
+
60
+ <script type="text/html" id="tmpl-fusion-shortcake-field-attachment">
61
+ <div class="field-block">
62
+ <label for="{{ data.attr }}">{{ data.label }}</label>
63
+ <div class="shortcake-attachment-preview attachment-preview attachment">
64
+ <button id="{{ data.attr }}" class="button button-small add">{{ data.addButton }}</button>
65
+ <button class="button button-small remove">&times;</button>
66
+ <span class="loading-indicator spinner"></span>
67
+ </div>
68
+ </div>
69
+ </script>
70
+
71
+ <?php
72
+ }
73
+
74
+ }
inc/fields/class-field-color.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shortcake_Field_Color {
4
+
5
+ private static $instance = null;
6
+
7
+ // All registered post fields.
8
+ private $post_fields = array();
9
+
10
+ // Field Settings.
11
+ private $fields = array(
12
+ 'color' => array(
13
+ 'template' => 'fusion-shortcake-field-color',
14
+ 'view' => 'editAttributeFieldColor',
15
+ ),
16
+ );
17
+
18
+ public static function get_instance() {
19
+ if ( null == self::$instance ) {
20
+ self::$instance = new self;
21
+ self::$instance->setup_actions();
22
+ }
23
+ return self::$instance;
24
+ }
25
+
26
+ private function setup_actions() {
27
+
28
+ add_filter( 'shortcode_ui_fields', array( $this, 'filter_shortcode_ui_fields' ) );
29
+ add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ), 100 );
30
+ add_action( 'shortcode_ui_loaded_editor', array( $this, 'load_template' ) );
31
+
32
+ }
33
+
34
+ private function color_attribute_present() {
35
+
36
+ foreach( Shortcode_UI::get_instance()->get_shortcodes() as $shortcode ) {
37
+ if ( empty( $shortcode['attrs'] ) ) {
38
+ continue;
39
+ }
40
+
41
+ foreach ( $shortcode['attrs'] as $attribute ) {
42
+ if ( empty( $attribute['type'] ) ) {
43
+ continue;
44
+ }
45
+
46
+ if ( $attribute['type'] == 'color' ) {
47
+ return true;
48
+ }
49
+ }
50
+ }
51
+
52
+ return false;
53
+
54
+ }
55
+
56
+ public function filter_shortcode_ui_fields( $fields ) {
57
+ return array_merge( $fields, $this->fields );
58
+ }
59
+
60
+ public function action_admin_enqueue_scripts() {
61
+
62
+ if ( ! $this->color_attribute_present() ) {
63
+ return;
64
+ }
65
+
66
+ $script = plugins_url( '/js/build/field-color.js', dirname( dirname( __FILE__ ) ) );
67
+
68
+ wp_enqueue_script( 'shortcake-field-color', $script, array( 'shortcode-ui' ) );
69
+
70
+ }
71
+
72
+ /**
73
+ * Output templates used by the color field.
74
+ */
75
+ public function load_template() {
76
+
77
+ if ( ! $this->color_attribute_present() ) {
78
+ return;
79
+ }
80
+
81
+ wp_enqueue_script( 'wp-color-picker' );
82
+ wp_enqueue_style( 'wp-color-picker' );
83
+
84
+ ?>
85
+
86
+ <script type="text/html" id="tmpl-fusion-shortcake-field-color">
87
+ <div class="field-block">
88
+ <label for="{{ data.attr }}">{{ data.label }}</label>
89
+ <input type="text" name="{{ data.attr }}" id="{{ data.attr }}" value="{{ data.value }}" placeholder="{{ data.placeholder }}" data-default-color="{{ data.value }}"/>
90
+ <# if ( typeof data.description == 'string' ) { #>
91
+ <p class="description">{{ data.description }}</p>
92
+ <# } #>
93
+ </div>
94
+ </script>
95
+
96
+ <?php
97
+ }
98
+
99
+ }
inc/fields/class-shortcode-ui-fields.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shortcode_UI_Fields {
4
+
5
+ private static $instance = null;
6
+
7
+ // Default Field Settings.
8
+ private $field_defaults = array(
9
+ 'template' => 'shortcode-ui-field-text',
10
+ 'view' => 'editAttributeField',
11
+ );
12
+
13
+ // Field Settings.
14
+ private $fields = array(
15
+ 'text' => array(),
16
+ 'textarea' => array(
17
+ 'template' => 'shortcode-ui-field-textarea',
18
+ ),
19
+ 'url' => array(
20
+ 'template' => 'shortcode-ui-field-url',
21
+ ),
22
+ 'select' => array(
23
+ 'template' => 'shortcode-ui-field-select',
24
+ ),
25
+ 'checkbox' => array(
26
+ 'template' => 'shortcode-ui-field-checkbox',
27
+ ),
28
+ 'radio' => array(
29
+ 'template' => 'shortcode-ui-field-radio',
30
+ ),
31
+ 'email' => array(
32
+ 'template' => 'shortcode-ui-field-email',
33
+ ),
34
+ 'number' => array(
35
+ 'template' => 'shortcode-ui-field-number',
36
+ ),
37
+ 'date' => array(
38
+ 'template' => 'shortcode-ui-field-date',
39
+ ),
40
+ );
41
+
42
+ public static function get_instance() {
43
+ if ( null == self::$instance ) {
44
+ self::$instance = new self;
45
+ self::$instance->setup_actions();
46
+ }
47
+ return self::$instance;
48
+ }
49
+
50
+ private function setup_actions() {
51
+ add_action( 'init', array( $this, 'action_init' ) );
52
+ add_action( 'enqueue_shortcode_ui', array( $this, 'action_enqueue_shortcode_ui' ), 100 );
53
+ }
54
+
55
+ /**
56
+ * Init.
57
+ * @return null
58
+ */
59
+ public function action_init() {
60
+
61
+ /**
62
+ * Filter the available fields.
63
+ * @var array
64
+ */
65
+ $this->fields = apply_filters( 'shortcode_ui_fields', $this->fields );
66
+
67
+ // set default args for each field.
68
+ $field_defaults = $this->field_defaults;
69
+ $this->fields = array_map( function( $args ) use ( $field_defaults ) {
70
+ return wp_parse_args( $args, $field_defaults );
71
+ }, $this->fields );
72
+
73
+ }
74
+
75
+ public function action_enqueue_shortcode_ui() {
76
+
77
+ wp_localize_script( 'shortcode-ui', 'shortcodeUIFieldData', $this->fields );
78
+
79
+ }
80
+
81
+ }
inc/templates/edit-form.tpl.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/html" id="tmpl-shortcode-default-edit-form">
2
+ <form class="edit-shortcode-form">
3
+ <p><a href="#" class="edit-shortcode-form-cancel">&#8592; <?php esc_html_e( 'Back to list', 'shortcode-ui' ); ?></a></p>
4
+
5
+ <div class="edit-shortcode-form-fields"></div>
6
+ </form>
7
+ </script>
8
+
9
+ <script type="text/html" id="tmpl-tabbed-view-base">
10
+ <div class="{{{ data.styles.group }}}" data-role="tab-group">
11
+ <# _.each( data.tabs, function( tab, key ) { #>
12
+ <a href="#" class="{{{ data.styles.tab }}}" data-role="tab" data-target="{{ key }}">{{ tab.label }}</a>
13
+ <# }); #>
14
+ </div>
15
+ <div class="edit-shortcode-tabs-content" data-role="tab-content"></div>
16
+ </script>
17
+
18
+ <script type="text/html" id="tmpl-shortcode-ui-field-text">
19
+ <div class="field-block">
20
+ <label for="{{ data.attr }}">{{ data.label }}</label>
21
+ <input type="text" name="{{ data.attr }}" id="{{ data.attr }}" value="{{ data.value }}" placeholder="{{ data.placeholder }}"/>
22
+ <# if ( typeof data.description == 'string' ) { #>
23
+ <p class="description">{{ data.description }}</p>
24
+ <# } #>
25
+ </div>
26
+ </script>
27
+
28
+ <script type="text/html" id="tmpl-shortcode-ui-field-url">
29
+ <div class="field-block">
30
+ <label for="{{ data.attr }}">{{ data.label }}</label>
31
+ <input type="url" name="{{ data.attr }}" id="{{ data.attr }}" value="{{ data.value }}" class="code" placeholder="{{ data.placeholder }}"/>
32
+ <# if ( typeof data.description == 'string' ) { #>
33
+ <p class="description">{{ data.description }}</p>
34
+ <# } #>
35
+ </div>
36
+ </script>
37
+
38
+ <script type="text/html" id="tmpl-shortcode-ui-field-textarea">
39
+ <div class="field-block">
40
+ <label for="{{ data.attr }}">{{ data.label }}</label>
41
+ <textarea name="{{ data.attr }}" id="{{ data.attr }}" placeholder="{{ data.placeholder }}">{{ data.value }}</textarea>
42
+ <# if ( typeof data.description == 'string' ) { #>
43
+ <p class="description">{{ data.description }}</p>
44
+ <# } #>
45
+ </div>
46
+ </script>
47
+
48
+ <script type="text/html" id="tmpl-shortcode-ui-field-select">
49
+ <div class="field-block">
50
+ <label for="{{ data.attr }}">{{ data.label }}</label>
51
+ <select name="{{ data.attr }}" id="{{ data.attr }}">
52
+ <# _.each( data.options, function( label, value ) { #>
53
+ <option value="{{ value }}" <# if ( value == data.value ){ print('selected'); } #>>{{ label }}</option>
54
+ <# }); #>
55
+ </select>
56
+ <# if ( typeof data.description == 'string' ) { #>
57
+ <p class="description">{{ data.description }}</p>
58
+ <# } #>
59
+ </div>
60
+ </script>
61
+
62
+ <script type="text/html" id="tmpl-shortcode-ui-field-radio">
63
+ <div class="field-block">
64
+ <label for="{{ data.attr }}">{{ data.label }}</label>
65
+ <# _.each( data.options, function( label, value ) { #>
66
+ <input type="radio" name="{{ data.attr }}" value="{{ value }}" <# if ( value == data.value ){ print('checked'); } #>>{{ label }}<br />
67
+ <# }); #>
68
+ <# if ( typeof data.description == 'string' ) { #>
69
+ <p class="description">{{ data.description }}</p>
70
+ <# } #>
71
+ </div>
72
+ </script>
73
+
74
+ <script type="text/html" id="tmpl-shortcode-ui-field-checkbox">
75
+ <div class="field-block">
76
+ <label for="{{ data.attr }}">
77
+ <input type="checkbox" name="{{ data.attr }}" id="{{ data.attr }}" value="{{ data.value }}" <# if ( 'true' == data.value ){ print('checked'); } #>>
78
+ {{ data.label }}
79
+ </label>
80
+ <# if ( typeof data.description == 'string' ) { #>
81
+ <p class="description">{{ data.description }}</p>
82
+ <# } #>
83
+ </div>
84
+ </script>
85
+
86
+ <script type="text/html" id="tmpl-shortcode-ui-field-email">
87
+ <div class="field-block">
88
+ <label for="{{ data.attr }}">{{ data.label }}</label>
89
+ <input type="email" name="{{ data.attr }}" id="{{ data.attr }}" value="{{ data.value}}" placeholder="{{ data.placeholder }}"/>
90
+ <# if ( typeof data.description == 'string' ) { #>
91
+ <p class="description">{{ data.description }}</p>
92
+ <# } #>
93
+ </div>
94
+ </script>
95
+
96
+ <script type="text/html" id="tmpl-shortcode-ui-field-number">
97
+ <div class="field-block">
98
+ <label for="{{ data.attr }}">{{ data.label }}</label>
99
+ <input type="number" name="{{ data.attr }}" id="{{ data.attr }}" value="{{ data.value}}" placeholder="{{ data.placeholder }}"/>
100
+ <# if ( typeof data.description == 'string' ) { #>
101
+ <p class="description">{{ data.description }}</p>
102
+ <# } #>
103
+ </div>
104
+ </script>
105
+
106
+ <script type="text/html" id="tmpl-shortcode-ui-field-hidden">
107
+ <div class="field-block">
108
+ <label for="{{ data.attr }}">{{ data.label }}</label>
109
+ <input type="hidden" name="{{ data.attr }}" id="{{ data.attr }}" value="true" />
110
+ <# if ( typeof data.description == 'string' ) { #>
111
+ <p class="description">{{ data.description }}</p>
112
+ <# } #>
113
+ </div>
114
+ </script>
115
+
116
+ <script type="text/html" id="tmpl-shortcode-ui-field-date">
117
+ <div class="field-block">
118
+ <label for="{{ data.attr }}">{{ data.label }}</label>
119
+ <input type="date" name="{{ data.attr }}" id="{{ data.attr }}" value="{{ data.value }}" placeholder="{{ data.placeholder }}"/>
120
+ <# if ( typeof data.description == 'string' ) { #>
121
+ <p class="description">{{ data.description }}</p>
122
+ <# } #>
123
+ </div>
124
+ </script>
125
+
126
+ <script type="text/html" id="tmpl-shortcode-ui-content">
127
+ <div class="field-block">
128
+ <label for="inner_content">{{ data.label }}</label>
129
+ <textarea id="inner_content" name="inner_content" class="content-edit">{{ data.value }}</textarea>
130
+ <# if ( typeof data.description == 'string' ) { #>
131
+ <p class="description">{{ data.description }}</p>
132
+ <# } #>
133
+ </div>
134
+ </script>
inc/templates/list-item.tpl.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/html" id="tmpl-add-shortcode-list">
2
+
3
+ <ul class="add-shortcode-list"></ul>
4
+
5
+ </script>
6
+
7
+ <script type="text/html" id="tmpl-add-shortcode-list-item">
8
+
9
+ <div class="add-shortcode-list-item-icon">{{{ data.listItemImage }}}</div>
10
+
11
+ <h4 class="add-shortcode-list-item-title">{{ data.label }}</h4>
12
+
13
+ </script>
inc/templates/media-frame.tpl.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/html" id="tmpl-shortcode-ui-media-frame">
2
+
3
+ <div class="media-frame-title" style="left: 0;">
4
+ <h1>{{ data.media_frame_title }}</h1>
5
+ </div>
6
+
7
+ <div class="media-frame-content" style="left: 0;">
8
+ </div>
9
+
10
+ <div class="media-frame-toolbar" style="left: 0;">
11
+
12
+ <div class="media-frame-uploader"></div>
13
+
14
+ </script>
js/build/field-attachment.js ADDED
@@ -0,0 +1,385 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+ (function (global){
3
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
4
+ var ShortcodeAttribute = require('./../models/shortcode-attribute.js');
5
+
6
+ /**
7
+ * Shortcode Attributes collection.
8
+ */
9
+ var ShortcodeAttributes = Backbone.Collection.extend({
10
+ model : ShortcodeAttribute,
11
+ // Deep Clone.
12
+ clone : function() {
13
+ return new this.constructor(_.map(this.models, function(m) {
14
+ return m.clone();
15
+ }));
16
+ }
17
+ });
18
+
19
+ module.exports = ShortcodeAttributes;
20
+
21
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
22
+ },{"./../models/shortcode-attribute.js":5}],2:[function(require,module,exports){
23
+ (function (global){
24
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
25
+ var Shortcode = require('./../models/shortcode.js');
26
+
27
+ // Shortcode Collection
28
+ var Shortcodes = Backbone.Collection.extend({
29
+ model : Shortcode
30
+ });
31
+
32
+ module.exports = Shortcodes;
33
+
34
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
35
+ },{"./../models/shortcode.js":6}],3:[function(require,module,exports){
36
+ (function (global){
37
+ var sui = require('./utils/sui.js'),
38
+ editAttributeField = require('./views/edit-attribute-field.js'),
39
+ $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
40
+
41
+ // Cache attachment IDs for quicker loading.
42
+ var iDCache = {};
43
+
44
+ sui.views.editAttributeFieldAttachment = editAttributeField.extend( {
45
+
46
+ render: function() {
47
+
48
+ var model = this.model;
49
+
50
+ // Set model default values.
51
+ for ( var arg in ShorcakeImageFieldData.defaultArgs ) {
52
+ if ( ! model.get( arg ) ) {
53
+ model.set( arg, ShorcakeImageFieldData.defaultArgs[ arg ] );
54
+ }
55
+ }
56
+
57
+ this.$el.html( this.template( model.toJSON() ) );
58
+
59
+ var $container = this.$el.find( '.shortcake-attachment-preview' );
60
+ var $addButton = $container.find( 'button.add' );
61
+ var $removeButton = $container.find( 'button.remove' );
62
+
63
+ var frame = wp.media( {
64
+ multiple: false,
65
+ title: model.get( 'frameTitle' ),
66
+ library: {
67
+ type: model.get( 'libraryType' ),
68
+ },
69
+ } );
70
+
71
+ /**
72
+ * Update the field attachment.
73
+ * Re-renders UI.
74
+ * If ID is empty - does nothing.
75
+ *
76
+ * @param {int} id Attachment ID
77
+ */
78
+ var updateAttachment = function( id ) {
79
+
80
+ if ( ! id ) {
81
+ return;
82
+ }
83
+
84
+ model.set( 'value', id );
85
+
86
+ if ( iDCache[ id ] ) {
87
+ renderPreview( iDCache[ id ] );
88
+ return;
89
+ }
90
+
91
+ $container.addClass( 'loading' );
92
+
93
+ wp.ajax.post( 'get-attachment', {
94
+ 'id': id
95
+ } ).done( function( attachment ) {
96
+ // Cache for later.
97
+ iDCache[ id ] = attachment;
98
+ renderPreview( attachment );
99
+ $container.removeClass( 'loading' );
100
+ } );
101
+
102
+ }
103
+
104
+ /**
105
+ * Renders attachment preview in field.
106
+ * @param {object} attachment model
107
+ * @return null
108
+ */
109
+ var renderPreview = function( attachment ) {
110
+
111
+ var $thumbnail = $('<div class="thumbnail"></div>');
112
+
113
+ if ( 'image' !== attachment.type ) {
114
+
115
+ $( '<img/>', {
116
+ src: attachment.icon,
117
+ alt: attachment.title,
118
+ } ).appendTo( $thumbnail );
119
+
120
+ $( '<div/>', {
121
+ class: 'filename',
122
+ html: '<div>' + attachment.title + '</div>',
123
+ } ).appendTo( $thumbnail );
124
+
125
+ } else {
126
+
127
+ $( '<img/>', {
128
+ src: attachment.sizes.thumbnail.url,
129
+ width: attachment.sizes.thumbnail.width,
130
+ height: attachment.sizes.thumbnail.height,
131
+ alt: attachment.alt,
132
+ } ) .appendTo( $thumbnail )
133
+
134
+ }
135
+
136
+ $thumbnail.find( 'img' ).wrap( '<div class="centered"></div>' );
137
+ $container.append( $thumbnail );
138
+ $container.toggleClass( 'has-attachment', true );
139
+
140
+ }
141
+
142
+ /**
143
+ * Remove the attachment.
144
+ * Render preview & Update the model.
145
+ */
146
+ var removeAttachment = function() {
147
+
148
+ model.set( 'value', null );
149
+
150
+ $container.toggleClass( 'has-attachment', false );
151
+ $container.toggleClass( 'has-attachment', false );
152
+ $container.find( '.thumbnail' ).remove();
153
+ }
154
+
155
+ // Add initial Attachment if available.
156
+ updateAttachment( model.get( 'value' ) );
157
+
158
+ // Remove file when the button is clicked.
159
+ $removeButton.click( function(e) {
160
+ e.preventDefault();
161
+ removeAttachment();
162
+ });
163
+
164
+ // Open media frame when add button is clicked
165
+ $addButton.click( function(e) {
166
+ e.preventDefault();
167
+ frame.open();
168
+ } );
169
+
170
+ // Update the attachment when an item is selected.
171
+ frame.on( 'select', function() {
172
+
173
+ var selection = frame.state().get('selection');
174
+ attachment = selection.first();
175
+
176
+ updateAttachment( attachment.id );
177
+
178
+ frame.close();
179
+
180
+ });
181
+
182
+ }
183
+
184
+ } );
185
+
186
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
187
+ },{"./utils/sui.js":7,"./views/edit-attribute-field.js":8}],4:[function(require,module,exports){
188
+ (function (global){
189
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
190
+
191
+ /**
192
+ * Shortcode Attribute Model.
193
+ */
194
+ var InnerContent = Backbone.Model.extend({
195
+ defaults : false,
196
+ });
197
+
198
+ module.exports = InnerContent;
199
+
200
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
201
+ },{}],5:[function(require,module,exports){
202
+ (function (global){
203
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
204
+
205
+ var ShortcodeAttribute = Backbone.Model.extend({
206
+ defaults: {
207
+ attr: '',
208
+ label: '',
209
+ type: '',
210
+ value: '',
211
+ placeholder: '',
212
+ },
213
+ });
214
+
215
+ module.exports = ShortcodeAttribute;
216
+
217
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
218
+ },{}],6:[function(require,module,exports){
219
+ (function (global){
220
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
221
+ var ShortcodeAttributes = require('./../collections/shortcode-attributes.js');
222
+ var InnerContent = require('./inner-content.js');
223
+
224
+ Shortcode = Backbone.Model.extend({
225
+
226
+ defaults: {
227
+ label: '',
228
+ shortcode_tag: '',
229
+ attrs: new ShortcodeAttributes,
230
+ inner_content: new InnerContent,
231
+ },
232
+
233
+ /**
234
+ * Custom set method.
235
+ * Handles setting the attribute collection.
236
+ */
237
+ set: function( attributes, options ) {
238
+
239
+ if ( attributes.attrs !== undefined && ! ( attributes.attrs instanceof ShortcodeAttributes ) ) {
240
+ attributes.attrs = new ShortcodeAttributes( attributes.attrs );
241
+ }
242
+
243
+ if ( attributes.inner_content !== undefined && ! ( attributes.inner_content instanceof InnerContent ) ) {
244
+ attributes.inner_content = new InnerContent( attributes.inner_content );
245
+ }
246
+
247
+ return Backbone.Model.prototype.set.call(this, attributes, options);
248
+ },
249
+
250
+ /**
251
+ * Custom toJSON.
252
+ * Handles converting the attribute collection to JSON.
253
+ */
254
+ toJSON: function( options ) {
255
+ options = Backbone.Model.prototype.toJSON.call(this, options);
256
+ if ( options.attrs !== undefined && ( options.attrs instanceof ShortcodeAttributes ) ) {
257
+ options.attrs = options.attrs.toJSON();
258
+ }
259
+ if ( options.inner_content !== undefined && ( options.inner_content instanceof InnerContent ) ) {
260
+ options.inner_content = options.inner_content.toJSON();
261
+ }
262
+ return options;
263
+ },
264
+
265
+ /**
266
+ * Custom clone
267
+ * Make sure we don't clone a reference to attributes.
268
+ */
269
+ clone: function() {
270
+ var clone = Backbone.Model.prototype.clone.call( this );
271
+ clone.set( 'attrs', clone.get( 'attrs' ).clone() );
272
+ clone.set( 'inner_content', clone.get( 'inner_content' ).clone() );
273
+ return clone;
274
+ },
275
+
276
+ /**
277
+ * Get the shortcode as... a shortcode!
278
+ *
279
+ * @return string eg [shortcode attr1=value]
280
+ */
281
+ formatShortcode: function() {
282
+
283
+ var template, shortcodeAttributes, attrs = [], content, self = this;
284
+
285
+ this.get( 'attrs' ).each( function( attr ) {
286
+
287
+ // Skip empty attributes.
288
+ if ( ! attr.get( 'value' ) || attr.get( 'value' ).length < 1 ) {
289
+ return;
290
+ }
291
+
292
+ attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' );
293
+
294
+ } );
295
+
296
+ if ( 'undefined' !== typeof this.get( 'inner_content' ).get( 'value' ) && this.get( 'inner_content' ).get( 'value').length > 0 ) {
297
+ content = this.get( 'inner_content' ).get( 'value' );
298
+ }
299
+
300
+ template = "[{{ shortcode }} {{ attributes }}]"
301
+
302
+ if ( content && content.length > 0 ) {
303
+ template += "{{ content }}[/{{ shortcode }}]"
304
+ }
305
+
306
+ template = template.replace( /{{ shortcode }}/g, this.get('shortcode_tag') );
307
+ template = template.replace( /{{ attributes }}/g, attrs.join( ' ' ) );
308
+ template = template.replace( /{{ content }}/g, content );
309
+
310
+ return template;
311
+
312
+ }
313
+
314
+ });
315
+
316
+ module.exports = Shortcode;
317
+
318
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
319
+ },{"./../collections/shortcode-attributes.js":1,"./inner-content.js":4}],7:[function(require,module,exports){
320
+ var Shortcodes = require('./../collections/shortcodes.js');
321
+
322
+ window.Shortcode_UI = window.Shortcode_UI || {
323
+ shortcodes: new Shortcodes,
324
+ views: {},
325
+ controllers: {},
326
+ };
327
+
328
+ module.exports = window.Shortcode_UI;
329
+
330
+ },{"./../collections/shortcodes.js":2}],8:[function(require,module,exports){
331
+ (function (global){
332
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
333
+ sui = require('./../utils/sui.js');
334
+
335
+ var editAttributeField = Backbone.View.extend( {
336
+
337
+ tagName: "div",
338
+
339
+ events: {
340
+ 'keyup input[type="text"]': 'updateValue',
341
+ 'keyup textarea': 'updateValue',
342
+ 'change select': 'updateValue',
343
+ 'change input[type=checkbox]': 'updateValue',
344
+ 'change input[type=radio]': 'updateValue',
345
+ 'change input[type=email]': 'updateValue',
346
+ 'change input[type=number]': 'updateValue',
347
+ 'change input[type=date]': 'updateValue',
348
+ 'change input[type=url]': 'updateValue',
349
+ },
350
+
351
+ render: function() {
352
+ this.$el.html( this.template( this.model.toJSON() ) );
353
+ return this
354
+ },
355
+
356
+ /**
357
+ * Input Changed Update Callback.
358
+ *
359
+ * If the input field that has changed is for content or a valid attribute,
360
+ * then it should update the model.
361
+ */
362
+ updateValue: function( e ) {
363
+
364
+ if ( this.model.get( 'attr' ) ) {
365
+ var $el = $( this.el ).find( '[name=' + this.model.get( 'attr' ) + ']' );
366
+ } else {
367
+ var $el = $( this.el ).find( '[name="inner_content"]' );
368
+ }
369
+
370
+ if ( 'radio' === this.model.attributes.type ) {
371
+ this.model.set( 'value', $el.filter(':checked').first().val() );
372
+ } else if ( 'checkbox' === this.model.attributes.type ) {
373
+ this.model.set( 'value', $el.is( ':checked' ) );
374
+ } else {
375
+ this.model.set( 'value', $el.val() );
376
+ }
377
+ },
378
+
379
+ } );
380
+
381
+ sui.views.editAttributeField = editAttributeField;
382
+ module.exports = editAttributeField;
383
+
384
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
385
+ },{"./../utils/sui.js":7}]},{},[3]);
js/build/field-color.js ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+ (function (global){
3
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
4
+ var ShortcodeAttribute = require('./../models/shortcode-attribute.js');
5
+
6
+ /**
7
+ * Shortcode Attributes collection.
8
+ */
9
+ var ShortcodeAttributes = Backbone.Collection.extend({
10
+ model : ShortcodeAttribute,
11
+ // Deep Clone.
12
+ clone : function() {
13
+ return new this.constructor(_.map(this.models, function(m) {
14
+ return m.clone();
15
+ }));
16
+ }
17
+ });
18
+
19
+ module.exports = ShortcodeAttributes;
20
+
21
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
22
+ },{"./../models/shortcode-attribute.js":5}],2:[function(require,module,exports){
23
+ (function (global){
24
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
25
+ var Shortcode = require('./../models/shortcode.js');
26
+
27
+ // Shortcode Collection
28
+ var Shortcodes = Backbone.Collection.extend({
29
+ model : Shortcode
30
+ });
31
+
32
+ module.exports = Shortcodes;
33
+
34
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
35
+ },{"./../models/shortcode.js":6}],3:[function(require,module,exports){
36
+ (function (global){
37
+ var sui = require('./utils/sui.js'),
38
+ editAttributeField = require('./views/edit-attribute-field.js'),
39
+ $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
40
+
41
+ sui.views.editAttributeFieldColor = editAttributeField.extend( {
42
+
43
+ render: function() {
44
+ this.$el.html( this.template( this.model.toJSON() ) );
45
+
46
+ this.$el.find('input[type="text"]:not(.wp-color-picker)').wpColorPicker({
47
+ change: function() {
48
+ jQuery(this).trigger('keyup');
49
+ }
50
+ });
51
+
52
+ return this;
53
+ }
54
+
55
+ } );
56
+
57
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
58
+ },{"./utils/sui.js":7,"./views/edit-attribute-field.js":8}],4:[function(require,module,exports){
59
+ (function (global){
60
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
61
+
62
+ /**
63
+ * Shortcode Attribute Model.
64
+ */
65
+ var InnerContent = Backbone.Model.extend({
66
+ defaults : false,
67
+ });
68
+
69
+ module.exports = InnerContent;
70
+
71
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
72
+ },{}],5:[function(require,module,exports){
73
+ (function (global){
74
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
75
+
76
+ var ShortcodeAttribute = Backbone.Model.extend({
77
+ defaults: {
78
+ attr: '',
79
+ label: '',
80
+ type: '',
81
+ value: '',
82
+ placeholder: '',
83
+ },
84
+ });
85
+
86
+ module.exports = ShortcodeAttribute;
87
+
88
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
89
+ },{}],6:[function(require,module,exports){
90
+ (function (global){
91
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
92
+ var ShortcodeAttributes = require('./../collections/shortcode-attributes.js');
93
+ var InnerContent = require('./inner-content.js');
94
+
95
+ Shortcode = Backbone.Model.extend({
96
+
97
+ defaults: {
98
+ label: '',
99
+ shortcode_tag: '',
100
+ attrs: new ShortcodeAttributes,
101
+ inner_content: new InnerContent,
102
+ },
103
+
104
+ /**
105
+ * Custom set method.
106
+ * Handles setting the attribute collection.
107
+ */
108
+ set: function( attributes, options ) {
109
+
110
+ if ( attributes.attrs !== undefined && ! ( attributes.attrs instanceof ShortcodeAttributes ) ) {
111
+ attributes.attrs = new ShortcodeAttributes( attributes.attrs );
112
+ }
113
+
114
+ if ( attributes.inner_content !== undefined && ! ( attributes.inner_content instanceof InnerContent ) ) {
115
+ attributes.inner_content = new InnerContent( attributes.inner_content );
116
+ }
117
+
118
+ return Backbone.Model.prototype.set.call(this, attributes, options);
119
+ },
120
+
121
+ /**
122
+ * Custom toJSON.
123
+ * Handles converting the attribute collection to JSON.
124
+ */
125
+ toJSON: function( options ) {
126
+ options = Backbone.Model.prototype.toJSON.call(this, options);
127
+ if ( options.attrs !== undefined && ( options.attrs instanceof ShortcodeAttributes ) ) {
128
+ options.attrs = options.attrs.toJSON();
129
+ }
130
+ if ( options.inner_content !== undefined && ( options.inner_content instanceof InnerContent ) ) {
131
+ options.inner_content = options.inner_content.toJSON();
132
+ }
133
+ return options;
134
+ },
135
+
136
+ /**
137
+ * Custom clone
138
+ * Make sure we don't clone a reference to attributes.
139
+ */
140
+ clone: function() {
141
+ var clone = Backbone.Model.prototype.clone.call( this );
142
+ clone.set( 'attrs', clone.get( 'attrs' ).clone() );
143
+ clone.set( 'inner_content', clone.get( 'inner_content' ).clone() );
144
+ return clone;
145
+ },
146
+
147
+ /**
148
+ * Get the shortcode as... a shortcode!
149
+ *
150
+ * @return string eg [shortcode attr1=value]
151
+ */
152
+ formatShortcode: function() {
153
+
154
+ var template, shortcodeAttributes, attrs = [], content, self = this;
155
+
156
+ this.get( 'attrs' ).each( function( attr ) {
157
+
158
+ // Skip empty attributes.
159
+ if ( ! attr.get( 'value' ) || attr.get( 'value' ).length < 1 ) {
160
+ return;
161
+ }
162
+
163
+ attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' );
164
+
165
+ } );
166
+
167
+ if ( 'undefined' !== typeof this.get( 'inner_content' ).get( 'value' ) && this.get( 'inner_content' ).get( 'value').length > 0 ) {
168
+ content = this.get( 'inner_content' ).get( 'value' );
169
+ }
170
+
171
+ template = "[{{ shortcode }} {{ attributes }}]"
172
+
173
+ if ( content && content.length > 0 ) {
174
+ template += "{{ content }}[/{{ shortcode }}]"
175
+ }
176
+
177
+ template = template.replace( /{{ shortcode }}/g, this.get('shortcode_tag') );
178
+ template = template.replace( /{{ attributes }}/g, attrs.join( ' ' ) );
179
+ template = template.replace( /{{ content }}/g, content );
180
+
181
+ return template;
182
+
183
+ }
184
+
185
+ });
186
+
187
+ module.exports = Shortcode;
188
+
189
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
190
+ },{"./../collections/shortcode-attributes.js":1,"./inner-content.js":4}],7:[function(require,module,exports){
191
+ var Shortcodes = require('./../collections/shortcodes.js');
192
+
193
+ window.Shortcode_UI = window.Shortcode_UI || {
194
+ shortcodes: new Shortcodes,
195
+ views: {},
196
+ controllers: {},
197
+ };
198
+
199
+ module.exports = window.Shortcode_UI;
200
+
201
+ },{"./../collections/shortcodes.js":2}],8:[function(require,module,exports){
202
+ (function (global){
203
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
204
+ sui = require('./../utils/sui.js');
205
+
206
+ var editAttributeField = Backbone.View.extend( {
207
+
208
+ tagName: "div",
209
+
210
+ events: {
211
+ 'keyup input[type="text"]': 'updateValue',
212
+ 'keyup textarea': 'updateValue',
213
+ 'change select': 'updateValue',
214
+ 'change input[type=checkbox]': 'updateValue',
215
+ 'change input[type=radio]': 'updateValue',
216
+ 'change input[type=email]': 'updateValue',
217
+ 'change input[type=number]': 'updateValue',
218
+ 'change input[type=date]': 'updateValue',
219
+ 'change input[type=url]': 'updateValue',
220
+ },
221
+
222
+ render: function() {
223
+ this.$el.html( this.template( this.model.toJSON() ) );
224
+ return this
225
+ },
226
+
227
+ /**
228
+ * Input Changed Update Callback.
229
+ *
230
+ * If the input field that has changed is for content or a valid attribute,
231
+ * then it should update the model.
232
+ */
233
+ updateValue: function( e ) {
234
+
235
+ if ( this.model.get( 'attr' ) ) {
236
+ var $el = $( this.el ).find( '[name=' + this.model.get( 'attr' ) + ']' );
237
+ } else {
238
+ var $el = $( this.el ).find( '[name="inner_content"]' );
239
+ }
240
+
241
+ if ( 'radio' === this.model.attributes.type ) {
242
+ this.model.set( 'value', $el.filter(':checked').first().val() );
243
+ } else if ( 'checkbox' === this.model.attributes.type ) {
244
+ this.model.set( 'value', $el.is( ':checked' ) );
245
+ } else {
246
+ this.model.set( 'value', $el.val() );
247
+ }
248
+ },
249
+
250
+ } );
251
+
252
+ sui.views.editAttributeField = editAttributeField;
253
+ module.exports = editAttributeField;
254
+
255
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
256
+ },{"./../utils/sui.js":7}]},{},[3]);
js/build/shortcode-ui.js ADDED
@@ -0,0 +1,1393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+ (function (global){
3
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
4
+ var ShortcodeAttribute = require('./../models/shortcode-attribute.js');
5
+
6
+ /**
7
+ * Shortcode Attributes collection.
8
+ */
9
+ var ShortcodeAttributes = Backbone.Collection.extend({
10
+ model : ShortcodeAttribute,
11
+ // Deep Clone.
12
+ clone : function() {
13
+ return new this.constructor(_.map(this.models, function(m) {
14
+ return m.clone();
15
+ }));
16
+ }
17
+ });
18
+
19
+ module.exports = ShortcodeAttributes;
20
+
21
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
22
+ },{"./../models/shortcode-attribute.js":5}],2:[function(require,module,exports){
23
+ (function (global){
24
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
25
+ var Shortcode = require('./../models/shortcode.js');
26
+
27
+ // Shortcode Collection
28
+ var Shortcodes = Backbone.Collection.extend({
29
+ model : Shortcode
30
+ });
31
+
32
+ module.exports = Shortcodes;
33
+
34
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
35
+ },{"./../models/shortcode.js":6}],3:[function(require,module,exports){
36
+ (function (global){
37
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null),
38
+ wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null);
39
+ Shortcodes = require('./../collections/shortcodes.js');
40
+
41
+ var MediaController = wp.media.controller.State.extend({
42
+
43
+ initialize: function(){
44
+
45
+ this.props = new Backbone.Model({
46
+ currentShortcode: null,
47
+ action: 'select',
48
+ search: null
49
+ });
50
+
51
+ this.props.on( 'change:action', this.refresh, this );
52
+
53
+ },
54
+
55
+ refresh: function() {
56
+ if ( this.frame && this.frame.toolbar ) {
57
+ this.frame.toolbar.get().refresh();
58
+ }
59
+ },
60
+
61
+ search: function( searchTerm ) {
62
+ var pattern = new RegExp( searchTerm, "gi" );
63
+ var filteredModels = sui.shortcodes.filter( function( model ) {
64
+ return pattern.test( model.get( "label" ) );
65
+ });
66
+ return filteredModels;
67
+ },
68
+
69
+ insert: function() {
70
+ var shortcode = this.props.get('currentShortcode');
71
+ if ( shortcode ) {
72
+ send_to_editor( shortcode.formatShortcode() );
73
+ this.reset();
74
+ this.frame.close();
75
+ }
76
+ },
77
+
78
+ reset: function() {
79
+ this.props.set( 'action', 'select' );
80
+ this.props.set( 'currentShortcode', null );
81
+ this.props.set( 'search', null );
82
+ },
83
+
84
+ });
85
+
86
+ sui.controllers.MediaController = MediaController;
87
+ module.exports = MediaController;
88
+
89
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
90
+ },{"./../collections/shortcodes.js":2}],4:[function(require,module,exports){
91
+ (function (global){
92
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
93
+
94
+ /**
95
+ * Shortcode Attribute Model.
96
+ */
97
+ var InnerContent = Backbone.Model.extend({
98
+ defaults : false,
99
+ });
100
+
101
+ module.exports = InnerContent;
102
+
103
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
104
+ },{}],5:[function(require,module,exports){
105
+ (function (global){
106
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
107
+
108
+ var ShortcodeAttribute = Backbone.Model.extend({
109
+ defaults: {
110
+ attr: '',
111
+ label: '',
112
+ type: '',
113
+ value: '',
114
+ placeholder: '',
115
+ },
116
+ });
117
+
118
+ module.exports = ShortcodeAttribute;
119
+
120
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
121
+ },{}],6:[function(require,module,exports){
122
+ (function (global){
123
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
124
+ var ShortcodeAttributes = require('./../collections/shortcode-attributes.js');
125
+ var InnerContent = require('./inner-content.js');
126
+
127
+ Shortcode = Backbone.Model.extend({
128
+
129
+ defaults: {
130
+ label: '',
131
+ shortcode_tag: '',
132
+ attrs: new ShortcodeAttributes,
133
+ inner_content: new InnerContent,
134
+ },
135
+
136
+ /**
137
+ * Custom set method.
138
+ * Handles setting the attribute collection.
139
+ */
140
+ set: function( attributes, options ) {
141
+
142
+ if ( attributes.attrs !== undefined && ! ( attributes.attrs instanceof ShortcodeAttributes ) ) {
143
+ attributes.attrs = new ShortcodeAttributes( attributes.attrs );
144
+ }
145
+
146
+ if ( attributes.inner_content !== undefined && ! ( attributes.inner_content instanceof InnerContent ) ) {
147
+ attributes.inner_content = new InnerContent( attributes.inner_content );
148
+ }
149
+
150
+ return Backbone.Model.prototype.set.call(this, attributes, options);
151
+ },
152
+
153
+ /**
154
+ * Custom toJSON.
155
+ * Handles converting the attribute collection to JSON.
156
+ */
157
+ toJSON: function( options ) {
158
+ options = Backbone.Model.prototype.toJSON.call(this, options);
159
+ if ( options.attrs !== undefined && ( options.attrs instanceof ShortcodeAttributes ) ) {
160
+ options.attrs = options.attrs.toJSON();
161
+ }
162
+ if ( options.inner_content !== undefined && ( options.inner_content instanceof InnerContent ) ) {
163
+ options.inner_content = options.inner_content.toJSON();
164
+ }
165
+ return options;
166
+ },
167
+
168
+ /**
169
+ * Custom clone
170
+ * Make sure we don't clone a reference to attributes.
171
+ */
172
+ clone: function() {
173
+ var clone = Backbone.Model.prototype.clone.call( this );
174
+ clone.set( 'attrs', clone.get( 'attrs' ).clone() );
175
+ clone.set( 'inner_content', clone.get( 'inner_content' ).clone() );
176
+ return clone;
177
+ },
178
+
179
+ /**
180
+ * Get the shortcode as... a shortcode!
181
+ *
182
+ * @return string eg [shortcode attr1=value]
183
+ */
184
+ formatShortcode: function() {
185
+
186
+ var template, shortcodeAttributes, attrs = [], content, self = this;
187
+
188
+ this.get( 'attrs' ).each( function( attr ) {
189
+
190
+ // Skip empty attributes.
191
+ if ( ! attr.get( 'value' ) || attr.get( 'value' ).length < 1 ) {
192
+ return;
193
+ }
194
+
195
+ attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' );
196
+
197
+ } );
198
+
199
+ if ( 'undefined' !== typeof this.get( 'inner_content' ).get( 'value' ) && this.get( 'inner_content' ).get( 'value').length > 0 ) {
200
+ content = this.get( 'inner_content' ).get( 'value' );
201
+ }
202
+
203
+ template = "[{{ shortcode }} {{ attributes }}]"
204
+
205
+ if ( content && content.length > 0 ) {
206
+ template += "{{ content }}[/{{ shortcode }}]"
207
+ }
208
+
209
+ template = template.replace( /{{ shortcode }}/g, this.get('shortcode_tag') );
210
+ template = template.replace( /{{ attributes }}/g, attrs.join( ' ' ) );
211
+ template = template.replace( /{{ content }}/g, content );
212
+
213
+ return template;
214
+
215
+ }
216
+
217
+ });
218
+
219
+ module.exports = Shortcode;
220
+
221
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
222
+ },{"./../collections/shortcode-attributes.js":1,"./inner-content.js":4}],7:[function(require,module,exports){
223
+ (function (global){
224
+ var sui = require('./utils/sui.js'),
225
+ Shortcodes = require('./collections/shortcodes.js'),
226
+ shortcodeViewConstructor = require('./utils/shortcode-view-constructor.js'),
227
+ mediaFrame = require('./views/media-frame.js'),
228
+ wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null),
229
+ $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
230
+
231
+ $(document).ready(function(){
232
+
233
+ // Create collection of shortcode models from data.
234
+ sui.shortcodes.add( shortcodeUIData.shortcodes );
235
+
236
+ wp.media.view.MediaFrame.Post = mediaFrame;
237
+
238
+ // Register a view for each shortcode.
239
+ sui.shortcodes.each( function( shortcode ) {
240
+ if ( wp.mce.views ) {
241
+ wp.mce.views.register(
242
+ shortcode.get('shortcode_tag'),
243
+ // Must extend for 4.1.
244
+ // This is handled by wp.mce.views.register in 4.2.
245
+ $.extend( true, {}, shortcodeViewConstructor )
246
+ );
247
+ }
248
+ } );
249
+
250
+ });
251
+
252
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
253
+ },{"./collections/shortcodes.js":2,"./utils/shortcode-view-constructor.js":8,"./utils/sui.js":9,"./views/media-frame.js":14}],8:[function(require,module,exports){
254
+ (function (global){
255
+ sui = require('./sui.js');
256
+ wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null);
257
+ $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
258
+
259
+ /**
260
+ * Generic shortcode mce view constructor.
261
+ * This is cloned and used by each shortcode when registering a view.
262
+ */
263
+ var shortcodeViewConstructor = {
264
+
265
+ initialize: function( options ) {
266
+ this.shortcodeModel = this.getShortcodeModel( this.shortcode );
267
+ },
268
+
269
+ /**
270
+ * Get the shortcode model given the view shortcode options.
271
+ * Must be a registered shortcode (see sui.shortcodes)
272
+ */
273
+ getShortcodeModel: function( options ) {
274
+
275
+ var shortcodeModel;
276
+
277
+ shortcodeModel = sui.shortcodes.findWhere( { shortcode_tag: options.tag } );
278
+
279
+ if ( ! shortcodeModel ) {
280
+ return;
281
+ }
282
+
283
+ shortcodeModel = shortcodeModel.clone();
284
+
285
+ shortcodeModel.get('attrs').each(
286
+ function( attr ) {
287
+ if ( attr.get('attr') in options.attrs.named ) {
288
+ attr.set(
289
+ 'value',
290
+ options.attrs.named[ attr.get('attr') ]
291
+ );
292
+ }
293
+ }
294
+ );
295
+
296
+ if ('content' in options) {
297
+ var inner_content = shortcodeModel.get('inner_content');
298
+ inner_content.set('value', options.content)
299
+ }
300
+
301
+ return shortcodeModel;
302
+
303
+ },
304
+
305
+ /**
306
+ * Return the preview HTML.
307
+ * If empty, fetches data.
308
+ *
309
+ * @return string
310
+ */
311
+ getContent : function() {
312
+ if ( ! this.content ) {
313
+ this.fetch();
314
+ }
315
+ return this.content;
316
+ },
317
+
318
+ /**
319
+ * Fetch preview.
320
+ * Async. Sets this.content and calls this.render.
321
+ *
322
+ * @return undefined
323
+ */
324
+ fetch : function() {
325
+
326
+ var self = this;
327
+
328
+ if ( ! this.fetching ) {
329
+
330
+ this.fetching = true;
331
+
332
+ wp.ajax.post( 'do_shortcode', {
333
+ post_id: $( '#post_ID' ).val(),
334
+ shortcode: this.shortcodeModel.formatShortcode(),
335
+ nonce: shortcodeUIData.nonces.preview,
336
+ }).done( function( response ) {
337
+ self.content = response;
338
+ }).fail( function() {
339
+ self.content = '<span class="shortcake-error">' + shortcodeUIData.strings.mce_view_error + '</span>';
340
+ } ).always( function() {
341
+ delete self.fetching;
342
+ self.render( true );
343
+ } );
344
+
345
+ }
346
+
347
+ },
348
+
349
+ /**
350
+ * Edit shortcode.
351
+ * Get shortcode model and open edit modal.
352
+ *
353
+ */
354
+ edit : function( shortcodeString ) {
355
+
356
+ var currentShortcode;
357
+
358
+ // Backwards compatability for WP pre-4.2
359
+ if ( 'object' === typeof( shortcodeString ) ) {
360
+ shortcodeString = decodeURIComponent( $(shortcodeString).attr('data-wpview-text') );
361
+ }
362
+
363
+ currentShortcode = this.parseShortcodeString( shortcodeString );
364
+
365
+ if ( currentShortcode ) {
366
+
367
+ var wp_media_frame = wp.media.frames.wp_media_frame = wp.media({
368
+ frame : "post",
369
+ state : 'shortcode-ui',
370
+ currentShortcode : currentShortcode,
371
+ });
372
+
373
+ wp_media_frame.open();
374
+
375
+ }
376
+
377
+ },
378
+
379
+ /**
380
+ * Parse a shortcode string and return shortcode model.
381
+ * Must be a registered shortcode - see window.Shortcode_UI.shortcodes.
382
+ *
383
+ * @todo - I think there must be a cleaner way to get the
384
+ * shortcode & args here that doesn't use regex.
385
+ *
386
+ * @param string shortcodeString
387
+ * @return Shortcode
388
+ */
389
+ parseShortcodeString: function( shortcodeString ) {
390
+
391
+ var model, attr;
392
+
393
+ var megaRegex = /\[([^\s\]]+)([^\]]+)?\]([^\[]*)?(\[\/(\S+?)\])?/;
394
+ var matches = shortcodeString.match( megaRegex );
395
+
396
+ if ( ! matches ) {
397
+ return;
398
+ }
399
+
400
+ defaultShortcode = sui.shortcodes.findWhere({
401
+ shortcode_tag : matches[1]
402
+ });
403
+
404
+ if ( ! defaultShortcode ) {
405
+ return;
406
+ }
407
+
408
+ currentShortcode = defaultShortcode.clone();
409
+
410
+ if ( matches[2] ) {
411
+
412
+ attributeMatches = matches[2].match( /(\S+?=".*?")/g ) || [];
413
+
414
+ // convert attribute strings to object.
415
+ for ( var i = 0; i < attributeMatches.length; i++ ) {
416
+
417
+ var bitsRegEx = /(\S+?)="(.*?)"/g;
418
+ var bits = bitsRegEx.exec( attributeMatches[i] );
419
+
420
+ attr = currentShortcode.get( 'attrs' ).findWhere({
421
+ attr : bits[1]
422
+ });
423
+
424
+ if ( attr ) {
425
+ attr.set('value', bits[2]);
426
+ }
427
+
428
+ }
429
+
430
+ }
431
+
432
+ if ( matches[3] ) {
433
+ var inner_content = currentShortcode.get( 'inner_content' );
434
+ inner_content.set( 'value', matches[3] );
435
+ }
436
+
437
+ return currentShortcode;
438
+
439
+ },
440
+
441
+ // Backwards compatability for Pre WP 4.2.
442
+ View: {
443
+
444
+ overlay: true,
445
+
446
+ initialize: function( options ) {
447
+ this.shortcode = this.getShortcode( options );
448
+ },
449
+
450
+ getShortcode: function( options ) {
451
+
452
+ var shortcodeModel, shortcode;
453
+
454
+ shortcodeModel = sui.shortcodes.findWhere( { shortcode_tag: options.shortcode.tag } );
455
+
456
+ if (!shortcodeModel) {
457
+ return;
458
+ }
459
+
460
+ shortcode = shortcodeModel.clone();
461
+
462
+ shortcode.get('attrs').each(
463
+ function(attr) {
464
+
465
+ if (attr.get('attr') in options.shortcode.attrs.named) {
466
+ attr.set('value',
467
+ options.shortcode.attrs.named[attr
468
+ .get('attr')]);
469
+ }
470
+
471
+ });
472
+
473
+ if ('content' in options.shortcode) {
474
+ var inner_content = shortcode.get('inner_content');
475
+ inner_content.set('value', options.shortcode.content)
476
+ }
477
+
478
+ return shortcode;
479
+
480
+ },
481
+
482
+ fetch : function() {
483
+
484
+ var self = this;
485
+
486
+ if ( ! this.parsed ) {
487
+
488
+ wp.ajax.post( 'do_shortcode', {
489
+ post_id: $( '#post_ID' ).val(),
490
+ shortcode: this.shortcode.formatShortcode(),
491
+ nonce: shortcodeUIData.nonces.preview,
492
+ }).done( function( response ) {
493
+ if ( response.indexOf( '<script' ) !== -1 ) {
494
+ self.setIframes( self.getEditorStyles(), response );
495
+ } else {
496
+ self.parsed = response;
497
+ self.render( true );
498
+ }
499
+ }).fail( function() {
500
+ self.parsed = '<span class="shortcake-error">' + shortcodeUIData.strings.mce_view_error + '</span>';
501
+ self.render( true );
502
+ } );
503
+
504
+ }
505
+
506
+ },
507
+
508
+ /**
509
+ * Render the shortcode
510
+ *
511
+ * To ensure consistent rendering - this makes an ajax request to the
512
+ * admin and displays.
513
+ *
514
+ * @return string html
515
+ */
516
+ getHtml : function() {
517
+
518
+ if ( ! this.parsed ) {
519
+ this.fetch();
520
+ }
521
+
522
+ return this.parsed;
523
+ },
524
+
525
+ /**
526
+ * Returns an array of <link> tags for stylesheets applied to the TinyMCE editor.
527
+ *
528
+ * @method getEditorStyles
529
+ * @returns {Array}
530
+ */
531
+ getEditorStyles: function() {
532
+
533
+ var styles = '';
534
+
535
+ this.getNodes( function ( editor, node, content ) {
536
+ var dom = editor.dom,
537
+ bodyClasses = editor.getBody().className || '',
538
+ iframe, iframeDoc, i, resize;
539
+
540
+ tinymce.each( dom.$( 'link[rel="stylesheet"]', editor.getDoc().head ), function( link ) {
541
+ if ( link.href && link.href.indexOf( 'skins/lightgray/content.min.css' ) === -1 &&
542
+ link.href.indexOf( 'skins/wordpress/wp-content.css' ) === -1 ) {
543
+
544
+ styles += dom.getOuterHTML( link ) + '\n';
545
+ }
546
+
547
+ });
548
+
549
+ } );
550
+
551
+ return styles;
552
+ },
553
+
554
+ },
555
+
556
+ };
557
+
558
+ module.exports = shortcodeViewConstructor;
559
+
560
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
561
+ },{"./sui.js":9}],9:[function(require,module,exports){
562
+ var Shortcodes = require('./../collections/shortcodes.js');
563
+
564
+ window.Shortcode_UI = window.Shortcode_UI || {
565
+ shortcodes: new Shortcodes,
566
+ views: {},
567
+ controllers: {},
568
+ };
569
+
570
+ module.exports = window.Shortcode_UI;
571
+
572
+ },{"./../collections/shortcodes.js":2}],10:[function(require,module,exports){
573
+ (function (global){
574
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
575
+ sui = require('./../utils/sui.js');
576
+
577
+ var editAttributeField = Backbone.View.extend( {
578
+
579
+ tagName: "div",
580
+
581
+ events: {
582
+ 'keyup input[type="text"]': 'updateValue',
583
+ 'keyup textarea': 'updateValue',
584
+ 'change select': 'updateValue',
585
+ 'change input[type=checkbox]': 'updateValue',
586
+ 'change input[type=radio]': 'updateValue',
587
+ 'change input[type=email]': 'updateValue',
588
+ 'change input[type=number]': 'updateValue',
589
+ 'change input[type=date]': 'updateValue',
590
+ 'change input[type=url]': 'updateValue',
591
+ },
592
+
593
+ render: function() {
594
+ this.$el.html( this.template( this.model.toJSON() ) );
595
+ return this
596
+ },
597
+
598
+ /**
599
+ * Input Changed Update Callback.
600
+ *
601
+ * If the input field that has changed is for content or a valid attribute,
602
+ * then it should update the model.
603
+ */
604
+ updateValue: function( e ) {
605
+
606
+ if ( this.model.get( 'attr' ) ) {
607
+ var $el = $( this.el ).find( '[name=' + this.model.get( 'attr' ) + ']' );
608
+ } else {
609
+ var $el = $( this.el ).find( '[name="inner_content"]' );
610
+ }
611
+
612
+ if ( 'radio' === this.model.attributes.type ) {
613
+ this.model.set( 'value', $el.filter(':checked').first().val() );
614
+ } else if ( 'checkbox' === this.model.attributes.type ) {
615
+ this.model.set( 'value', $el.is( ':checked' ) );
616
+ } else {
617
+ this.model.set( 'value', $el.val() );
618
+ }
619
+ },
620
+
621
+ } );
622
+
623
+ sui.views.editAttributeField = editAttributeField;
624
+ module.exports = editAttributeField;
625
+
626
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
627
+ },{"./../utils/sui.js":9}],11:[function(require,module,exports){
628
+ (function (global){
629
+ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null),
630
+ sui = require('./../utils/sui.js'),
631
+ editAttributeField = require('./edit-attribute-field.js');
632
+
633
+ /**
634
+ * Single edit shortcode content view.
635
+ */
636
+ var EditShortcodeForm = wp.Backbone.View.extend({
637
+ template: wp.template('shortcode-default-edit-form'),
638
+
639
+ initialize: function() {
640
+
641
+ var t = this;
642
+
643
+ var innerContent = this.model.get( 'inner_content' );
644
+ if ( typeof innerContent.attributes.type !== 'undefined' ) {
645
+
646
+ // add UI for inner_content
647
+ var view = new editAttributeField( {
648
+ model: innerContent,
649
+ shortcode: t.model,
650
+ } );
651
+
652
+ view.template = wp.media.template( 'shortcode-ui-content' );
653
+ t.views.add( '.edit-shortcode-form-fields', view );
654
+
655
+ }
656
+
657
+ this.model.get( 'attrs' ).each( function( attr ) {
658
+
659
+ // Get the field settings from localization data.
660
+ var type = attr.get('type');
661
+
662
+ if ( ! shortcodeUIFieldData[ type ] ) {
663
+ return;
664
+ }
665
+
666
+ var viewObjName = shortcodeUIFieldData[ type ].view;
667
+ var tmplName = shortcodeUIFieldData[ type ].template;
668
+
669
+ var view = new sui.views[viewObjName]( { model: attr } );
670
+ view.template = wp.media.template( tmplName );
671
+ view.shortcode = t.model;
672
+
673
+ t.views.add( '.edit-shortcode-form-fields', view );
674
+
675
+ } );
676
+
677
+ },
678
+
679
+ });
680
+
681
+ module.exports = EditShortcodeForm;
682
+
683
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
684
+ },{"./../utils/sui.js":9,"./edit-attribute-field.js":10}],12:[function(require,module,exports){
685
+ (function (global){
686
+ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null);
687
+
688
+ /**
689
+ * Single shortcode list item view.
690
+ */
691
+ var insertShortcodeListItem = wp.Backbone.View.extend({
692
+
693
+ tagName : 'li',
694
+ template : wp.template('add-shortcode-list-item'),
695
+ className : 'shortcode-list-item',
696
+
697
+ render : function() {
698
+
699
+ var data = this.model.toJSON();
700
+ this.$el.attr('data-shortcode', data.shortcode_tag);
701
+
702
+ if (('listItemImage' in data)
703
+ && 0 === data.listItemImage.indexOf('dashicons-')) {
704
+ data.listItemImage = '<div class="dashicons ' + data.listItemImage
705
+ + '"></div>';
706
+ }
707
+
708
+ this.$el.html(this.template(data));
709
+
710
+ return this;
711
+
712
+ }
713
+ });
714
+
715
+ module.exports = insertShortcodeListItem;
716
+
717
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
718
+ },{}],13:[function(require,module,exports){
719
+ (function (global){
720
+ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null);
721
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
722
+ var Shortcodes = require('./../collections/shortcodes.js');
723
+ var insertShortcodeListItem = require('./insert-shortcode-list-item.js');
724
+
725
+ var insertShortcodeList = wp.Backbone.View.extend({
726
+
727
+ tagName : 'div',
728
+ template : wp.template('add-shortcode-list'),
729
+
730
+ initialize : function( options ) {
731
+
732
+ this.displayShortcodes( options );
733
+
734
+ },
735
+
736
+ refresh: function( shortcodeData ) {
737
+ if ( shortcodeData instanceof Backbone.Collection ) {
738
+ var options = { shortcodes: shortcodeData };
739
+ } else {
740
+ var options = { shortcodes: new Shortcodes( shortcodeData ) };
741
+ }
742
+ this.displayShortcodes( options );
743
+ },
744
+
745
+ displayShortcodes: function(options) {
746
+ var t = this;
747
+
748
+ t.$el.find('.add-shortcode-list').html('');
749
+ t.options = {};
750
+ t.options.shortcodes = options.shortcodes;
751
+
752
+ t.options.shortcodes.each(function(shortcode) {
753
+ t.views.add('ul', new insertShortcodeListItem({
754
+ model : shortcode
755
+ }));
756
+ });
757
+ }
758
+
759
+ });
760
+
761
+ module.exports = insertShortcodeList;
762
+
763
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
764
+ },{"./../collections/shortcodes.js":2,"./insert-shortcode-list-item.js":12}],14:[function(require,module,exports){
765
+ (function (global){
766
+ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null),
767
+ MediaController = require('./../controllers/media-controller.js'),
768
+ Shortcode_UI = require('./shortcode-ui'),
769
+ Toolbar = require('./media-toolbar');
770
+
771
+ var postMediaFrame = wp.media.view.MediaFrame.Post;
772
+ var mediaFrame = postMediaFrame.extend( {
773
+
774
+ initialize: function() {
775
+
776
+ postMediaFrame.prototype.initialize.apply( this, arguments );
777
+
778
+ var id = 'shortcode-ui';
779
+
780
+ var opts = {
781
+ id : id,
782
+ search : true,
783
+ router : false,
784
+ toolbar : id + '-toolbar',
785
+ menu : 'default',
786
+ title : shortcodeUIData.strings.media_frame_menu_insert_label,
787
+ tabs : [ 'insert' ],
788
+ priority: 66,
789
+ content : id + '-content-insert',
790
+ };
791
+
792
+ if ( 'currentShortcode' in this.options ) {
793
+ opts.title = shortcodeUIData.strings.media_frame_menu_update_label;
794
+ }
795
+
796
+ var controller = new MediaController( opts );
797
+
798
+ if ( 'currentShortcode' in this.options ) {
799
+ controller.props.set( 'currentShortcode', arguments[0].currentShortcode );
800
+ controller.props.set( 'action', 'update' );
801
+ }
802
+
803
+ this.states.add([ controller]);
804
+
805
+ this.on( 'content:render:' + id + '-content-insert', _.bind( this.contentRender, this, 'shortcode-ui', 'insert' ) );
806
+ this.on( 'toolbar:create:' + id + '-toolbar', this.toolbarCreate, this );
807
+ this.on( 'toolbar:render:' + id + '-toolbar', this.toolbarRender, this );
808
+ this.on( 'menu:render:default', this.renderShortcodeUIMenu );
809
+
810
+ },
811
+
812
+ contentRender : function( id, tab ) {
813
+ this.content.set(
814
+ new Shortcode_UI( {
815
+ controller: this,
816
+ className: 'clearfix ' + id + '-content ' + id + '-content-' + tab
817
+ } )
818
+ );
819
+ },
820
+
821
+ toolbarRender: function( toolbar ) {},
822
+
823
+ toolbarCreate : function( toolbar ) {
824
+ var text = shortcodeUIData.strings.media_frame_toolbar_insert_label;
825
+ if ( 'currentShortcode' in this.options ) {
826
+ text = shortcodeUIData.strings.media_frame_toolbar_update_label;
827
+ }
828
+
829
+ toolbar.view = new Toolbar( {
830
+ controller : this,
831
+ items: {
832
+ insert: {
833
+ text: text,
834
+ style: 'primary',
835
+ priority: 80,
836
+ requires: false,
837
+ click: this.insertAction,
838
+ }
839
+ }
840
+ } );
841
+ },
842
+
843
+ renderShortcodeUIMenu: function( view ) {
844
+
845
+ // Add a menu separator link.
846
+ view.set({
847
+ 'shortcode-ui-separator': new wp.media.View({
848
+ className: 'separator',
849
+ priority: 65
850
+ })
851
+ });
852
+
853
+ // Hide menu if editing.
854
+ // @todo - fix this.
855
+ // This is a hack.
856
+ // I just can't work out how to do it properly...
857
+ if (
858
+ view.controller.state().props
859
+ && view.controller.state().props.get( 'currentShortcode' )
860
+ ) {
861
+ window.setTimeout( function() {
862
+ view.controller.$el.addClass( 'hide-menu' );
863
+ } );
864
+ }
865
+
866
+ },
867
+
868
+ insertAction: function() {
869
+ this.controller.state().insert();
870
+ },
871
+
872
+ } );
873
+
874
+ module.exports = mediaFrame;
875
+
876
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
877
+ },{"./../controllers/media-controller.js":3,"./media-toolbar":15,"./shortcode-ui":18}],15:[function(require,module,exports){
878
+ (function (global){
879
+ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null);
880
+
881
+ /**
882
+ * Toolbar view that extends wp.media.view.Toolbar
883
+ * to define cusotm refresh method
884
+ */
885
+ var Toolbar = wp.media.view.Toolbar.extend({
886
+ initialize : function() {
887
+ _.defaults(this.options, {
888
+ requires : false
889
+ });
890
+ // Call 'initialize' directly on the parent class.
891
+ wp.media.view.Toolbar.prototype.initialize.apply(this, arguments);
892
+ },
893
+
894
+ refresh : function() {
895
+ var action = this.controller.state().props.get('action');
896
+ if( this.get('insert') ) {
897
+ this.get('insert').model.set('disabled', action == 'select');
898
+ }
899
+ /**
900
+ * call 'refresh' directly on the parent class
901
+ */
902
+ wp.media.view.Toolbar.prototype.refresh.apply(this, arguments);
903
+ }
904
+ });
905
+
906
+ module.exports = Toolbar;
907
+
908
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
909
+ },{}],16:[function(require,module,exports){
910
+ (function (global){
911
+ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null);
912
+ sui = require('./../utils/sui.js');
913
+
914
+ var SearchShortcode = wp.media.view.Search.extend({
915
+ tagName: 'input',
916
+ className: 'search',
917
+ id: 'media-search-input',
918
+
919
+ initialize: function( options ) {
920
+ this.shortcodeList = options.shortcodeList;
921
+ },
922
+
923
+ attributes: {
924
+ type: 'search',
925
+ placeholder: shortcodeUIData.strings.search_placeholder
926
+ },
927
+
928
+ events: {
929
+ 'keyup': 'search',
930
+ },
931
+
932
+ /**
933
+ * @returns {wp.media.view.Search} Returns itself to allow chaining
934
+ */
935
+ render: function() {
936
+ this.el.value = this.model.escape('search');
937
+ return this;
938
+ },
939
+
940
+ refreshShortcodes: function( shortcodeData ) {
941
+ this.shortcodeList.refresh( shortcodeData );
942
+ },
943
+
944
+ search: function( event ) {
945
+ if ( event.target.value == '' ) {
946
+ this.refreshShortcodes( sui.shortcodes );
947
+ } else {
948
+ this.refreshShortcodes( this.controller.search( event.target.value ) );
949
+ }
950
+ }
951
+ });
952
+
953
+ sui.views.SearchShortcode = SearchShortcode;
954
+ module.exports = SearchShortcode;
955
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
956
+ },{"./../utils/sui.js":9}],17:[function(require,module,exports){
957
+ (function (global){
958
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
959
+
960
+ /**
961
+ * Preview of rendered shortcode.
962
+ * Asynchronously fetches rendered shortcode content from WordPress.
963
+ * Displayed in an iframe to isolate editor styles.
964
+ *
965
+ * @class ShortcodePreview
966
+ * @constructor
967
+ * @params options
968
+ * @params options.model {Shortcode} Requires a valid shortcode.
969
+ */
970
+ var ShortcodePreview = Backbone.View.extend({
971
+ initialize: function( options ) {
972
+ this.head = this.getEditorStyles().join( "\n" );
973
+ },
974
+
975
+ getLoading: function() {
976
+ return '<div class="loading-placeholder">' +
977
+ '<div class="dashicons dashicons-admin-media"></div>' +
978
+ '<div class="wpview-loading"><ins></ins></div>' +
979
+ '</div>';
980
+ },
981
+
982
+ /**
983
+ * @method render
984
+ * @chainable
985
+ * @returns {ShortcodePreview}
986
+ */
987
+ render: function() {
988
+
989
+ var self = this;
990
+
991
+ // Render loading iFrame.
992
+ this.renderIFrame({
993
+ head: self.head,
994
+ body: self.getLoading(),
995
+ });
996
+
997
+ // Fetch shortcode preview.
998
+ // Render iFrame with shortcode preview.
999
+ this.fetchShortcode( function( response ) {
1000
+ self.renderIFrame({
1001
+ head: self.head,
1002
+ body: response,
1003
+ });
1004
+ });
1005
+
1006
+ return this;
1007
+ },
1008
+
1009
+ /**
1010
+ * Render a child iframe, removing any previously rendered iframe. Additionally, observe the rendered iframe
1011
+ * for mutations and resize as necessary to match content.
1012
+ *
1013
+ * @param params
1014
+ */
1015
+ renderIFrame: function( params ) {
1016
+
1017
+ var self = this, $iframe, resize;
1018
+
1019
+ _.defaults( params || {}, { 'head': '', 'body': '', 'body_classes': 'shortcake shortcake-preview' });
1020
+
1021
+ $iframe = $( '<iframe/>', {
1022
+ src: tinymce.Env.ie ? 'javascript:""' : '',
1023
+ frameBorder: '0',
1024
+ allowTransparency: 'true',
1025
+ scrolling: 'no',
1026
+ style: "width: 100%; display: block",
1027
+ } );
1028
+
1029
+ /**
1030
+ * Render preview in iFrame once loaded.
1031
+ * This is required because you can't write to
1032
+ * an iFrame contents before it exists.
1033
+ */
1034
+ $iframe.load( function() {
1035
+
1036
+ self.autoresizeIframe( $(this) );
1037
+
1038
+ var head = $(this).contents().find('head'),
1039
+ body = $(this).contents().find('body');
1040
+
1041
+ head.html( params.head );
1042
+ body.html( params.body );
1043
+ body.addClass( params.body_classes );
1044
+
1045
+ } );
1046
+
1047
+ this.$el.html( $iframe );
1048
+
1049
+ },
1050
+
1051
+ /**
1052
+ * Watch for mutations in iFrame content.
1053
+ * resize iFrame height on change.
1054
+ *
1055
+ * @param jQuery object $iframe
1056
+ */
1057
+ autoresizeIframe: function( $iframe ) {
1058
+
1059
+ var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
1060
+
1061
+ // Resize iFrame to size inner document.
1062
+ var resize = function() {
1063
+ $iframe.height( $iframe.contents().find('html').height() );
1064
+ };
1065
+
1066
+ resize();
1067
+
1068
+ if ( MutationObserver ) {
1069
+
1070
+ var observer = new MutationObserver( function() {
1071
+ resize();
1072
+ $iframe.contents().find('img,link').load( resize );
1073
+ } );
1074
+
1075
+ observer.observe(
1076
+ $iframe.contents()[0],
1077
+ { attributes: true, childList: true, subtree: true }
1078
+ );
1079
+
1080
+ } else {
1081
+
1082
+ for ( i = 1; i < 6; i++ ) {
1083
+ setTimeout( resize, i * 700 );
1084
+ }
1085
+
1086
+ }
1087
+
1088
+ },
1089
+
1090
+
1091
+ /**
1092
+ * Makes an AJAX call to the server to render the shortcode based on user supplied attributes. Server-side
1093
+ * rendering is necessary to allow for shortcodes that incorporate external content based on shortcode
1094
+ * attributes.
1095
+ *
1096
+ * @method fetchShortcode
1097
+ * @returns {String} Rendered shortcode markup (HTML).
1098
+ */
1099
+ fetchShortcode: function( callback ) {
1100
+
1101
+ wp.ajax.post( 'do_shortcode', {
1102
+ post_id: $( '#post_ID' ).val(),
1103
+ shortcode: this.model.formatShortcode(),
1104
+ nonce: shortcodeUIData.nonces.preview,
1105
+ }).done( function( response ) {
1106
+ callback( response );
1107
+ }).fail( function() {
1108
+ callback( '<span class="shortcake-error">' + shortcodeUIData.strings.mce_view_error + '</span>' );
1109
+ } );
1110
+
1111
+ },
1112
+
1113
+ /**
1114
+ * Returns an array of <link> tags for stylesheets applied to the TinyMCE editor.
1115
+ *
1116
+ * @method getEditorStyles
1117
+ * @returns {Array}
1118
+ */
1119
+ getEditorStyles: function() {
1120
+ var styles = {};
1121
+
1122
+ _.each( tinymce.editors, function( editor ) {
1123
+ _.each( editor.dom.$( 'link[rel="stylesheet"]', editor.getDoc().head ), function( link ) {
1124
+ var href;
1125
+ ( href = link.href ) && ( styles[href] = true ); // Poor man's de-duping.
1126
+ });
1127
+ });
1128
+
1129
+ styles = _.map( _.keys( styles ), function( href ) {
1130
+ return $( '<link rel="stylesheet" type="text/css">' ).attr( 'href', href )[0].outerHTML;
1131
+ });
1132
+
1133
+ return styles;
1134
+ }
1135
+ });
1136
+
1137
+ module.exports = ShortcodePreview;
1138
+
1139
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
1140
+ },{}],18:[function(require,module,exports){
1141
+ (function (global){
1142
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null),
1143
+ insertShortcodeList = require('./insert-shortcode-list.js'),
1144
+ TabbedView = require('./tabbed-view.js'),
1145
+ ShortcodePreview = require('./shortcode-preview.js'),
1146
+ EditShortcodeForm = require('./edit-shortcode-form.js'),
1147
+ Toolbar = require('./media-toolbar.js'),
1148
+ SearchShortcode = require('./search-shortcode.js'),
1149
+ sui = require('./../utils/sui.js');
1150
+ $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
1151
+
1152
+ var Shortcode_UI = Backbone.View.extend({
1153
+
1154
+ events: {
1155
+ "click .add-shortcode-list li": "select",
1156
+ "click .edit-shortcode-form-cancel": "cancelSelect"
1157
+ },
1158
+
1159
+ initialize: function(options) {
1160
+ this.controller = options.controller.state();
1161
+ //toolbar model looks for controller.state()
1162
+ this.toolbar_controller = options.controller;
1163
+ },
1164
+
1165
+ createToolbar: function(options) {
1166
+ toolbarOptions = {
1167
+ controller: this.toolbar_controller
1168
+ }
1169
+
1170
+ this.toolbar = new Toolbar( toolbarOptions );
1171
+
1172
+ this.views.add( this.toolbar );
1173
+
1174
+ this.toolbar.set( 'search', new SearchShortcode({
1175
+ controller: this.controller,
1176
+ model: this.controller.props,
1177
+ shortcodeList: this.shortcodeList,
1178
+ priority: 60
1179
+ }).render() );
1180
+
1181
+ },
1182
+
1183
+ render: function() {
1184
+
1185
+ this.$el.html('');
1186
+
1187
+ switch( this.controller.props.get('action') ) {
1188
+ case 'select' :
1189
+ this.renderSelectShortcodeView();
1190
+ break;
1191
+ case 'update' :
1192
+ case 'insert' :
1193
+ this.renderEditShortcodeView();
1194
+ break;
1195
+ }
1196
+
1197
+ },
1198
+
1199
+ renderSelectShortcodeView: function() {
1200
+ this.views.unset();
1201
+ this.shortcodeList = new insertShortcodeList( { shortcodes: sui.shortcodes } );
1202
+ this.createToolbar();
1203
+ this.views.add('', this.shortcodeList);
1204
+ },
1205
+
1206
+ renderEditShortcodeView: function() {
1207
+ var shortcode = this.controller.props.get( 'currentShortcode' );
1208
+ var view = new TabbedView({
1209
+ tabs: {
1210
+ edit: {
1211
+ label: shortcodeUIData.strings.edit_tab_label,
1212
+ content: new EditShortcodeForm({ model: shortcode })
1213
+ },
1214
+
1215
+ preview: {
1216
+ label: shortcodeUIData.strings.preview_tab_label,
1217
+ content: new ShortcodePreview({ model: shortcode }),
1218
+ open: function() {
1219
+ this.render();
1220
+ }
1221
+ }
1222
+ },
1223
+
1224
+ styles: {
1225
+ group: 'media-router edit-shortcode-tabs',
1226
+ tab: 'media-menu-item edit-shortcode-tab'
1227
+ }
1228
+ });
1229
+
1230
+ this.$el.append( view.render().el );
1231
+
1232
+ if ( this.controller.props.get('action') === 'update' ) {
1233
+ this.$el.find( '.edit-shortcode-form-cancel' ).remove();
1234
+ }
1235
+
1236
+ return this;
1237
+
1238
+ },
1239
+
1240
+ cancelSelect: function( e ) {
1241
+ e.preventDefault();
1242
+
1243
+ this.controller.props.set( 'action', 'select' );
1244
+ this.controller.props.set( 'currentShortcode', null );
1245
+ this.render();
1246
+ },
1247
+
1248
+ select: function(e) {
1249
+ this.controller.props.set( 'action', 'insert' );
1250
+ var target = $(e.currentTarget).closest( '.shortcode-list-item' );
1251
+ var shortcode = sui.shortcodes.findWhere( { shortcode_tag: target.attr( 'data-shortcode' ) } );
1252
+
1253
+ if ( ! shortcode ) {
1254
+ return;
1255
+ }
1256
+
1257
+ this.controller.props.set( 'currentShortcode', shortcode.clone() );
1258
+
1259
+ this.render();
1260
+
1261
+ },
1262
+
1263
+ });
1264
+
1265
+ module.exports = Shortcode_UI;
1266
+
1267
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
1268
+ },{"./../utils/sui.js":9,"./edit-shortcode-form.js":11,"./insert-shortcode-list.js":13,"./media-toolbar.js":15,"./search-shortcode.js":16,"./shortcode-preview.js":17,"./tabbed-view.js":19}],19:[function(require,module,exports){
1269
+ (function (global){
1270
+ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null);
1271
+ var sui = require('./../utils/sui.js');
1272
+
1273
+ /**
1274
+ * Abstraction to manage tabbed content. Tab parameters (e.g., label) along with
1275
+ * views for associated content are passed to initialize the tabbed view.
1276
+ *
1277
+ * @class TabbedView
1278
+ * @constructor
1279
+ * @extends Backbone.View
1280
+ * @params [options]
1281
+ * @params [options.tabs] {Object} A hash of key:value pairs, where each value
1282
+ * is itself an object with the following properties:
1283
+ *
1284
+ * label: The label to display on the tab. content: The `Backbone.View`
1285
+ * associated with the tab content.
1286
+ */
1287
+ var TabbedView = Backbone.View.extend({
1288
+ template : wp.template('tabbed-view-base'),
1289
+ tabs : {},
1290
+
1291
+ events : {
1292
+ 'click [data-role="tab"]' : function(event) {
1293
+ this.tabSwitcher(event);
1294
+ }
1295
+ },
1296
+
1297
+ initialize : function(options) {
1298
+ Backbone.View.prototype.initialize.apply(this, arguments);
1299
+
1300
+ _.defaults(this.options = (options || {}), {
1301
+ styles : {
1302
+ group : '',
1303
+ tab : ''
1304
+ }
1305
+ });
1306
+
1307
+ this.tabs = _.extend(this.tabs, options.tabs);
1308
+ },
1309
+
1310
+ /**
1311
+ * @method render
1312
+ * @chainable
1313
+ * @returns {TabbedView}
1314
+ */
1315
+ render : function() {
1316
+ var $content;
1317
+
1318
+ this.$el.html(this.template({
1319
+ tabs : this.tabs,
1320
+ styles : this.options.styles
1321
+ }));
1322
+
1323
+ $content = this.$('[data-role="tab-content"]');
1324
+ $content.empty();
1325
+
1326
+ _.each(this.tabs, function(tab) {
1327
+ var $el = tab.content.render().$el;
1328
+ $el.hide();
1329
+ $content.append($el);
1330
+ });
1331
+
1332
+ this.select(0);
1333
+
1334
+ return this;
1335
+ },
1336
+
1337
+ /**
1338
+ * Switches tab when previewing or editing
1339
+ */
1340
+ tabSwitcher : function(event) {
1341
+ event.stopPropagation();
1342
+ event.preventDefault();
1343
+
1344
+ var target = $(event.currentTarget).attr('data-target');
1345
+
1346
+ this.select(target);
1347
+ },
1348
+
1349
+ /**
1350
+ * Programmatically select (activate) a specific tab. Used internally to
1351
+ * process tab click events.
1352
+ *
1353
+ * @method select
1354
+ * @param selector
1355
+ * {number|string} The index (zero based) or key of the target
1356
+ * tab.
1357
+ */
1358
+ select : function(selector) {
1359
+ var index = 0;
1360
+ var target = null;
1361
+ var tab;
1362
+
1363
+ selector = selector || 0;
1364
+
1365
+ _.each(this.tabs, function(tab, key) {
1366
+ tab.content.$el.hide();
1367
+
1368
+ if (selector === key || selector === index) {
1369
+ target = key;
1370
+ }
1371
+
1372
+ index = index + 1;
1373
+ });
1374
+
1375
+ this.$('[data-role="tab"]').removeClass('active');
1376
+
1377
+ if (target) {
1378
+ tab = this.tabs[target];
1379
+
1380
+ this.$('[data-role="tab"][data-target="' + target + '"]').addClass(
1381
+ 'active');
1382
+
1383
+ tab.content.$el.show();
1384
+ (typeof tab.open == 'function') && tab.open.call(tab.content);
1385
+ }
1386
+ }
1387
+ });
1388
+
1389
+ sui.views.TabbedView = TabbedView;
1390
+ module.exports = TabbedView;
1391
+
1392
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
1393
+ },{"./../utils/sui.js":9}]},{},[7]);
js/collections/shortcode-attributes.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var Backbone = require('backbone');
2
+ var ShortcodeAttribute = require('sui-models/shortcode-attribute');
3
+
4
+ /**
5
+ * Shortcode Attributes collection.
6
+ */
7
+ var ShortcodeAttributes = Backbone.Collection.extend({
8
+ model : ShortcodeAttribute,
9
+ // Deep Clone.
10
+ clone : function() {
11
+ return new this.constructor(_.map(this.models, function(m) {
12
+ return m.clone();
13
+ }));
14
+ }
15
+ });
16
+
17
+ module.exports = ShortcodeAttributes;
js/collections/shortcodes.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ var Backbone = require('backbone');
2
+ var Shortcode = require('sui-models/shortcode');
3
+
4
+ // Shortcode Collection
5
+ var Shortcodes = Backbone.Collection.extend({
6
+ model : Shortcode
7
+ });
8
+
9
+ module.exports = Shortcodes;
js/controllers/media-controller.js ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var Backbone = require('backbone'),
2
+ wp = require('wp');
3
+ Shortcodes = require('sui-collections/shortcodes');
4
+
5
+ var MediaController = wp.media.controller.State.extend({
6
+
7
+ initialize: function(){
8
+
9
+ this.props = new Backbone.Model({
10
+ currentShortcode: null,
11
+ action: 'select',
12
+ search: null
13
+ });
14
+
15
+ this.props.on( 'change:action', this.refresh, this );
16
+
17
+ },
18
+
19
+ refresh: function() {
20
+ if ( this.frame && this.frame.toolbar ) {
21
+ this.frame.toolbar.get().refresh();
22
+ }
23
+ },
24
+
25
+ search: function( searchTerm ) {
26
+ var pattern = new RegExp( searchTerm, "gi" );
27
+ var filteredModels = sui.shortcodes.filter( function( model ) {
28
+ return pattern.test( model.get( "label" ) );
29
+ });
30
+ return filteredModels;
31
+ },
32
+
33
+ insert: function() {
34
+ var shortcode = this.props.get('currentShortcode');
35
+ if ( shortcode ) {
36
+ send_to_editor( shortcode.formatShortcode() );
37
+ this.reset();
38
+ this.frame.close();
39
+ }
40
+ },
41
+
42
+ reset: function() {
43
+ this.props.set( 'action', 'select' );
44
+ this.props.set( 'currentShortcode', null );
45
+ this.props.set( 'search', null );
46
+ },
47
+
48
+ });
49
+
50
+ sui.controllers.MediaController = MediaController;
51
+ module.exports = MediaController;
js/field-attachment.js ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var sui = require('sui-utils/sui'),
2
+ editAttributeField = require( 'sui-views/edit-attribute-field' ),
3
+ $ = require('jquery');
4
+
5
+ // Cache attachment IDs for quicker loading.
6
+ var iDCache = {};
7
+
8
+ sui.views.editAttributeFieldAttachment = editAttributeField.extend( {
9
+
10
+ render: function() {
11
+
12
+ var model = this.model;
13
+
14
+ // Set model default values.
15
+ for ( var arg in ShorcakeImageFieldData.defaultArgs ) {
16
+ if ( ! model.get( arg ) ) {
17
+ model.set( arg, ShorcakeImageFieldData.defaultArgs[ arg ] );
18
+ }
19
+ }
20
+
21
+ this.$el.html( this.template( model.toJSON() ) );
22
+
23
+ var $container = this.$el.find( '.shortcake-attachment-preview' );
24
+ var $addButton = $container.find( 'button.add' );
25
+ var $removeButton = $container.find( 'button.remove' );
26
+
27
+ var frame = wp.media( {
28
+ multiple: false,
29
+ title: model.get( 'frameTitle' ),
30
+ library: {
31
+ type: model.get( 'libraryType' ),
32
+ },
33
+ } );
34
+
35
+ /**
36
+ * Update the field attachment.
37
+ * Re-renders UI.
38
+ * If ID is empty - does nothing.
39
+ *
40
+ * @param {int} id Attachment ID
41
+ */
42
+ var updateAttachment = function( id ) {
43
+
44
+ if ( ! id ) {
45
+ return;
46
+ }
47
+
48
+ model.set( 'value', id );
49
+
50
+ if ( iDCache[ id ] ) {
51
+ renderPreview( iDCache[ id ] );
52
+ return;
53
+ }
54
+
55
+ $container.addClass( 'loading' );
56
+
57
+ wp.ajax.post( 'get-attachment', {
58
+ 'id': id
59
+ } ).done( function( attachment ) {
60
+ // Cache for later.
61
+ iDCache[ id ] = attachment;
62
+ renderPreview( attachment );
63
+ $container.removeClass( 'loading' );
64
+ } );
65
+
66
+ }
67
+
68
+ /**
69
+ * Renders attachment preview in field.
70
+ * @param {object} attachment model
71
+ * @return null
72
+ */
73
+ var renderPreview = function( attachment ) {
74
+
75
+ var $thumbnail = $('<div class="thumbnail"></div>');
76
+
77
+ if ( 'image' !== attachment.type ) {
78
+
79
+ $( '<img/>', {
80
+ src: attachment.icon,
81
+ alt: attachment.title,
82
+ } ).appendTo( $thumbnail );
83
+
84
+ $( '<div/>', {
85
+ class: 'filename',
86
+ html: '<div>' + attachment.title + '</div>',
87
+ } ).appendTo( $thumbnail );
88
+
89
+ } else {
90
+
91
+ $( '<img/>', {
92
+ src: attachment.sizes.thumbnail.url,
93
+ width: attachment.sizes.thumbnail.width,
94
+ height: attachment.sizes.thumbnail.height,
95
+ alt: attachment.alt,
96
+ } ) .appendTo( $thumbnail )
97
+
98
+ }
99
+
100
+ $thumbnail.find( 'img' ).wrap( '<div class="centered"></div>' );
101
+ $container.append( $thumbnail );
102
+ $container.toggleClass( 'has-attachment', true );
103
+
104
+ }
105
+
106
+ /**
107
+ * Remove the attachment.
108
+ * Render preview & Update the model.
109
+ */
110
+ var removeAttachment = function() {
111
+
112
+ model.set( 'value', null );
113
+
114
+ $container.toggleClass( 'has-attachment', false );
115
+ $container.toggleClass( 'has-attachment', false );
116
+ $container.find( '.thumbnail' ).remove();
117
+ }
118
+
119
+ // Add initial Attachment if available.
120
+ updateAttachment( model.get( 'value' ) );
121
+
122
+ // Remove file when the button is clicked.
123
+ $removeButton.click( function(e) {
124
+ e.preventDefault();
125
+ removeAttachment();
126
+ });
127
+
128
+ // Open media frame when add button is clicked
129
+ $addButton.click( function(e) {
130
+ e.preventDefault();
131
+ frame.open();
132
+ } );
133
+
134
+ // Update the attachment when an item is selected.
135
+ frame.on( 'select', function() {
136
+
137
+ var selection = frame.state().get('selection');
138
+ attachment = selection.first();
139
+
140
+ updateAttachment( attachment.id );
141
+
142
+ frame.close();
143
+
144
+ });
145
+
146
+ }
147
+
148
+ } );
js/field-color.js ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var sui = require('sui-utils/sui'),
2
+ editAttributeField = require( 'sui-views/edit-attribute-field' ),
3
+ $ = require('jquery');
4
+
5
+ sui.views.editAttributeFieldColor = editAttributeField.extend( {
6
+
7
+ render: function() {
8
+ this.$el.html( this.template( this.model.toJSON() ) );
9
+
10
+ this.$el.find('input[type="text"]:not(.wp-color-picker)').wpColorPicker({
11
+ change: function() {
12
+ jQuery(this).trigger('keyup');
13
+ }
14
+ });
15
+
16
+ return this;
17
+ }
18
+
19
+ } );
js/models/inner-content.js ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ var Backbone = require('backbone');
2
+
3
+ /**
4
+ * Shortcode Attribute Model.
5
+ */
6
+ var InnerContent = Backbone.Model.extend({
7
+ defaults : false,
8
+ });
9
+
10
+ module.exports = InnerContent;
js/models/shortcode-attribute.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var Backbone = require('backbone');
2
+
3
+ var ShortcodeAttribute = Backbone.Model.extend({
4
+ defaults: {
5
+ attr: '',
6
+ label: '',
7
+ type: '',
8
+ value: '',
9
+ placeholder: '',
10
+ },
11
+ });
12
+
13
+ module.exports = ShortcodeAttribute;
js/models/shortcode.js ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var Backbone = require('backbone');
2
+ var ShortcodeAttributes = require('sui-collections/shortcode-attributes');
3
+ var InnerContent = require('sui-models/inner-content');
4
+
5
+ Shortcode = Backbone.Model.extend({
6
+
7
+ defaults: {
8
+ label: '',
9
+ shortcode_tag: '',
10
+ attrs: new ShortcodeAttributes,
11
+ inner_content: new InnerContent,
12
+ },
13
+
14
+ /**
15
+ * Custom set method.
16
+ * Handles setting the attribute collection.
17
+ */
18
+ set: function( attributes, options ) {
19
+
20
+ if ( attributes.attrs !== undefined && ! ( attributes.attrs instanceof ShortcodeAttributes ) ) {
21
+ attributes.attrs = new ShortcodeAttributes( attributes.attrs );
22
+ }
23
+
24
+ if ( attributes.inner_content !== undefined && ! ( attributes.inner_content instanceof InnerContent ) ) {
25
+ attributes.inner_content = new InnerContent( attributes.inner_content );
26
+ }
27
+
28
+ return Backbone.Model.prototype.set.call(this, attributes, options);
29
+ },
30
+
31
+ /**
32
+ * Custom toJSON.
33
+ * Handles converting the attribute collection to JSON.
34
+ */
35
+ toJSON: function( options ) {
36
+ options = Backbone.Model.prototype.toJSON.call(this, options);
37
+ if ( options.attrs !== undefined && ( options.attrs instanceof ShortcodeAttributes ) ) {
38
+ options.attrs = options.attrs.toJSON();
39
+ }
40
+ if ( options.inner_content !== undefined && ( options.inner_content instanceof InnerContent ) ) {
41
+ options.inner_content = options.inner_content.toJSON();
42
+ }
43
+ return options;
44
+ },
45
+
46
+ /**
47
+ * Custom clone
48
+ * Make sure we don't clone a reference to attributes.
49
+ */
50
+ clone: function() {
51
+ var clone = Backbone.Model.prototype.clone.call( this );
52
+ clone.set( 'attrs', clone.get( 'attrs' ).clone() );
53
+ clone.set( 'inner_content', clone.get( 'inner_content' ).clone() );
54
+ return clone;
55
+ },
56
+
57
+ /**
58
+ * Get the shortcode as... a shortcode!
59
+ *
60
+ * @return string eg [shortcode attr1=value]
61
+ */
62
+ formatShortcode: function() {
63
+
64
+ var template, shortcodeAttributes, attrs = [], content, self = this;
65
+
66
+ this.get( 'attrs' ).each( function( attr ) {
67
+
68
+ // Skip empty attributes.
69
+ if ( ! attr.get( 'value' ) || attr.get( 'value' ).length < 1 ) {
70
+ return;
71
+ }
72
+
73
+ attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' );
74
+
75
+ } );
76
+
77
+ if ( 'undefined' !== typeof this.get( 'inner_content' ).get( 'value' ) && this.get( 'inner_content' ).get( 'value').length > 0 ) {
78
+ content = this.get( 'inner_content' ).get( 'value' );
79
+ }
80
+
81
+ template = "[{{ shortcode }} {{ attributes }}]"
82
+
83
+ if ( content && content.length > 0 ) {
84
+ template += "{{ content }}[/{{ shortcode }}]"
85
+ }
86
+
87
+ template = template.replace( /{{ shortcode }}/g, this.get('shortcode_tag') );
88
+ template = template.replace( /{{ attributes }}/g, attrs.join( ' ' ) );
89
+ template = template.replace( /{{ content }}/g, content );
90
+
91
+ return template;
92
+
93
+ }
94
+
95
+ });
96
+
97
+ module.exports = Shortcode;
js/shortcode-ui.js ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var sui = require('sui-utils/sui'),
2
+ Shortcodes = require('sui-collections/shortcodes'),
3
+ shortcodeViewConstructor = require('sui-utils/shortcode-view-constructor'),
4
+ mediaFrame = require('sui-views/media-frame'),
5
+ wp = require('wp'),
6
+ $ = require('jquery');
7
+
8
+ $(document).ready(function(){
9
+
10
+ // Create collection of shortcode models from data.
11
+ sui.shortcodes.add( shortcodeUIData.shortcodes );
12
+
13
+ wp.media.view.MediaFrame.Post = mediaFrame;
14
+
15
+ // Register a view for each shortcode.
16
+ sui.shortcodes.each( function( shortcode ) {
17
+ if ( wp.mce.views ) {
18
+ wp.mce.views.register(
19
+ shortcode.get('shortcode_tag'),
20
+ // Must extend for 4.1.
21
+ // This is handled by wp.mce.views.register in 4.2.
22
+ $.extend( true, {}, shortcodeViewConstructor )
23
+ );
24
+ }
25
+ } );
26
+
27
+ });
js/utils/shortcode-view-constructor.js ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ sui = require('sui-utils/sui');
2
+ wp = require('wp');
3
+ $ = require('jquery');
4
+
5
+ /**
6
+ * Generic shortcode mce view constructor.
7
+ * This is cloned and used by each shortcode when registering a view.
8
+ */
9
+ var shortcodeViewConstructor = {
10
+
11
+ initialize: function( options ) {
12
+ this.shortcodeModel = this.getShortcodeModel( this.shortcode );
13
+ },
14
+
15
+ /**
16
+ * Get the shortcode model given the view shortcode options.
17
+ * Must be a registered shortcode (see sui.shortcodes)
18
+ */
19
+ getShortcodeModel: function( options ) {
20
+
21
+ var shortcodeModel;
22
+
23
+ shortcodeModel = sui.shortcodes.findWhere( { shortcode_tag: options.tag } );
24
+
25
+ if ( ! shortcodeModel ) {
26
+ return;
27
+ }
28
+
29
+ shortcodeModel = shortcodeModel.clone();
30
+
31
+ shortcodeModel.get('attrs').each(
32
+ function( attr ) {
33
+ if ( attr.get('attr') in options.attrs.named ) {
34
+ attr.set(
35
+ 'value',
36
+ options.attrs.named[ attr.get('attr') ]
37
+ );
38
+ }
39
+ }
40
+ );
41
+
42
+ if ('content' in options) {
43
+ var inner_content = shortcodeModel.get('inner_content');
44
+ inner_content.set('value', options.content)
45
+ }
46
+
47
+ return shortcodeModel;
48
+
49
+ },
50
+
51
+ /**
52
+ * Return the preview HTML.
53
+ * If empty, fetches data.
54
+ *
55
+ * @return string
56
+ */
57
+ getContent : function() {
58
+ if ( ! this.content ) {
59
+ this.fetch();
60
+ }
61
+ return this.content;
62
+ },
63
+
64
+ /**
65
+ * Fetch preview.
66
+ * Async. Sets this.content and calls this.render.
67
+ *
68
+ * @return undefined
69
+ */
70
+ fetch : function() {
71
+
72
+ var self = this;
73
+
74
+ if ( ! this.fetching ) {
75
+
76
+ this.fetching = true;
77
+
78
+ wp.ajax.post( 'do_shortcode', {
79
+ post_id: $( '#post_ID' ).val(),
80
+ shortcode: this.shortcodeModel.formatShortcode(),
81
+ nonce: shortcodeUIData.nonces.preview,
82
+ }).done( function( response ) {
83
+ self.content = response;
84
+ }).fail( function() {
85
+ self.content = '<span class="shortcake-error">' + shortcodeUIData.strings.mce_view_error + '</span>';
86
+ } ).always( function() {
87
+ delete self.fetching;
88
+ self.render( true );
89
+ } );
90
+
91
+ }
92
+
93
+ },
94
+
95
+ /**
96
+ * Edit shortcode.
97
+ * Get shortcode model and open edit modal.
98
+ *
99
+ */
100
+ edit : function( shortcodeString ) {
101
+
102
+ var currentShortcode;
103
+
104
+ // Backwards compatability for WP pre-4.2
105
+ if ( 'object' === typeof( shortcodeString ) ) {
106
+ shortcodeString = decodeURIComponent( $(shortcodeString).attr('data-wpview-text') );
107
+ }
108
+
109
+ currentShortcode = this.parseShortcodeString( shortcodeString );
110
+
111
+ if ( currentShortcode ) {
112
+
113
+ var wp_media_frame = wp.media.frames.wp_media_frame = wp.media({
114
+ frame : "post",
115
+ state : 'shortcode-ui',
116
+ currentShortcode : currentShortcode,
117
+ });
118
+
119
+ wp_media_frame.open();
120
+
121
+ }
122
+
123
+ },
124
+
125
+ /**
126
+ * Parse a shortcode string and return shortcode model.
127
+ * Must be a registered shortcode - see window.Shortcode_UI.shortcodes.
128
+ *
129
+ * @todo - I think there must be a cleaner way to get the
130
+ * shortcode & args here that doesn't use regex.
131
+ *
132
+ * @param string shortcodeString
133
+ * @return Shortcode
134
+ */
135
+ parseShortcodeString: function( shortcodeString ) {
136
+
137
+ var model, attr;
138
+
139
+ var megaRegex = /\[([^\s\]]+)([^\]]+)?\]([^\[]*)?(\[\/(\S+?)\])?/;
140
+ var matches = shortcodeString.match( megaRegex );
141
+
142
+ if ( ! matches ) {
143
+ return;
144
+ }
145
+
146
+ defaultShortcode = sui.shortcodes.findWhere({
147
+ shortcode_tag : matches[1]
148
+ });
149
+
150
+ if ( ! defaultShortcode ) {
151
+ return;
152
+ }
153
+
154
+ currentShortcode = defaultShortcode.clone();
155
+
156
+ if ( matches[2] ) {
157
+
158
+ attributeMatches = matches[2].match( /(\S+?=".*?")/g ) || [];
159
+
160
+ // convert attribute strings to object.
161
+ for ( var i = 0; i < attributeMatches.length; i++ ) {
162
+
163
+ var bitsRegEx = /(\S+?)="(.*?)"/g;
164
+ var bits = bitsRegEx.exec( attributeMatches[i] );
165
+
166
+ attr = currentShortcode.get( 'attrs' ).findWhere({
167
+ attr : bits[1]
168
+ });
169
+
170
+ if ( attr ) {
171
+ attr.set('value', bits[2]);
172
+ }
173
+
174
+ }
175
+
176
+ }
177
+
178
+ if ( matches[3] ) {
179
+ var inner_content = currentShortcode.get( 'inner_content' );
180
+ inner_content.set( 'value', matches[3] );
181
+ }
182
+
183
+ return currentShortcode;
184
+
185
+ },
186
+
187
+ // Backwards compatability for Pre WP 4.2.
188
+ View: {
189
+
190
+ overlay: true,
191
+
192
+ initialize: function( options ) {
193
+ this.shortcode = this.getShortcode( options );
194
+ },
195
+
196
+ getShortcode: function( options ) {
197
+
198
+ var shortcodeModel, shortcode;
199
+
200
+ shortcodeModel = sui.shortcodes.findWhere( { shortcode_tag: options.shortcode.tag } );
201
+
202
+ if (!shortcodeModel) {
203
+ return;
204
+ }
205
+
206
+ shortcode = shortcodeModel.clone();
207
+
208
+ shortcode.get('attrs').each(
209
+ function(attr) {
210
+
211
+ if (attr.get('attr') in options.shortcode.attrs.named) {
212
+ attr.set('value',
213
+ options.shortcode.attrs.named[attr
214
+ .get('attr')]);
215
+ }
216
+
217
+ });
218
+
219
+ if ('content' in options.shortcode) {
220
+ var inner_content = shortcode.get('inner_content');
221
+ inner_content.set('value', options.shortcode.content)
222
+ }
223
+
224
+ return shortcode;
225
+
226
+ },
227
+
228
+ fetch : function() {
229
+
230
+ var self = this;
231
+
232
+ if ( ! this.parsed ) {
233
+
234
+ wp.ajax.post( 'do_shortcode', {
235
+ post_id: $( '#post_ID' ).val(),
236
+ shortcode: this.shortcode.formatShortcode(),
237
+ nonce: shortcodeUIData.nonces.preview,
238
+ }).done( function( response ) {
239
+ if ( response.indexOf( '<script' ) !== -1 ) {
240
+ self.setIframes( self.getEditorStyles(), response );
241
+ } else {
242
+ self.parsed = response;
243
+ self.render( true );
244
+ }
245
+ }).fail( function() {
246
+ self.parsed = '<span class="shortcake-error">' + shortcodeUIData.strings.mce_view_error + '</span>';
247
+ self.render( true );
248
+ } );
249
+
250
+ }
251
+
252
+ },
253
+
254
+ /**
255
+ * Render the shortcode
256
+ *
257
+ * To ensure consistent rendering - this makes an ajax request to the
258
+ * admin and displays.
259
+ *
260
+ * @return string html
261
+ */
262
+ getHtml : function() {
263
+
264
+ if ( ! this.parsed ) {
265
+ this.fetch();
266
+ }
267
+
268
+ return this.parsed;
269
+ },
270
+
271
+ /**
272
+ * Returns an array of <link> tags for stylesheets applied to the TinyMCE editor.
273
+ *
274
+ * @method getEditorStyles
275
+ * @returns {Array}
276
+ */
277
+ getEditorStyles: function() {
278
+
279
+ var styles = '';
280
+
281
+ this.getNodes( function ( editor, node, content ) {
282
+ var dom = editor.dom,
283
+ bodyClasses = editor.getBody().className || '',
284
+ iframe, iframeDoc, i, resize;
285
+
286
+ tinymce.each( dom.$( 'link[rel="stylesheet"]', editor.getDoc().head ), function( link ) {
287
+ if ( link.href && link.href.indexOf( 'skins/lightgray/content.min.css' ) === -1 &&
288
+ link.href.indexOf( 'skins/wordpress/wp-content.css' ) === -1 ) {
289
+
290
+ styles += dom.getOuterHTML( link ) + '\n';
291
+ }
292
+
293
+ });
294
+
295
+ } );
296
+
297
+ return styles;
298
+ },
299
+
300
+ },
301
+
302
+ };
303
+
304
+ module.exports = shortcodeViewConstructor;
js/utils/sui.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ var Shortcodes = require('sui-collections/shortcodes');
2
+
3
+ window.Shortcode_UI = window.Shortcode_UI || {
4
+ shortcodes: new Shortcodes,
5
+ views: {},
6
+ controllers: {},
7
+ };
8
+
9
+ module.exports = window.Shortcode_UI;
js/views/edit-attribute-field.js ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var Backbone = require('backbone');
2
+ sui = require('sui-utils/sui');
3
+
4
+ var editAttributeField = Backbone.View.extend( {
5
+
6
+ tagName: "div",
7
+
8
+ events: {
9
+ 'keyup input[type="text"]': 'updateValue',
10
+ 'keyup textarea': 'updateValue',
11
+ 'change select': 'updateValue',
12
+ 'change input[type=checkbox]': 'updateValue',
13
+ 'change input[type=radio]': 'updateValue',
14
+ 'change input[type=email]': 'updateValue',
15
+ 'change input[type=number]': 'updateValue',
16
+ 'change input[type=date]': 'updateValue',
17
+ 'change input[type=url]': 'updateValue',
18
+ },
19
+
20
+ render: function() {
21
+ this.$el.html( this.template( this.model.toJSON() ) );
22
+ return this
23
+ },
24
+
25
+ /**
26
+ * Input Changed Update Callback.
27
+ *
28
+ * If the input field that has changed is for content or a valid attribute,
29
+ * then it should update the model.
30
+ */
31
+ updateValue: function( e ) {
32
+
33
+ if ( this.model.get( 'attr' ) ) {
34
+ var $el = $( this.el ).find( '[name=' + this.model.get( 'attr' ) + ']' );
35
+ } else {
36
+ var $el = $( this.el ).find( '[name="inner_content"]' );
37
+ }
38
+
39
+ if ( 'radio' === this.model.attributes.type ) {
40
+ this.model.set( 'value', $el.filter(':checked').first().val() );
41
+ } else if ( 'checkbox' === this.model.attributes.type ) {
42
+ this.model.set( 'value', $el.is( ':checked' ) );
43
+ } else {
44
+ this.model.set( 'value', $el.val() );
45
+ }
46
+ },
47
+
48
+ } );
49
+
50
+ sui.views.editAttributeField = editAttributeField;
51
+ module.exports = editAttributeField;
js/views/edit-shortcode-form.js ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var wp = require('wp'),
2
+ sui = require('sui-utils/sui'),
3
+ editAttributeField = require( 'sui-views/edit-attribute-field' );
4
+
5
+ /**
6
+ * Single edit shortcode content view.
7
+ */
8
+ var EditShortcodeForm = wp.Backbone.View.extend({
9
+ template: wp.template('shortcode-default-edit-form'),
10
+
11
+ initialize: function() {
12
+
13
+ var t = this;
14
+
15
+ var innerContent = this.model.get( 'inner_content' );
16
+ if ( typeof innerContent.attributes.type !== 'undefined' ) {
17
+
18
+ // add UI for inner_content
19
+ var view = new editAttributeField( {
20
+ model: innerContent,
21
+ shortcode: t.model,
22
+ } );
23
+
24
+ view.template = wp.media.template( 'shortcode-ui-content' );
25
+ t.views.add( '.edit-shortcode-form-fields', view );
26
+
27
+ }
28
+
29
+ this.model.get( 'attrs' ).each( function( attr ) {
30
+
31
+ // Get the field settings from localization data.
32
+ var type = attr.get('type');
33
+
34
+ if ( ! shortcodeUIFieldData[ type ] ) {
35
+ return;
36
+ }
37
+
38
+ var viewObjName = shortcodeUIFieldData[ type ].view;
39
+ var tmplName = shortcodeUIFieldData[ type ].template;
40
+
41
+ var view = new sui.views[viewObjName]( { model: attr } );
42
+ view.template = wp.media.template( tmplName );
43
+ view.shortcode = t.model;
44
+
45
+ t.views.add( '.edit-shortcode-form-fields', view );
46
+
47
+ } );
48
+
49
+ },
50
+
51
+ });
52
+
53
+ module.exports = EditShortcodeForm;
js/views/insert-shortcode-list-item.js ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var wp = require('wp');
2
+
3
+ /**
4
+ * Single shortcode list item view.
5
+ */
6
+ var insertShortcodeListItem = wp.Backbone.View.extend({
7
+
8
+ tagName : 'li',
9
+ template : wp.template('add-shortcode-list-item'),
10
+ className : 'shortcode-list-item',
11
+
12
+ render : function() {
13
+
14
+ var data = this.model.toJSON();
15
+ this.$el.attr('data-shortcode', data.shortcode_tag);
16
+
17
+ if (('listItemImage' in data)
18
+ && 0 === data.listItemImage.indexOf('dashicons-')) {
19
+ data.listItemImage = '<div class="dashicons ' + data.listItemImage
20
+ + '"></div>';
21
+ }
22
+
23
+ this.$el.html(this.template(data));
24
+
25
+ return this;
26
+
27
+ }
28
+ });
29
+
30
+ module.exports = insertShortcodeListItem;
js/views/insert-shortcode-list.js ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var wp = require('wp');
2
+ var Backbone = require('backbone');
3
+ var Shortcodes = require('sui-collections/shortcodes');
4
+ var insertShortcodeListItem = require('sui-views/insert-shortcode-list-item');
5
+
6
+ var insertShortcodeList = wp.Backbone.View.extend({
7
+
8
+ tagName : 'div',
9
+ template : wp.template('add-shortcode-list'),
10
+
11
+ initialize : function( options ) {
12
+
13
+ this.displayShortcodes( options );
14
+
15
+ },
16
+
17
+ refresh: function( shortcodeData ) {
18
+ if ( shortcodeData instanceof Backbone.Collection ) {
19
+ var options = { shortcodes: shortcodeData };
20
+ } else {
21
+ var options = { shortcodes: new Shortcodes( shortcodeData ) };
22
+ }
23
+ this.displayShortcodes( options );
24
+ },
25
+
26
+ displayShortcodes: function(options) {
27
+ var t = this;
28
+
29
+ t.$el.find('.add-shortcode-list').html('');
30
+ t.options = {};
31
+ t.options.shortcodes = options.shortcodes;
32
+
33
+ t.options.shortcodes.each(function(shortcode) {
34
+ t.views.add('ul', new insertShortcodeListItem({
35
+ model : shortcode
36
+ }));
37
+ });
38
+ }
39
+
40
+ });
41
+
42
+ module.exports = insertShortcodeList;
js/views/media-frame.js ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var wp = require('wp'),
2
+ MediaController = require('sui-controllers/media-controller'),
3
+ Shortcode_UI = require('./shortcode-ui'),
4
+ Toolbar = require('./media-toolbar');
5
+
6
+ var postMediaFrame = wp.media.view.MediaFrame.Post;
7
+ var mediaFrame = postMediaFrame.extend( {
8
+
9
+ initialize: function() {
10
+
11
+ postMediaFrame.prototype.initialize.apply( this, arguments );
12
+
13
+ var id = 'shortcode-ui';
14
+
15
+ var opts = {
16
+ id : id,
17
+ search : true,
18
+ router : false,
19
+ toolbar : id + '-toolbar',
20
+ menu : 'default',
21
+ title : shortcodeUIData.strings.media_frame_menu_insert_label,
22
+ tabs : [ 'insert' ],
23
+ priority: 66,
24
+ content : id + '-content-insert',
25
+ };
26
+
27
+ if ( 'currentShortcode' in this.options ) {
28
+ opts.title = shortcodeUIData.strings.media_frame_menu_update_label;
29
+ }
30
+
31
+ var controller = new MediaController( opts );
32
+
33
+ if ( 'currentShortcode' in this.options ) {
34
+ controller.props.set( 'currentShortcode', arguments[0].currentShortcode );
35
+ controller.props.set( 'action', 'update' );
36
+ }
37
+
38
+ this.states.add([ controller]);
39
+
40
+ this.on( 'content:render:' + id + '-content-insert', _.bind( this.contentRender, this, 'shortcode-ui', 'insert' ) );
41
+ this.on( 'toolbar:create:' + id + '-toolbar', this.toolbarCreate, this );
42
+ this.on( 'toolbar:render:' + id + '-toolbar', this.toolbarRender, this );
43
+ this.on( 'menu:render:default', this.renderShortcodeUIMenu );
44
+
45
+ },
46
+
47
+ contentRender : function( id, tab ) {
48
+ this.content.set(
49
+ new Shortcode_UI( {
50
+ controller: this,
51
+ className: 'clearfix ' + id + '-content ' + id + '-content-' + tab
52
+ } )
53
+ );
54
+ },
55
+
56
+ toolbarRender: function( toolbar ) {},
57
+
58
+ toolbarCreate : function( toolbar ) {
59
+ var text = shortcodeUIData.strings.media_frame_toolbar_insert_label;
60
+ if ( 'currentShortcode' in this.options ) {
61
+ text = shortcodeUIData.strings.media_frame_toolbar_update_label;
62
+ }
63
+
64
+ toolbar.view = new Toolbar( {
65
+ controller : this,
66
+ items: {
67
+ insert: {
68
+ text: text,
69
+ style: 'primary',
70
+ priority: 80,
71
+ requires: false,
72
+ click: this.insertAction,
73
+ }
74
+ }
75
+ } );
76
+ },
77
+
78
+ renderShortcodeUIMenu: function( view ) {
79
+
80
+ // Add a menu separator link.
81
+ view.set({
82
+ 'shortcode-ui-separator': new wp.media.View({
83
+ className: 'separator',
84
+ priority: 65
85
+ })
86
+ });
87
+
88
+ // Hide menu if editing.
89
+ // @todo - fix this.
90
+ // This is a hack.
91
+ // I just can't work out how to do it properly...
92
+ if (
93
+ view.controller.state().props
94
+ && view.controller.state().props.get( 'currentShortcode' )
95
+ ) {
96
+ window.setTimeout( function() {
97
+ view.controller.$el.addClass( 'hide-menu' );
98
+ } );
99
+ }
100
+
101
+ },
102
+
103
+ insertAction: function() {
104
+ this.controller.state().insert();
105
+ },
106
+
107
+ } );
108
+
109
+ module.exports = mediaFrame;
js/views/media-toolbar.js ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var wp = require('wp');
2
+
3
+ /**
4
+ * Toolbar view that extends wp.media.view.Toolbar
5
+ * to define cusotm refresh method
6
+ */
7
+ var Toolbar = wp.media.view.Toolbar.extend({
8
+ initialize : function() {
9
+ _.defaults(this.options, {
10
+ requires : false
11
+ });
12
+ // Call 'initialize' directly on the parent class.
13
+ wp.media.view.Toolbar.prototype.initialize.apply(this, arguments);
14
+ },
15
+
16
+ refresh : function() {
17
+ var action = this.controller.state().props.get('action');
18
+ if( this.get('insert') ) {
19
+ this.get('insert').model.set('disabled', action == 'select');
20
+ }
21
+ /**
22
+ * call 'refresh' directly on the parent class
23
+ */
24
+ wp.media.view.Toolbar.prototype.refresh.apply(this, arguments);
25
+ }
26
+ });
27
+
28
+ module.exports = Toolbar;
js/views/search-shortcode.js ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var wp = require('wp');
2
+ sui = require('sui-utils/sui');
3
+
4
+ var SearchShortcode = wp.media.view.Search.extend({
5
+ tagName: 'input',
6
+ className: 'search',
7
+ id: 'media-search-input',
8
+
9
+ initialize: function( options ) {
10
+ this.shortcodeList = options.shortcodeList;
11
+ },
12
+
13
+ attributes: {
14
+ type: 'search',
15
+ placeholder: shortcodeUIData.strings.search_placeholder
16
+ },
17
+
18
+ events: {
19
+ 'keyup': 'search',
20
+ },
21
+
22
+ /**
23
+ * @returns {wp.media.view.Search} Returns itself to allow chaining
24
+ */
25
+ render: function() {
26
+ this.el.value = this.model.escape('search');
27
+ return this;
28
+ },
29
+
30
+ refreshShortcodes: function( shortcodeData ) {
31
+ this.shortcodeList.refresh( shortcodeData );
32
+ },
33
+
34
+ search: function( event ) {
35
+ if ( event.target.value == '' ) {
36
+ this.refreshShortcodes( sui.shortcodes );
37
+ } else {
38
+ this.refreshShortcodes( this.controller.search( event.target.value ) );
39
+ }
40
+ }
41
+ });
42
+
43
+ sui.views.SearchShortcode = SearchShortcode;
44
+ module.exports = SearchShortcode;
js/views/shortcode-preview.js ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var Backbone = require('backbone');
2
+
3
+ /**
4
+ * Preview of rendered shortcode.
5
+ * Asynchronously fetches rendered shortcode content from WordPress.
6
+ * Displayed in an iframe to isolate editor styles.
7
+ *
8
+ * @class ShortcodePreview
9
+ * @constructor
10
+ * @params options
11
+ * @params options.model {Shortcode} Requires a valid shortcode.
12
+ */
13
+ var ShortcodePreview = Backbone.View.extend({
14
+ initialize: function( options ) {
15
+ this.head = this.getEditorStyles().join( "\n" );
16
+ },
17
+
18
+ getLoading: function() {
19
+ return '<div class="loading-placeholder">' +
20
+ '<div class="dashicons dashicons-admin-media"></div>' +
21
+ '<div class="wpview-loading"><ins></ins></div>' +
22
+ '</div>';
23
+ },
24
+
25
+ /**
26
+ * @method render
27
+ * @chainable
28
+ * @returns {ShortcodePreview}
29
+ */
30
+ render: function() {
31
+
32
+ var self = this;
33
+
34
+ // Render loading iFrame.
35
+ this.renderIFrame({
36
+ head: self.head,
37
+ body: self.getLoading(),
38
+ });
39
+
40
+ // Fetch shortcode preview.
41
+ // Render iFrame with shortcode preview.
42
+ this.fetchShortcode( function( response ) {
43
+ self.renderIFrame({
44
+ head: self.head,
45
+ body: response,
46
+ });
47
+ });
48
+
49
+ return this;
50
+ },
51
+
52
+ /**
53
+ * Render a child iframe, removing any previously rendered iframe. Additionally, observe the rendered iframe
54
+ * for mutations and resize as necessary to match content.
55
+ *
56
+ * @param params
57
+ */
58
+ renderIFrame: function( params ) {
59
+
60
+ var self = this, $iframe, resize;
61
+
62
+ _.defaults( params || {}, { 'head': '', 'body': '', 'body_classes': 'shortcake shortcake-preview' });
63
+
64
+ $iframe = $( '<iframe/>', {
65
+ src: tinymce.Env.ie ? 'javascript:""' : '',
66
+ frameBorder: '0',
67
+ allowTransparency: 'true',
68
+ scrolling: 'no',
69
+ style: "width: 100%; display: block",
70
+ } );
71
+
72
+ /**
73
+ * Render preview in iFrame once loaded.
74
+ * This is required because you can't write to
75
+ * an iFrame contents before it exists.
76
+ */
77
+ $iframe.load( function() {
78
+
79
+ self.autoresizeIframe( $(this) );
80
+
81
+ var head = $(this).contents().find('head'),
82
+ body = $(this).contents().find('body');
83
+
84
+ head.html( params.head );
85
+ body.html( params.body );
86
+ body.addClass( params.body_classes );
87
+
88
+ } );
89
+
90
+ this.$el.html( $iframe );
91
+
92
+ },
93
+
94
+ /**
95
+ * Watch for mutations in iFrame content.
96
+ * resize iFrame height on change.
97
+ *
98
+ * @param jQuery object $iframe
99
+ */
100
+ autoresizeIframe: function( $iframe ) {
101
+
102
+ var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
103
+
104
+ // Resize iFrame to size inner document.
105
+ var resize = function() {
106
+ $iframe.height( $iframe.contents().find('html').height() );
107
+ };
108
+
109
+ resize();
110
+
111
+ if ( MutationObserver ) {
112
+
113
+ var observer = new MutationObserver( function() {
114
+ resize();
115
+ $iframe.contents().find('img,link').load( resize );
116
+ } );
117
+
118
+ observer.observe(
119
+ $iframe.contents()[0],
120
+ { attributes: true, childList: true, subtree: true }
121
+ );
122
+
123
+ } else {
124
+
125
+ for ( i = 1; i < 6; i++ ) {
126
+ setTimeout( resize, i * 700 );
127
+ }
128
+
129
+ }
130
+
131
+ },
132
+
133
+
134
+ /**
135
+ * Makes an AJAX call to the server to render the shortcode based on user supplied attributes. Server-side
136
+ * rendering is necessary to allow for shortcodes that incorporate external content based on shortcode
137
+ * attributes.
138
+ *
139
+ * @method fetchShortcode
140
+ * @returns {String} Rendered shortcode markup (HTML).
141
+ */
142
+ fetchShortcode: function( callback ) {
143
+
144
+ wp.ajax.post( 'do_shortcode', {
145
+ post_id: $( '#post_ID' ).val(),
146
+ shortcode: this.model.formatShortcode(),
147
+ nonce: shortcodeUIData.nonces.preview,
148
+ }).done( function( response ) {
149
+ callback( response );
150
+ }).fail( function() {
151
+ callback( '<span class="shortcake-error">' + shortcodeUIData.strings.mce_view_error + '</span>' );
152
+ } );
153
+
154
+ },
155
+
156
+ /**
157
+ * Returns an array of <link> tags for stylesheets applied to the TinyMCE editor.
158
+ *
159
+ * @method getEditorStyles
160
+ * @returns {Array}
161
+ */
162
+ getEditorStyles: function() {
163
+ var styles = {};
164
+
165
+ _.each( tinymce.editors, function( editor ) {
166
+ _.each( editor.dom.$( 'link[rel="stylesheet"]', editor.getDoc().head ), function( link ) {
167
+ var href;
168
+ ( href = link.href ) && ( styles[href] = true ); // Poor man's de-duping.
169
+ });
170
+ });
171
+
172
+ styles = _.map( _.keys( styles ), function( href ) {
173
+ return $( '<link rel="stylesheet" type="text/css">' ).attr( 'href', href )[0].outerHTML;
174
+ });
175
+
176
+ return styles;
177
+ }
178
+ });
179
+
180
+ module.exports = ShortcodePreview;
js/views/shortcode-ui.js ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var Backbone = require('backbone'),
2
+ insertShortcodeList = require('sui-views/insert-shortcode-list'),
3
+ TabbedView = require('sui-views/tabbed-view'),
4
+ ShortcodePreview = require('sui-views/shortcode-preview'),
5
+ EditShortcodeForm = require('sui-views/edit-shortcode-form'),
6
+ Toolbar = require('sui-views/media-toolbar'),
7
+ SearchShortcode = require('sui-views/search-shortcode'),
8
+ sui = require('sui-utils/sui');
9
+ $ = require('jquery');
10
+
11
+ var Shortcode_UI = Backbone.View.extend({
12
+
13
+ events: {
14
+ "click .add-shortcode-list li": "select",
15
+ "click .edit-shortcode-form-cancel": "cancelSelect"
16
+ },
17
+
18
+ initialize: function(options) {
19
+ this.controller = options.controller.state();
20
+ //toolbar model looks for controller.state()
21
+ this.toolbar_controller = options.controller;
22
+ },
23
+
24
+ createToolbar: function(options) {
25
+ toolbarOptions = {
26
+ controller: this.toolbar_controller
27
+ }
28
+
29
+ this.toolbar = new Toolbar( toolbarOptions );
30
+
31
+ this.views.add( this.toolbar );
32
+
33
+ this.toolbar.set( 'search', new SearchShortcode({
34
+ controller: this.controller,
35
+ model: this.controller.props,
36
+ shortcodeList: this.shortcodeList,
37
+ priority: 60
38
+ }).render() );
39
+
40
+ },
41
+
42
+ render: function() {
43
+
44
+ this.$el.html('');
45
+
46
+ switch( this.controller.props.get('action') ) {
47
+ case 'select' :
48
+ this.renderSelectShortcodeView();
49
+ break;
50
+ case 'update' :
51
+ case 'insert' :
52
+ this.renderEditShortcodeView();
53
+ break;
54
+ }
55
+
56
+ },
57
+
58
+ renderSelectShortcodeView: function() {
59
+ this.views.unset();
60
+ this.shortcodeList = new insertShortcodeList( { shortcodes: sui.shortcodes } );
61
+ this.createToolbar();
62
+ this.views.add('', this.shortcodeList);
63
+ },
64
+
65
+ renderEditShortcodeView: function() {
66
+ var shortcode = this.controller.props.get( 'currentShortcode' );
67
+ var view = new TabbedView({
68
+ tabs: {
69
+ edit: {
70
+ label: shortcodeUIData.strings.edit_tab_label,
71
+ content: new EditShortcodeForm({ model: shortcode })
72
+ },
73
+
74
+ preview: {
75
+ label: shortcodeUIData.strings.preview_tab_label,
76
+ content: new ShortcodePreview({ model: shortcode }),
77
+ open: function() {
78
+ this.render();
79
+ }
80
+ }
81
+ },
82
+
83
+ styles: {
84
+ group: 'media-router edit-shortcode-tabs',
85
+ tab: 'media-menu-item edit-shortcode-tab'
86
+ }
87
+ });
88
+
89
+ this.$el.append( view.render().el );
90
+
91
+ if ( this.controller.props.get('action') === 'update' ) {
92
+ this.$el.find( '.edit-shortcode-form-cancel' ).remove();
93
+ }
94
+
95
+ return this;
96
+
97
+ },
98
+
99
+ cancelSelect: function( e ) {
100
+ e.preventDefault();
101
+
102
+ this.controller.props.set( 'action', 'select' );
103
+ this.controller.props.set( 'currentShortcode', null );
104
+ this.render();
105
+ },
106
+
107
+ select: function(e) {
108
+ this.controller.props.set( 'action', 'insert' );
109
+ var target = $(e.currentTarget).closest( '.shortcode-list-item' );
110
+ var shortcode = sui.shortcodes.findWhere( { shortcode_tag: target.attr( 'data-shortcode' ) } );
111
+
112
+ if ( ! shortcode ) {
113
+ return;
114
+ }
115
+
116
+ this.controller.props.set( 'currentShortcode', shortcode.clone() );
117
+
118
+ this.render();
119
+
120
+ },
121
+
122
+ });
123
+
124
+ module.exports = Shortcode_UI;
js/views/tabbed-view.js ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var Backbone = require('backbone');
2
+ var sui = require('sui-utils/sui');
3
+
4
+ /**
5
+ * Abstraction to manage tabbed content. Tab parameters (e.g., label) along with
6
+ * views for associated content are passed to initialize the tabbed view.
7
+ *
8
+ * @class TabbedView
9
+ * @constructor
10
+ * @extends Backbone.View
11
+ * @params [options]
12
+ * @params [options.tabs] {Object} A hash of key:value pairs, where each value
13
+ * is itself an object with the following properties:
14
+ *
15
+ * label: The label to display on the tab. content: The `Backbone.View`
16
+ * associated with the tab content.
17
+ */
18
+ var TabbedView = Backbone.View.extend({
19
+ template : wp.template('tabbed-view-base'),
20
+ tabs : {},
21
+
22
+ events : {
23
+ 'click [data-role="tab"]' : function(event) {
24
+ this.tabSwitcher(event);
25
+ }
26
+ },
27
+
28
+ initialize : function(options) {
29
+ Backbone.View.prototype.initialize.apply(this, arguments);
30
+
31
+ _.defaults(this.options = (options || {}), {
32
+ styles : {
33
+ group : '',
34
+ tab : ''
35
+ }
36
+ });
37
+
38
+ this.tabs = _.extend(this.tabs, options.tabs);
39
+ },
40
+
41
+ /**
42
+ * @method render
43
+ * @chainable
44
+ * @returns {TabbedView}
45
+ */
46
+ render : function() {
47
+ var $content;
48
+
49
+ this.$el.html(this.template({
50
+ tabs : this.tabs,
51
+ styles : this.options.styles
52
+ }));
53
+
54
+ $content = this.$('[data-role="tab-content"]');
55
+ $content.empty();
56
+
57
+ _.each(this.tabs, function(tab) {
58
+ var $el = tab.content.render().$el;
59
+ $el.hide();
60
+ $content.append($el);
61
+ });
62
+
63
+ this.select(0);
64
+
65
+ return this;
66
+ },
67
+
68
+ /**
69
+ * Switches tab when previewing or editing
70
+ */
71
+ tabSwitcher : function(event) {
72
+ event.stopPropagation();
73
+ event.preventDefault();
74
+
75
+ var target = $(event.currentTarget).attr('data-target');
76
+
77
+ this.select(target);
78
+ },
79
+
80
+ /**
81
+ * Programmatically select (activate) a specific tab. Used internally to
82
+ * process tab click events.
83
+ *
84
+ * @method select
85
+ * @param selector
86
+ * {number|string} The index (zero based) or key of the target
87
+ * tab.
88
+ */
89
+ select : function(selector) {
90
+ var index = 0;
91
+ var target = null;
92
+ var tab;
93
+
94
+ selector = selector || 0;
95
+
96
+ _.each(this.tabs, function(tab, key) {
97
+ tab.content.$el.hide();
98
+
99
+ if (selector === key || selector === index) {
100
+ target = key;
101
+ }
102
+
103
+ index = index + 1;
104
+ });
105
+
106
+ this.$('[data-role="tab"]').removeClass('active');
107
+
108
+ if (target) {
109
+ tab = this.tabs[target];
110
+
111
+ this.$('[data-role="tab"][data-target="' + target + '"]').addClass(
112
+ 'active');
113
+
114
+ tab.content.$el.show();
115
+ (typeof tab.open == 'function') && tab.open.call(tab.content);
116
+ }
117
+ }
118
+ });
119
+
120
+ sui.views.TabbedView = TabbedView;
121
+ module.exports = TabbedView;
languages/shortcode-ui-pt_PT.mo ADDED
Binary file
languages/shortcode-ui-pt_PT.po ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2015
2
+ # This file is distributed under the same license as the package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: \n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/shortcode-ui\n"
7
+ "POT-Creation-Date: 2015-02-17 17:16:53+00:00\n"
8
+ "PO-Revision-Date: 2015-02-17 17:17-0000\n"
9
+ "Last-Translator: WordPress Portugal <http;//wp-portugal.com>\n"
10
+ "Language-Team: \n"
11
+ "Language: pt_PT\n"
12
+ "MIME-Version: 1.0\n"
13
+ "Content-Type: text/plain; charset=UTF-8\n"
14
+ "Content-Transfer-Encoding: 8bit\n"
15
+ "X-Generator: Poedit 1.7.1\n"
16
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
+
18
+ #: inc/class-shortcode-ui.php:86 inc/class-shortcode-ui.php:87
19
+ msgid "Insert Post Element"
20
+ msgstr "Inserir elemento"
21
+
22
+ #: inc/class-shortcode-ui.php:88
23
+ msgid "Post Element Details"
24
+ msgstr "Detalhes do elemento"
25
+
26
+ #: inc/class-shortcode-ui.php:89
27
+ msgid "Insert Element"
28
+ msgstr "Inserir elemento"
29
+
30
+ #: inc/class-shortcode-ui.php:90
31
+ msgid "Update"
32
+ msgstr "Actualizar"
33
+
34
+ #: inc/class-shortcode-ui.php:91
35
+ msgid "Edit"
36
+ msgstr "Editar"
37
+
38
+ #: inc/class-shortcode-ui.php:92
39
+ msgid "Preview"
40
+ msgstr "Pré-visualizar"
41
+
42
+ #: inc/class-shortcode-ui.php:93
43
+ msgid "Failed to load preview"
44
+ msgstr "Erro ao carregar a pré-visualização"
45
+
46
+ #: inc/class-shortcode-ui.php:156
47
+ msgid "Something's rotten in the state of Denmark"
48
+ msgstr "Algo está podre no reino da Dinamarca"
49
+
50
+ #: inc/fields/class-field-attachment.php:47
51
+ #: inc/fields/class-field-attachment.php:48
52
+ msgid "Select Attachment"
53
+ msgstr "Escolha o anexo"
54
+
55
+ #: inc/templates/edit-form.tpl.php:3
56
+ msgid "Back to list"
57
+ msgstr "Voltar à lista"
58
+
59
+ #. Plugin Name of the plugin/theme
60
+ msgid "Shortcode UI"
61
+ msgstr "Shortcode UI"
62
+
63
+ #. Description of the plugin/theme
64
+ msgid "User Interface for adding shortcodes."
65
+ msgstr "Interface para adicionar shortcodes"
66
+
67
+ #. Author of the plugin/theme
68
+ msgid "Fusion Engineering and community"
69
+ msgstr "Fusion Engineering e a comunidade"
70
+
71
+ #. Author URI of the plugin/theme
72
+ msgid "http://next.fusion.net/tag/shortcode-ui/"
73
+ msgstr "http://next.fusion.net/tag/shortcode-ui/"
languages/shortcode-ui.pot ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2015 Fusion Engineering and community
2
+ # This file is distributed under the GPL v2 or later.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Shortcode UI v0.2.0-dev\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/shortcode-ui\n"
7
+ "POT-Creation-Date: 2015-03-18 14:20:37+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=utf-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "X-Generator: grunt-wp-i18n 0.5.0\n"
15
+ "X-Poedit-KeywordsList: "
16
+ "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_"
17
+ "attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
18
+ "Language: en\n"
19
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
20
+ "X-Poedit-Country: United States\n"
21
+ "X-Poedit-SourceCharset: UTF-8\n"
22
+ "X-Poedit-Basepath: ../\n"
23
+ "X-Poedit-SearchPath-0: .\n"
24
+ "X-Poedit-Bookmarks: \n"
25
+ "X-Textdomain-Support: yes\n"
26
+
27
+ #: inc/class-shortcode-ui.php:50
28
+ msgid "Inner Content"
29
+ msgstr ""
30
+
31
+ #: inc/class-shortcode-ui.php:123 inc/class-shortcode-ui.php:124
32
+ msgid "Insert Post Element"
33
+ msgstr ""
34
+
35
+ #: inc/class-shortcode-ui.php:125
36
+ msgid "Post Element Details"
37
+ msgstr ""
38
+
39
+ #: inc/class-shortcode-ui.php:126
40
+ msgid "Insert Element"
41
+ msgstr ""
42
+
43
+ #: inc/class-shortcode-ui.php:127
44
+ msgid "Update"
45
+ msgstr ""
46
+
47
+ #: inc/class-shortcode-ui.php:128
48
+ msgid "Edit"
49
+ msgstr ""
50
+
51
+ #: inc/class-shortcode-ui.php:129
52
+ msgid "Preview"
53
+ msgstr ""
54
+
55
+ #: inc/class-shortcode-ui.php:130
56
+ msgid "Failed to load preview"
57
+ msgstr ""
58
+
59
+ #: inc/class-shortcode-ui.php:131
60
+ msgid "Search"
61
+ msgstr ""
62
+
63
+ #: inc/class-shortcode-ui.php:218
64
+ msgid "Something's rotten in the state of Denmark"
65
+ msgstr ""
66
+
67
+ #: inc/fields/class-field-attachment.php:47
68
+ #: inc/fields/class-field-attachment.php:48
69
+ msgid "Select Attachment"
70
+ msgstr ""
71
+
72
+ #: inc/templates/edit-form.tpl.php:3
73
+ msgid "Back to list"
74
+ msgstr ""
75
+
76
+ #. Plugin Name of the plugin/theme
77
+ msgid "Shortcode UI"
78
+ msgstr ""
79
+
80
+ #. Description of the plugin/theme
81
+ msgid "User Interface for adding shortcodes."
82
+ msgstr ""
83
+
84
+ #. Author of the plugin/theme
85
+ msgid "Fusion Engineering and community"
86
+ msgstr ""
87
+
88
+ #. Author URI of the plugin/theme
89
+ msgid "http://next.fusion.net/tag/shortcode-ui/"
90
+ msgstr ""
package.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "shortcode-ui",
3
+ "version": "0.1.0",
4
+ "main": "Gruntfile.js",
5
+ "author": "Human Made Limited",
6
+ "license": "GPL V2",
7
+ "devDependencies": {
8
+ "browserify": "^8.1.3",
9
+ "browserify-shim": "^3.8.3",
10
+ "grunt": "^0.4.5",
11
+ "grunt-browserify": "^3.4.0",
12
+ "grunt-contrib-jasmine": "^0.8.2",
13
+ "grunt-contrib-jshint": "^0.11.0",
14
+ "grunt-contrib-watch": "^0.6.1",
15
+ "grunt-sass": "^0.18.0",
16
+ "grunt-wp-i18n": "^0.5.0",
17
+ "remapify": "1.4.3"
18
+ },
19
+ "browserify": {
20
+ "transform": [
21
+ "browserify-shim"
22
+ ]
23
+ },
24
+ "browserify-shim": {
25
+ "jquery": "global:jQuery",
26
+ "wp": "global:wp",
27
+ "underscore": "global:_",
28
+ "backbone": {
29
+ "exports": "global:Backbone",
30
+ "depends": [
31
+ "jquery",
32
+ "underscore"
33
+ ]
34
+ }
35
+ }
36
+ }
readme.txt ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Shortcake (Shortcode UI) ===
2
+ Contributors: mattheu, danielbachhuber, jitendraharpalani, sanchothefat, bfintal, davisshaver
3
+ Tags: shortcodes
4
+ Requires at least: 4.1
5
+ Tested up to: 4.2
6
+ Stable tag: 0.2.0
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Shortcake makes using WordPress shortcodes a piece of cake.
11
+
12
+ == Description ==
13
+
14
+ Used alongside `add_shortcode`, Shortcake supplies a user-friendly interface for adding a shortcode to a post, and viewing and editing it from within the content editor.
15
+
16
+ See the [Github README](https://github.com/fusioneng/Shortcake/blob/master/README.md) for implementation notes. To report bugs or feature requests, [please use Github issues](https://github.com/fusioneng/Shortcake/issues).
17
+
18
+ == Installation ==
19
+
20
+ Shortcake can be installed like any other WordPress plugin. Once you've done so, [follow these integration steps](https://github.com/fusioneng/Shortcake#usage) to register UI for your shortcode.
21
+
22
+ == Screenshots ==
23
+
24
+ 1. Without Shortcake, shortcodes have a minimal UI.
25
+ 2. But with Shortcake, TinyMCE will render the shortcode in a TinyMCE view.
26
+ 3. And add a user-friendly UI to edit shortcode content and attributes.
27
+ 4. Add new shortcodes to your post through "Add Media".
28
+
29
+ == Changelog ==
30
+
31
+ = 0.2.0 (March 18, 2015) =
32
+
33
+ * JS abstracted using Browserify.
34
+ * Enhancements to "Add Post Element" UI: shortcodes sorted alphabetically; search based on label.
35
+ * Much easier to select shortcode previews that include iframes.
36
+ * WordPress 4.2 compatibility.
37
+ * Added color picker to list of potential fields.
38
+ * Bug fix: IE11 compatibility.
39
+ * Bug fix: Checkbox field can now be unchecked.
40
+ * [Full release notes](http://fusion.net/story/105889/shortcake-v0-2-0-js-abstraction-add-post-element-enhancements-inner-content-field/).
41
+
42
+ = 0.1.0 (December 23, 2014) =
43
+
44
+ * Supports all HTML5 input types for form fields.
45
+ * Shortcode preview tab within the editing experience.
46
+ * Re-labeled the UI around “Post Elements”, which is more descriptive than “Content Items.”
47
+ * Many bug fixes.
48
+ * [Full release notes](http://next.fusion.net/2014/12/23/shortcake-v0-1-0-live-previews-fieldmanager-integration/).
49
+
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
screenshot-4.png ADDED
Binary file
shortcode-ui.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Shortcode UI
4
+ * Version: v0.2.0
5
+ * Description: User Interface for adding shortcodes.
6
+ * Author: Fusion Engineering and community
7
+ * Author URI: http://next.fusion.net/tag/shortcode-ui/
8
+ * Text Domain: shortcode-ui
9
+ * License: GPL v2 or later
10
+ *
11
+ * This program is free software; you can redistribute it and/or modify
12
+ * it under the terms of the GNU General Public License as published by
13
+ * the Free Software Foundation; either version 2 of the License, or
14
+ * (at your option) any later version.
15
+ *
16
+ * This program is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU General Public License for more details.
20
+ */
21
+
22
+ require_once dirname( __FILE__ ) . '/inc/class-shortcode-ui.php';
23
+ require_once dirname( __FILE__ ) . '/inc/fields/class-shortcode-ui-fields.php';
24
+ require_once dirname( __FILE__ ) . '/inc/fields/class-field-attachment.php';
25
+ require_once dirname( __FILE__ ) . '/inc/fields/class-field-color.php';
26
+
27
+ add_action( 'init', 'shortcode_ui_load_textdomain' );
28
+
29
+ add_action( 'init', function() {
30
+
31
+ $shortcode_ui = Shortcode_UI::get_instance();
32
+ $fields = Shortcode_UI_Fields::get_instance();
33
+ $attachment_field = Shortcake_Field_Attachment::get_instance();
34
+ $color_field = Shortcake_Field_Color::get_instance();
35
+
36
+ }, 5 );
37
+
38
+ /**
39
+ * Load translations
40
+ *
41
+ * @return null
42
+ */
43
+ function shortcode_ui_load_textdomain() {
44
+ load_plugin_textdomain( 'shortcode-ui', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
45
+ }
46
+
47
+ /**
48
+ * Register UI for Shortcode
49
+ *
50
+ * @param string $shortcode_tag
51
+ * @param array $args
52
+ * @return null
53
+ */
54
+ function shortcode_ui_register_for_shortcode( $shortcode_tag, $args = array() ) {
55
+ Shortcode_UI::get_instance()->register_shortcode_ui( $shortcode_tag, $args );
56
+ }
57
+
58
+ /**
59
+ * Get register UI args by shortcode tag
60
+ *
61
+ * @param string $shortcode_tag
62
+ * @param array $args
63
+ * @return null
64
+ */
65
+ function shortcode_ui_get_register_shortcode( $shortcode_tag, $args = array() ) {
66
+ return Shortcode_UI::get_instance()->get_shortcode( $shortcode_tag );
67
+ }
68
+
69
+ /**
70
+ * Queue the shortcode UI scripts & templates manually
71
+ */
72
+ function shortcode_ui_enqueue_assets() {
73
+ Shortcode_UI::get_instance()->enqueue();
74
+ }