b83ad077 by Jeff Balicki

resources

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent 2566d956
1 .wp-admin .media-toolbar-secondary select {
2 margin: 11px 16px 0 0;
3 }
4
5 .media-term-section {
6 margin: 0 0 20px;
7 }
8
9 .media-terms {
10 background: #fff;
11 border: 1px solid #dfdfdf;
12 border-radius: 3px;
13 max-height: 145px;
14 overflow: auto;
15 padding: 6px 8px;
16 }
17
18 .wp-admin .media-terms label {
19 display: block;
20 }
21
22 .wp-admin .media-terms input[type="checkbox"] {
23 margin: 0 5px 0 0;
24 position: relative;
25 top: -1px;
26 width: auto;
27 }
28
29 .media-terms ul ul {
30 padding: 10px 0 5px 10px;
31 }
32
33 .media-terms ul li:last-child {
34 margin: 0;
35 }
36
37
38 .add-new-term {
39 display: none;
40 }
41
42 .media-save-terms {
43 position: relative;
44 }
45
46 .media-save-terms:before {
47 background: url( '../images/saving.gif ') no-repeat #fff;
48 content: '';
49 display: block;
50 height: 16px;
51 position: absolute;
52 right: 5px;
53 top: 5px;
54 width: 16px
55 }
56
57 .media-save-terms label {
58 opacity: .5
59 }
60
61 /* Add new media term */
62 .toggle-add-media-term {
63 display: inline-block;
64 margin: 5px 0;
65 }
66
67 .toggle-add-media-term:before {
68 content: '+ ';
69 }
70
71 .add-new-term {
72 margin: 0 0 5px;
73 }
74
1 jQuery(document).ready(function(){
2
3 var media = wp.media;
4
5 /*
6 // for debug : trace every event triggered in the Region controller
7 var originalTrigger = wp.media.view.MediaFrame.prototype.trigger;
8 wp.media.view.MediaFrame.prototype.trigger = function(){
9 console.log('MediaFrame Event: ', arguments[0]);
10 originalTrigger.apply(this, Array.prototype.slice.call(arguments));
11 }; //
12
13 // for Network debug
14 var originalAjax = media.ajax;
15 media.ajax = function( action ) {
16 console.log( 'media.ajax: action = ' + JSON.stringify( action ) );
17 return originalAjax.apply(this, Array.prototype.slice.call(arguments));
18 };
19 */
20
21 /**
22 * Extended Filters dropdown with taxonomy term selection values
23 */
24 if ( media ) {
25 jQuery.each(mediaTaxonomies,function(key,label){
26
27 media.view.AttachmentFilters[key] = media.view.AttachmentFilters.extend({
28 className: key,
29
30 createFilters: function() {
31 var filters = {};
32
33 _.each( mediaTerms[key] || {}, function( term ) {
34
35 var query = {};
36
37 query[key] = {
38 taxonomy: key,
39 term_id: parseInt( term.id, 10 ),
40 term_slug: term.slug
41 };
42
43 filters[ term.slug ] = {
44 text: term.label,
45 props: query
46 };
47 });
48
49 this.filters = filters;
50 }
51
52
53 });
54
55 /**
56 * Replace the media-toolbar with our own
57 */
58 var myDrop = media.view.AttachmentsBrowser;
59
60 media.view.AttachmentsBrowser = media.view.AttachmentsBrowser.extend({
61 createToolbar: function() {
62
63 media.model.Query.defaultArgs.filterSource = 'filter-media-taxonomies';
64
65 myDrop.prototype.createToolbar.apply(this,arguments);
66
67 this.toolbar.set( key, new media.view.AttachmentFilters[key]({
68 controller: this.controller,
69 model: this.collection.props,
70 priority: -80
71 }).render()
72 );
73 }
74 });
75
76 });
77 }
78
79 /* Save taxonomy */
80 jQuery('html').delegate( '.media-terms input', 'change', function(){
81
82 var obj = jQuery(this),
83 container = obj.parents('.media-terms'),
84 row = container.parent(),
85 data = {
86 action: 'save-media-terms',
87 term_ids: [],
88 attachment_id: container.data('id'),
89 taxonomy: container.data('taxonomy')
90 };
91
92 container.find('input:checked').each(function(){
93 data.term_ids.push( jQuery(this).val() );
94 });
95
96 row.addClass('media-save-terms');
97 container.find('input').prop('disabled', 'disabled');
98
99 jQuery.post( ajaxurl, data, function( response ){
100 row.removeClass('media-save-terms');
101 container.find('input').removeProp('disabled');
102 });
103
104 });
105
106 // Add new taxonomy
107 jQuery('html').delegate('.toggle-add-media-term', 'click', function(e){
108 e.preventDefault();
109 jQuery(this).parent().find('.add-new-term').toggle();
110 });
111
112 // Save new taxnomy
113 jQuery('html').delegate('.save-media-term', 'click', function(e){
114
115 var obj = jQuery(this),
116 termField = obj.parent().find('input'),
117 termParent = obj.parent().find('select'),
118 data = {
119 action: 'add-media-term',
120 attachment_id: obj.data('id'),
121 taxonomy: obj.data('taxonomy'),
122 parent: termParent.val(),
123 term: termField.val()
124 };
125
126 // No val
127 if ( '' == data.term ) {
128 termField.focus();
129 return;
130 }
131
132 jQuery.post(ajaxurl, data, function(response){
133
134 obj.parents('.field').find('.media-terms ul:first').html( response.checkboxes );
135 obj.parents('.field').find('select').replaceWith( response.selectbox );
136
137 console.log( response );
138
139 termField.val('');
140
141 }, 'json' );
142
143 });
144
145 });
1 msgid ""
2 msgstr ""
3 "Project-Id-Version: Media Taxonomies v1.0\n"
4 "Report-Msgid-Bugs-To: \n"
5 "POT-Creation-Date: \n"
6 "PO-Revision-Date: 2013-09-15 16:27:14+0000\n"
7 "Last-Translator: horttcore <me@horttcore.de>\n"
8 "Language-Team: \n"
9 "MIME-Version: 1.0\n"
10 "Content-Type: text/plain; charset=UTF-8\n"
11 "Content-Transfer-Encoding: 8bit\n"
12 "Plural-Forms: nplurals=2; plural=n != 1;\n"
13 "X-Generator: CSL v1.x\n"
14 "X-Poedit-Language: German\n"
15 "X-Poedit-Country: GERMANY\n"
16 "X-Poedit-SourceCharset: utf-8\n"
17 "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
18 "X-Poedit-Basepath: \n"
19 "X-Poedit-Bookmarks: \n"
20 "X-Poedit-SearchPath-0: .\n"
21 "X-Textdomain-Support: yes"
22
23 #: media-taxonomies.php:223
24 #@ default
25 msgctxt "taxonomy general name"
26 msgid "Categories"
27 msgstr ""
28
29 #: media-taxonomies.php:224
30 #@ default
31 msgctxt "taxonomy singular name"
32 msgid "Category"
33 msgstr ""
34
35 #: media-taxonomies.php:225
36 #@ default
37 msgid "Search Categories"
38 msgstr ""
39
40 #: media-taxonomies.php:226
41 #@ default
42 msgid "All Categories"
43 msgstr ""
44
45 #: media-taxonomies.php:227
46 #@ default
47 msgid "Parent Category"
48 msgstr ""
49
50 #: media-taxonomies.php:228
51 #@ default
52 msgid "Parent Category:"
53 msgstr ""
54
55 #: media-taxonomies.php:229
56 #@ default
57 msgid "Edit Category"
58 msgstr ""
59
60 #: media-taxonomies.php:230
61 #@ default
62 msgid "Update Category"
63 msgstr ""
64
65 #: media-taxonomies.php:231
66 #@ default
67 msgid "Add New Category"
68 msgstr ""
69
70 #: media-taxonomies.php:232
71 #@ default
72 msgid "New Category Name"
73 msgstr ""
74
75 #: media-taxonomies.php:233
76 #@ default
77 msgid "Categories"
78 msgstr ""
79
80 #: media-taxonomies.php:237
81 #@ media-taxonomies
82 msgctxt "Category Slug"
83 msgid "media-category"
84 msgstr "medien-kategorie"
85
86 #: media-taxonomies.php:245
87 #@ default
88 msgctxt "taxonomy general name"
89 msgid "Tags"
90 msgstr ""
91
92 #: media-taxonomies.php:246
93 #@ default
94 msgctxt "taxonomy singular name"
95 msgid "Tag"
96 msgstr ""
97
98 #: media-taxonomies.php:247
99 #@ default
100 msgid "Search Tags"
101 msgstr ""
102
103 #: media-taxonomies.php:248
104 #@ default
105 msgid "All Tags"
106 msgstr ""
107
108 #: media-taxonomies.php:249
109 #@ default
110 msgid "Parent Tag"
111 msgstr ""
112
113 #: media-taxonomies.php:250
114 #@ default
115 msgid "Parent Tag:"
116 msgstr ""
117
118 #: media-taxonomies.php:251
119 #@ default
120 msgid "Edit Tag"
121 msgstr ""
122
123 #: media-taxonomies.php:252
124 #@ default
125 msgid "Update Tag"
126 msgstr ""
127
128 #: media-taxonomies.php:253
129 #@ default
130 msgid "Add New Tag"
131 msgstr ""
132
133 #: media-taxonomies.php:254
134 #@ default
135 msgid "New Tag Name"
136 msgstr ""
137
138 #: media-taxonomies.php:255
139 #@ default
140 msgid "Tags"
141 msgstr ""
142
143 #: media-taxonomies.php:259
144 #@ media-taxonomies
145 msgctxt "Tag Slug"
146 msgid "media-tag"
147 msgstr "medien-schlagwort"
148
149 #: media-taxonomies.php:287
150 #, php-format
151 #@ media-taxonomies
152 msgctxt "%1$s = plural, %2$s = singular"
153 msgid "View all %s"
154 msgstr "Alle %s"
155
1 <?php
2 /*
3 Plugin Name: Media Taxonomies
4 Plugin URI: http://horttcore.de
5 Description: Taxononmies for media files
6 Version: 1.3.0
7 Author: Ralf Hortt
8 Author URI: http://horttcore.de
9 License: GPL2
10 */
11
12
13 /**
14 * Media_Taxonomies
15 */
16 class Media_Taxonomies
17 {
18
19
20
21 /** Refers to a single instance of this class. */
22 private static $instance = null;
23
24
25
26 /**
27 * Constructor
28 *
29 * @access public
30 * @since v0.9
31 * @author Ralf Hortt
32 */
33 public function __construct()
34 {
35
36 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_assets' ) );
37 add_action( 'admin_head', array( $this, 'admin_head' ) );
38 add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
39 add_action( 'init', array( $this, 'register_taxonomy' ) );
40 add_filter( 'manage_edit-attachment_sortable_columns', array( $this, 'manage_edit_attachment_sortable_columns' ) );
41 add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ), 0, 1 );
42 add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ) );
43 add_action( 'wp_ajax_save-media-terms', array( $this, 'save_media_terms' ), 0, 1 );
44 add_action( 'wp_ajax_add-media-term', array( $this, 'add_media_term' ), 0, 1 );
45 load_plugin_textdomain( 'media-taxonomies', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
46
47 } // end __construct
48
49
50
51 /**
52 * Add media term
53 * ajax callback
54 *
55 * @since v.1.3
56 * @author Ralf Hortt
57 **/
58 public function add_media_term()
59 {
60 $response = array();
61 $attachment_id = intval( $_REQUEST['attachment_id'] );
62 $taxonomy = get_taxonomy( sanitize_text_field( $_REQUEST['taxonomy'] ) );
63 $parent = ( intval( $_REQUEST['parent'] ) > 0 ) ? intval( $_REQUEST['parent'] ) : 0;
64
65 // Check if term already exists
66 $term = get_term_by( 'name', sanitize_text_field( $_REQUEST['term'] ), $taxonomy->name );
67
68 // No, so lets add it
69 if ( !$term ) :
70 $term = wp_insert_term( sanitize_text_field( $_REQUEST['term'] ), $taxonomy->name, array( 'parent' => $parent ) );
71 $term = get_term_by( 'id', $term['term_id'], $taxonomy->name );
72 endif;
73
74 // Connect attachment with term
75 wp_set_object_terms( $attachment_id, $term->term_id, $taxonomy->name, TRUE );
76
77 $attachment_terms = wp_get_object_terms( $attachment_id, $taxonomy->name, array(
78 'fields' => 'ids'
79 ));
80
81 ob_start();
82 wp_terms_checklist( 0, array(
83 'selected_cats' => $attachment_terms,
84 'taxonomy' => $taxonomy->name,
85 'checked_ontop' => FALSE
86 ));
87 $checklist = ob_get_contents();
88 ob_end_clean();
89
90 $response['checkboxes'] = $checklist;
91 $response['selectbox'] = wp_dropdown_categories( array(
92 'taxonomy' => $taxonomy->name,
93 'class' => 'parent-' . $taxonomy->name,
94 'id' => 'parent-' . $taxonomy->name,
95 'name' => 'parent-' . $taxonomy->name,
96 'show_option_none' => '- ' . $taxonomy->labels->parent_item . ' -',
97 'hide_empty' => FALSE,
98 'echo' => FALSE,
99 ) );
100
101 die( json_encode( $response ) );
102 }
103
104
105
106 /**
107 * Enqueue admin scripts and styles
108 *
109 * @access public
110 * @since v0.9
111 * @author Ralf Hortt
112 */
113 public function admin_enqueue_assets()
114 {
115
116 wp_enqueue_script( 'media-taxonomies', plugins_url( 'javascript/media-taxonomies.js', __FILE__ ), array( 'jquery' ) );
117 wp_enqueue_style( 'media-taxonomies', plugins_url( 'css/media-taxonomies.css', __FILE__ ) );
118
119 } // end admin_enqueue_assets
120
121
122
123 /**
124 * Add taxonomy information
125 *
126 * @access public
127 * @since v0.9
128 * @author Ralf Hortt
129 */
130 public function admin_head()
131 {
132
133 $taxonomies = apply_filters( 'media-taxonomies', get_object_taxonomies( 'attachment', 'objects' ) );
134
135 if ( !$taxonomies )
136 return;
137
138 $attachment_taxonomies = $attachment_terms = array();
139
140 foreach ( $taxonomies as $taxonomyname => $taxonomy ) :
141
142 $terms = get_terms( $taxonomy->name, array(
143 'orderby' => 'name',
144 'order' => 'ASC',
145 'hide_empty' => true,
146 ) );
147
148 if ( !$terms )
149 break;
150
151 $attachment_taxonomies[$taxonomy->name] = $taxonomy->labels->name;
152 $attachment_terms[ $taxonomy->name ][] = array( 'id' => 0, 'label' => __('All') . ' ' . $taxonomy->labels->name, 'slug' => '' );
153
154 foreach ( $terms as $term )
155 $attachment_terms[ $taxonomy->name ][] = array( 'id' => $term->term_id, 'label' => $term->name, 'slug' => $term->slug );
156
157 endforeach;
158
159
160 ?>
161 <script type="text/javascript">
162 var mediaTaxonomies = <?php echo json_encode( $attachment_taxonomies ) ?>,
163 mediaTerms = <?php echo json_encode( $attachment_terms ) ?>;
164 </script>
165 <?php
166
167 } // end admin_head
168
169
170
171 /**
172 * Add taxonomy checkboxes
173 *
174 * @access public
175 * @param array $fields Fields
176 * @param obj $post Post obj
177 * @return array Fields
178 * @since v0.9
179 * @author Ralf Hortt
180 */
181 public function attachment_fields_to_edit( $fields, $post )
182 {
183
184 $screen = get_current_screen();
185
186 if ( isset( $screen->id ) && 'attachment' == $screen->id )
187 return $fields;
188
189 $taxonomies = apply_filters( 'media-taxonomies', get_object_taxonomies( 'attachment', 'objects' ) );
190
191 if ( !$taxonomies )
192 return $fields;
193
194 foreach ( $taxonomies as $taxonomyname => $taxonomy ) :
195
196 $fields[$taxonomyname] = array(
197 'label' => $taxonomy->labels->singular_name,
198 'input' => 'html',
199 'html' => $this->terms_checkboxes( $taxonomy, $post->ID ),
200 // 'value' => '',
201 // 'helps' => '',
202 'show_in_edit' => true,
203 );
204
205 endforeach;
206
207 return $fields;
208
209 } // end attachment_fields_to_edit
210
211
212
213 /**
214 * Creates or returns an instance of this class.
215 *
216 * @access public
217 * @return A single instance of this class.
218 * @since v0.9
219 */
220 public static function get_instance() {
221
222 if ( null == self::$instance )
223 self::$instance = new self;
224
225 return self::$instance;
226
227 } // end get_instance;
228
229
230
231 /**
232 *
233 * Filter attachments in modal box
234 *
235 * @access public
236 * @since v0.9.1
237 * @author Ralf Hortt
238 */
239 public function pre_get_posts( $query )
240 {
241 if ( !isset( $query->query_vars['post_type'] ) || 'attachment' != $query->query_vars['post_type'] )
242 return;
243
244 $taxonomies = apply_filters( 'media-taxonomies', get_object_taxonomies( 'attachment', 'objects' ) );
245
246 if ( !$taxonomies )
247 return;
248
249 foreach ( $taxonomies as $taxonomyname => $taxonomy ) :
250
251 if ( isset( $_REQUEST['query'][$taxonomyname] ) && $_REQUEST['query'][$taxonomyname]['term_slug'] ) :
252 $query->set( $taxonomyname, $_REQUEST['query'][$taxonomyname]['term_slug'] );
253 elseif ( isset( $_REQUEST[$taxonomyname] ) && is_numeric( $_REQUEST[$taxonomyname] ) && 0 != intval( $_REQUEST[$taxonomyname] ) ) :
254 $term = get_term_by( 'id', $_REQUEST[$taxonomyname], $taxonomyname );
255 if ( is_object( $term ) )
256 set_query_var( $taxonomyname, $term->slug );
257 endif;
258
259 endforeach;
260
261 } // end pre_get_posts
262
263
264
265 /**
266 *
267 * Register taxonomy
268 *
269 * @access public
270 * @since v0.9
271 * @author Ralf Hortt
272 */
273 public function register_taxonomy()
274 {
275
276 register_taxonomy( 'media-category', array( 'attachment' ), array(
277 'hierarchical' => TRUE,
278 'labels' => array(
279 'name' => _x( 'Categories', 'taxonomy general name' ),
280 'singular_name' => _x( 'Category', 'taxonomy singular name' ),
281 'search_items' => __( 'Search Categories' ),
282 'all_items' => __( 'All Categories' ),
283 'parent_item' => __( 'Parent Category' ),
284 'parent_item_colon' => __( 'Parent Category:' ),
285 'edit_item' => __( 'Edit Category' ),
286 'update_item' => __( 'Update Category' ),
287 'add_new_item' => __( 'Add New Category' ),
288 'new_item_name' => __( 'New Category Name' ),
289 'menu_name' => __( 'Categories' ),
290 ),
291 'show_ui' => TRUE,
292 'query_var' => TRUE,
293 'rewrite' => array( 'slug' => _x( 'media-category', 'Category Slug', 'media-taxonomies' ) ),
294 'show_admin_column' => TRUE,
295 'update_count_callback' => '_update_generic_term_count',
296 ));
297
298 register_taxonomy( 'media-tag', array( 'attachment' ), array(
299 'hierarchical' => FALSE,
300 'labels' => array(
301 'name' => _x( 'Tags', 'taxonomy general name' ),
302 'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
303 'search_items' => __( 'Search Tags' ),
304 'all_items' => __( 'All Tags' ),
305 'parent_item' => __( 'Parent Tag' ),
306 'parent_item_colon' => __( 'Parent Tag:' ),
307 'edit_item' => __( 'Edit Tag' ),
308 'update_item' => __( 'Update Tag' ),
309 'add_new_item' => __( 'Add New Tag' ),
310 'new_item_name' => __( 'New Tag Name' ),
311 'menu_name' => __( 'Tags' ),
312 ),
313 'show_ui' => TRUE,
314 'query_var' => TRUE,
315 'rewrite' => array( 'slug' => _x( 'media-tag', 'Tag Slug', 'media-taxonomies' ) ),
316 'show_admin_column' => TRUE,
317 'update_count_callback' => '_update_generic_term_count',
318 ));
319
320 } // end register_taxonomy;
321
322
323
324 /**
325 * Add custom filters in attachment listing
326 *
327 * @access public
328 * @since v0.9
329 * @author Ralf Hortt
330 **/
331 public function restrict_manage_posts()
332 {
333
334 global $wp_query;
335
336 $taxonomies = apply_filters( 'media-taxonomies', get_object_taxonomies( 'attachment', 'objects' ) );
337
338 if ( !$taxonomies )
339 return;
340
341 foreach ( $taxonomies as $taxonomyname => $taxonomy ) :
342
343 wp_dropdown_categories( array(
344 'show_option_all' => sprintf( _x( 'View all %s', '%1$s = plural, %2$s = singular', 'media-taxonomies' ), $taxonomy->labels->name, $taxonomy->labels->singular_name ),
345 'taxonomy' => $taxonomyname,
346 'name' => $taxonomyname,
347 'orderby' => 'name',
348 'selected' => ( isset( $wp_query->query[$taxonomyname] ) ? $wp_query->query[$taxonomyname] : '' ),
349 'hierarchical' => TRUE,
350 'hide_empty' => TRUE,
351 'hide_if_empty' => TRUE,
352 ) );
353
354 endforeach;
355
356 } // end restrict_manage_posts
357
358
359
360 /**
361 * Save media terms
362 *
363 * @todo security nonce
364 * @since v0.9
365 * @author Ralf Hortt
366 */
367 public function save_media_terms()
368 {
369
370 $post_id = intval( $_REQUEST['attachment_id'] );
371
372 if ( !current_user_can( 'edit_post', $post_id ) )
373 die();
374
375 $term_ids = array_map( 'intval', $_REQUEST['term_ids'] );
376
377 $response = wp_set_post_terms( $post_id, $term_ids, sanitize_text_field( $_REQUEST['taxonomy'] ) );
378 wp_update_term_count_now( $term_ids, sanitize_text_field( $_REQUEST['taxonomy'] ) );
379
380 } // end save_media_terms
381
382
383
384 /**
385 * Create a terms box
386 *
387 * @access protected
388 * @param obj $taxonomy Taxonomy
389 * @return str HTML output
390 * @since v0.9
391 * @author Ralf Hortt
392 */
393 protected function terms_checkboxes( $taxonomy, $post_id )
394 {
395
396 if ( !is_object( $taxonomy ) ) :
397
398 $taxonomy = get_taxonomy( $taxonomy );
399
400 endif;
401
402 $terms = get_terms( $taxonomy->name, array(
403 'hide_empty' => FALSE,
404 ));
405
406 $attachment_terms = wp_get_object_terms( $post_id, $taxonomy->name, array(
407 'fields' => 'ids'
408 ));
409
410 ob_start();
411
412 ?>
413 <div class="media-term-section">
414
415 <div class="media-terms" data-id="<?php echo $post_id ?>" data-taxonomy="<?php echo $taxonomy->name ?>">
416
417 <ul>
418 <?php
419 wp_terms_checklist( 0, array(
420 'selected_cats' => $attachment_terms,
421 'taxonomy' => $taxonomy->name,
422 'checked_ontop' => FALSE
423 ));
424 ?>
425 </ul>
426
427 </div><!-- .media-terms -->
428
429 <a href="#" class="toggle-add-media-term"><?php echo $taxonomy->labels->add_new_item ?></a>
430
431 <div class="add-new-term">
432
433 <input type="text" value="">
434
435 <?php
436 if ( 1 == $taxonomy->hierarchical ) :
437 wp_dropdown_categories( array(
438 'taxonomy' => $taxonomy->name,
439 'class' => 'parent-' . $taxonomy->name,
440 'id' => 'parent-' . $taxonomy->name,
441 'name' => 'parent-' . $taxonomy->name,
442 'show_option_none' => '- ' . $taxonomy->labels->parent_item . ' -',
443 'hide_empty' => FALSE,
444 ) );
445 endif;
446 ?>
447
448 <button class="button save-media-term" data-taxonomy="<?php echo $taxonomy->name ?>" data-id="<?php echo $post_id ?>"><?php echo $taxonomy->labels->add_new_item ?></button>
449
450 </div><!-- .add-new-term -->
451
452 </div><!-- .media-term-section -->
453
454 <?php
455
456 $output = ob_get_contents();
457 ob_end_clean();
458
459 return apply_filters( 'media-checkboxes', $output, $taxonomy, $terms );
460
461 } // end terms_checkboxes
462
463
464
465 }
466
467
468 Media_Taxonomies::get_instance();
1 === Media Taxonomies ===
2 Contributors: Horttcore
3 Donate link: http://horttcore.de
4 Tags: media, taxonomies
5 Requires at least: 3.8
6 Tested up to: 4.0
7 Stable tag: 1.3.0
8 License: GPLv2 or later
9 License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
11 WordPress taxonomies for media files.
12
13 == Description ==
14
15 WordPress taxonomies for media files.
16 Plugin ships with media-category and media-tag taxonomy
17
18 == Installation ==
19
20 * Put the plugin file in your plugin directory and activate it in your WP backend.
21 * Go to your media library and add some categories
22
23 == FAQ ==
24
25 = Why does my term count not match if I add another taxonomy? =
26
27 This might be a failure in your register_taxanomy function.
28 You have to set `update_count_callback` to `_update_generic_term_count` in the taxonomy registration
29 Visit for more information http://codex.wordpress.org/Function_Reference/register_taxonomy
30
31 = I added another taxonomy for attachments, but don't want to use the features of this plugin. =
32
33 Ok, use the `media-taxonomies` hook to remove your taxonomy from the list
34
35 = Known Bugs =
36
37 * Registering a core taxonomy via `register_taxonomy_for_object_type( 'post_tag', 'attachment' )` won't work
38
39 == Screenshots ==
40
41 1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif). Note that the screenshot is taken from
42 the /assets directory or the directory that contains the stable readme.txt (tags or trunk). Screenshots in the /assets
43 directory take precedence. For example, `/assets/screenshot-1.png` would win over `/tags/4.3/screenshot-1.png`
44 (or jpg, jpeg, gif).
45 2. This is the second screen shot
46
47 == Changelog ==
48
49 = 1.3 =
50
51 * Add new terms functionality
52 * Small improvements
53
54 = 1.2.2 =
55
56 * Small improvements
57
58 = 1.2.1 =
59
60 * Enhancement: Modal select box label changed to use WordPress standard - props Dirk
61
62 = 1.2 =
63
64 * Bugfix: Media modal filter did not work, broke due last versions fix
65
66 = 1.1 =
67
68 * Bugfix: Media overview filter did not work
69
70 = 1.0 =
71
72 * Added integrated modal filter - props Wyck
73 * Added german language file
74
75 = 0.9.1 =
76
77 * Added modal filter
78
79 = 0.9 =
80
81 * Preview version
82
83 == ToDo ==
84
85 * implement wp.media like 'All' selection, this is currently achieved by a workaround
...@@ -15453,7 +15453,7 @@ label[for=quicksearch] { ...@@ -15453,7 +15453,7 @@ label[for=quicksearch] {
15453 background-color: #2C2C2C; 15453 background-color: #2C2C2C;
15454 } 15454 }
15455 15455
15456 .course-list .element-item { 15456 .course-list:not(.resources) .element-item {
15457 position: relative; 15457 position: relative;
15458 float: left; 15458 float: left;
15459 width: calc(33.33% - 30px); 15459 width: calc(33.33% - 30px);
...@@ -15462,6 +15462,15 @@ label[for=quicksearch] { ...@@ -15462,6 +15462,15 @@ label[for=quicksearch] {
15462 padding: 10px; 15462 padding: 10px;
15463 } 15463 }
15464 15464
15465 .course-list.resources .element-item {
15466 position: relative;
15467 float: left;
15468 width: 100%;
15469 height: 60px;
15470 margin: 15px;
15471 padding: 10px;
15472 }
15473
15465 .view-plan { 15474 .view-plan {
15466 width: 100%; 15475 width: 100%;
15467 text-align: center; 15476 text-align: center;
...@@ -15489,6 +15498,10 @@ label[for=quicksearch] { ...@@ -15489,6 +15498,10 @@ label[for=quicksearch] {
15489 display: none; 15498 display: none;
15490 } 15499 }
15491 15500
15501 .isotope-pager .pager {
15502 display: inline-block;
15503 }
15504
15492 .type-sfwd-courses { 15505 .type-sfwd-courses {
15493 margin-top: 30px; 15506 margin-top: 30px;
15494 } 15507 }
......
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
...@@ -11,6 +11,9 @@ include 'inc/menu-widgets.php'; ...@@ -11,6 +11,9 @@ include 'inc/menu-widgets.php';
11 include 'inc/blocks.php'; 11 include 'inc/blocks.php';
12 include 'inc/custom-post-type.php'; 12 include 'inc/custom-post-type.php';
13 include 'inc/shortcodes.php'; 13 include 'inc/shortcodes.php';
14 include 'inc/shortcodes-course.php';
15 include 'inc/shortcodes-resources.php';
16
14 17
15 18
16 /** 19 /**
......
1 <?php
2
3 add_shortcode('course-list', 'course_list');
4
5
6 function course_list(){
7
8 $custom_args = array(
9 'post_type' => 'sfwd-courses',
10 'posts_per_page' => -1,
11 'paged' => 1,
12 );
13 $custom_query = new \WP_Query($custom_args);
14
15 ob_start();
16 $uniqid = uniqid();
17 if ($custom_query->have_posts()):?>
18 <div class="course-list">
19 <label for="quicksearch">Search programs:</label><input type="text" id="quicksearch" placeholder="" />
20 <div class="filters">
21 <a href="#" id="filter-more">FILTERS <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></a>
22 <div class="filter-group">
23 <div class="category-filter-group">
24 <?php $terms = get_terms( array( 'taxonomy' => 'ld_course_category' ,'parent' => 0) );
25 foreach($terms as $term){ ?>
26 <div class="category-filter"> <input id="<?php echo $term->slug ; ?>" value=".<?php echo $term->slug ; ?>" type="checkbox" class="sr-only"><label for="<?php echo $term->slug ; ?>"><?php echo $term->name ; ?></label></div>
27 <?php }; ?>
28 </div>
29 <div class="btn-group sort-button-group align-self-end">
30 <button class="btn btn-light" data-sort-direction="asc" data-sort-value="coursename" type="button">Name <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button>
31 <button class="btn btn-light" data-sort-direction="asc" data-sort-value="coursedate" type="button">Date <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button>
32 </div>
33 </div>
34 </div>
35 <div class="grid course">
36 <?php while ($custom_query->have_posts()): $custom_query->the_post();
37 echo course_card(get_the_ID());
38 endwhile; ?>
39 </div>
40 </div>
41 <?php endif;
42 wp_reset_query();
43 $output = ob_get_clean();
44 return $output;
45 }
46
47
48
49 function course_card($id){
50
51 ob_start();
52 $post = get_post($id);
53 $text = str_replace(']]>', ']]&gt;', apply_filters( 'the_content', strip_shortcodes($post->post_content)));
54 $excerpt_length = apply_filters( 'excerpt_length', 20 );
55 $text = wp_trim_words( $text, $excerpt_length, ' ...' );
56 $categories = get_the_terms( $id, 'ld_course_category' );
57 $cat =""; foreach( $categories as $category ) { $cat .= " ".$category->slug; }; ?>
58
59 <div class="element-item <?php echo $cat; ?> " data-category="<?php echo $cat; ?>">
60 <article id="post-<?php echo $id; ?>" class="post post-<?php echo $id; ?> sfwd-courses type-sfwd-courses">
61 <div class="card">
62 <div class="thumbnail"><div class="ribbon"><?php echo get_post_meta( $id, '_learndash_course_grid_custom_ribbon_text', true);?></div>
63 <div class="image">
64 <?php echo get_the_post_thumbnail($id, 'full' ); ?>
65 </div>
66 </div>
67 <div class="content">
68 <h3 class="entry-title"><?php echo $post->post_title; ?></h3>
69 <div class="entry-content">
70 <p><?php echo $text; ?></p>
71 </div>
72 <a class="btn" role="button" href="<?php echo get_permalink($id); ?>" rel="bookmark">LEARN MORE</a>
73
74 </div>
75 </div>
76 </article>
77 </div>
78
79 <?php
80 $output = ob_get_clean();
81 return $output;
82 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 add_shortcode('resources-list', 'resources_list');
4
5
6 function resources_list(){
7
8 $custom_args = array(
9 'post_type' => 'attachment',
10 'posts_per_page' => -1,
11 'paged' => 1,
12 'post_status' => 'any',
13 );
14 $custom_query = new \WP_Query($custom_args);
15
16 ob_start();
17 $uniqid = uniqid();
18 if ($custom_query->have_posts()):
19 ?>
20 <div class="course-list resources">
21 <label for="quicksearch">Search programs:</label><input type="text" id="quicksearch" placeholder="" />
22 <div class="filters">
23 <a href="#" id="filter-more">FILTERS <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></a>
24 <div class="filter-group">
25 <div class="category-filter-group">
26 <?php $terms = get_terms( array( 'taxonomy' => 'media-category' ,'parent' => 17) );
27 foreach($terms as $term){ ?>
28 <div class="category-filter"> <input id="<?php echo $term->slug ; ?>" value=".<?php echo $term->slug ; ?>" type="checkbox" class="sr-only"><label for="<?php echo $term->slug ; ?>"><?php echo $term->name ; ?></label></div>
29 <?php }; ?>
30 <?php $terms = get_terms( array( 'taxonomy' => 'media-category' ,'parent' => 22) );
31 foreach($terms as $term){ ?>
32 <div class="category-filter"> <input id="<?php echo $term->slug ; ?>" value=".<?php echo $term->slug ; ?>" type="checkbox" class="sr-only"><label for="<?php echo $term->slug ; ?>"><?php echo $term->name ; ?></label></div>
33 <?php }; ?>
34 </div>
35 <div class="btn-group sort-button-group align-self-end">
36 <button class="btn btn-light" data-sort-direction="asc" data-sort-value="coursename" type="button">Name <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button>
37 <button class="btn btn-light" data-sort-direction="asc" data-sort-value="coursedate" type="button">Date <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button>
38 </div>
39 </div>
40 </div>
41 <div class="grid resources">
42 <?php while ($custom_query->have_posts()): $custom_query->the_post();
43
44 echo resources(get_the_ID());
45 endwhile; ?>
46 </div>
47 </div>
48 <?php endif;
49 wp_reset_query();
50 $output = ob_get_clean();
51 return $output;
52 }
53
54
55
56 function resources($id){
57
58 ob_start();
59 $post = get_post($id);
60 $categories = get_the_terms( $id, 'media-category' );
61 $cat ="";
62 if(is_array( $categories)){
63 foreach( $categories as $category ) { $cat .= " ".$category->slug; };
64 } ?>
65
66 <div class="table-like__item element-item <?php echo $cat; ?> " data-category="<?php echo $cat; ?>">
67 <a role="button" href="<?php echo get_permalink($id); ?>"><?php echo $post->post_title; ?></a><br>
68 <?php echo wp_get_attachment_caption($id) ?>
69 </div>
70 <?php
71 $output = ob_get_clean();
72 return $output;
73 }
...\ No newline at end of file ...\ No newline at end of file
...@@ -99,87 +99,3 @@ function share_this($atts){ ...@@ -99,87 +99,3 @@ function share_this($atts){
99 <?php 99 <?php
100 return ob_get_clean(); 100 return ob_get_clean();
101 } 101 }
102
103
104
105
106 add_shortcode('course-list', 'course_list');
107
108
109 function course_list(){
110
111 $custom_args = array(
112 'post_type' => 'sfwd-courses',
113 'posts_per_page' => -1,
114 'paged' => 1,
115 );
116 $custom_query = new \WP_Query($custom_args);
117
118 ob_start();
119 $uniqid = uniqid();
120 if ($custom_query->have_posts()):?>
121 <div class="course-list">
122 <label for="quicksearch">Search programs:</label><input type="text" id="quicksearch" placeholder="" />
123 <div class="filters">
124 <a href="#" id="filter-more">FILTERS <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></a>
125 <div class="filter-group">
126 <div class="category-filter-group">
127 <?php $terms = get_terms( array( 'taxonomy' => 'ld_course_category' ,'parent' => 0) );
128 foreach($terms as $term){ ?>
129 <div class="category-filter"> <input id="<?php echo $term->slug ; ?>" value=".<?php echo $term->slug ; ?>" type="checkbox" class="sr-only"><label for="<?php echo $term->slug ; ?>"><?php echo $term->name ; ?></label></div>
130 <?php }; ?>
131 </div>
132 <div class="btn-group sort-button-group align-self-end">
133 <button class="btn btn-light" data-sort-direction="asc" data-sort-value="coursename" type="button">Name <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button>
134 <button class="btn btn-light" data-sort-direction="asc" data-sort-value="coursedate" type="button">Date <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button>
135 </div>
136 </div>
137 </div>
138 <div class="grid">
139 <?php while ($custom_query->have_posts()): $custom_query->the_post();
140 echo course_card(get_the_ID());
141 endwhile; ?>
142 </div>
143 </div>
144 <?php endif;
145 wp_reset_query();
146 $output = ob_get_clean();
147 return $output;
148 }
149
150
151
152 function course_card($id){
153
154 ob_start();
155 $post = get_post($id);
156 $text = str_replace(']]>', ']]&gt;', apply_filters( 'the_content', strip_shortcodes($post->post_content)));
157 $excerpt_length = apply_filters( 'excerpt_length', 20 );
158 $text = wp_trim_words( $text, $excerpt_length, ' ...' );
159 $categories = get_the_terms( $id, 'ld_course_category' );
160 $cat =""; foreach( $categories as $category ) { $cat .= " ".$category->slug; }; ?>
161
162 <div class="element-item <?php echo $cat; ?> " data-category="<?php echo $cat; ?>">
163 <article id="post-<?php echo $id; ?>" class="post post-<?php echo $id; ?> sfwd-courses type-sfwd-courses">
164 <div class="card">
165 <div class="thumbnail"><div class="ribbon"><?php echo get_post_meta( $id, '_learndash_course_grid_custom_ribbon_text', true);?></div>
166 <div class="image">
167 <?php echo get_the_post_thumbnail($id, 'full' ); ?>
168 </div>
169 </div>
170 <div class="content">
171 <h3 class="entry-title"><?php echo $post->post_title; ?></h3>
172 <div class="entry-content">
173 <p><?php echo $text; ?></p>
174 </div>
175 <a class="btn" role="button" href="<?php echo get_permalink($id); ?>" rel="bookmark">LEARN MORE</a>
176
177 </div>
178 </div>
179 </article>
180 </div>
181
182 <?php
183 $output = ob_get_clean();
184 return $output;
185 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -17636,28 +17636,114 @@ ...@@ -17636,28 +17636,114 @@
17636 if ($('.grid').length) { 17636 if ($('.grid').length) {
17637 // quick search regex 17637 // quick search regex
17638 var qsRegex; 17638 var qsRegex;
17639 17639 if ($('.grid.course').length) {
17640 // init Isotope 17640 // init Isotope
17641 var $grid = $('.grid').isotope({ 17641 var $grid = $('.grid.course').isotope({
17642 itemSelector: '.element-item', 17642 itemSelector: '.element-item',
17643 layoutMode: 'fitRows', 17643 layoutMode: 'fitRows',
17644 getSortData: { 17644 getSortData: {
17645 coursename: '.name', 17645 coursename: '.name',
17646 date: '[data-ticks]' 17646 date: '[data-ticks]'
17647 }, 17647 },
17648 filter: function () { 17648 filter: function () {
17649 var $this = $(this); 17649 var $this = $(this);
17650 var filterText = qsRegex ? $(this).text().match(qsRegex) : true; 17650 var filterText = qsRegex ? $(this).text().match(qsRegex) : true;
17651 var buttonResult = filterValue ? $this.is(filterValue) : true; 17651 var buttonResult = filterValue ? $this.is(filterValue) : true;
17652 return filterText && buttonResult; 17652 return filterText && buttonResult;
17653 } 17653 }
17654 }); 17654 });
17655 }
17656 if ($('.grid.resources').length) {
17657 var $grid = $('.grid.resources').isotope({
17658 itemSelector: '.element-item',
17659 layoutMode: 'vertical',
17660 getSortData: {
17661 coursename: '.name',
17662 date: '[data-ticks]'
17663 },
17664 filter: function () {
17665 var $this = $(this);
17666 var filterText = qsRegex ? $(this).text().match(qsRegex) : true;
17667 var buttonResult = filterValue ? $this.is(filterValue) : true;
17668 return filterText && buttonResult;
17669 }
17670 });
17671 var itemsPerPageDefault = 5;
17672 var itemsPerPage = defineItemsPerPage();
17673 var itemSelector = '.element-item';
17674 var currentNumberPages = 1;
17675 var currentPage = 1;
17676 var currentFilter = '*';
17677 var filterAtribute = 'data-filter';
17678 var pageAtribute = 'data-page';
17679 var pagerClass = 'isotope-pager';
17680 setPagination();
17681 goToPage(1);
17682 }
17683 function changeFilter(selector) {
17684 $grid.isotope({
17685 filter: selector
17686 });
17687 }
17688 function getFilterSelector() {
17689 var selector = itemSelector;
17690 if (currentFilter != '*') {
17691 selector += `[${filterAtribute}~="${currentFilter}"]`;
17692 }
17693 return selector;
17694 }
17695 function goToPage(n) {
17696 currentPage = n;
17697 var selector = getFilterSelector();
17698 selector += `[${pageAtribute}="${currentPage}"]`;
17699 changeFilter(selector);
17700 }
17701 function defineItemsPerPage() {
17702 var pages = itemsPerPageDefault;
17703 return pages;
17704 }
17705 function setPagination() {
17706 (function () {
17707 $grid.children(itemSelector).length;
17708 var item = 1;
17709 var page = 1;
17710 var selector = getFilterSelector();
17711 $grid.children(selector).each(function () {
17712 if (item > itemsPerPage) {
17713 page++;
17714 item = 1;
17715 }
17716 $(this).attr(pageAtribute, page);
17717 item++;
17718 });
17719 currentNumberPages = page;
17720 })();
17721 (function () {
17722 var $isotopePager = $('.' + pagerClass).length == 0 ? $('<div class="' + pagerClass + '"></div>') : $('.' + pagerClass);
17723 $isotopePager.html('');
17724 for (var i = 0; i < currentNumberPages; i++) {
17725 var $pager = $('<a href="javascript:void(0);" class="pager" ' + pageAtribute + '="' + (i + 1) + '"></a>');
17726 $pager.html(i + 1);
17727 $pager.click(function () {
17728 var page = $(this).eq(0).attr(pageAtribute);
17729 goToPage(page);
17730 });
17731 $pager.appendTo($isotopePager);
17732 }
17733 $grid.after($isotopePager);
17734 })();
17735 }
17655 17736
17656 // use value of search field to filter 17737 // use value of search field to filter
17657 var $quicksearch = $('#quicksearch').keyup(debounce(function () { 17738 var $quicksearch = $('#quicksearch').keyup(debounce(function () {
17658 console.log($quicksearch.val()); 17739 console.log($quicksearch.val());
17659 qsRegex = new RegExp($quicksearch.val(), 'gi'); 17740 qsRegex = new RegExp($quicksearch.val(), 'gi');
17660 $grid.isotope(); 17741 $grid.isotope();
17742 updateFilterCounts();
17743 if ($('.grid.resources').length) {
17744 setPagination();
17745 goToPage(1);
17746 }
17661 }, 200)); 17747 }, 200));
17662 17748
17663 // debounce so filtering doesn't happen every millisecond 17749 // debounce so filtering doesn't happen every millisecond
...@@ -17734,59 +17820,60 @@ ...@@ -17734,59 +17820,60 @@
17734 } 17820 }
17735 $grid.isotope('layout'); 17821 $grid.isotope('layout');
17736 } 17822 }
17823 if ($('.grid.course').length) {
17824 //****************************
17825 // Isotope Load more button
17826 //****************************
17827
17828 var initShow = 3; //number of images loaded on init & onclick load more button
17829 var counter = initShow; //counter for load more button
17830 var iso = $grid.data('isotope'); // get Isotope instance
17831 console.log('iso');
17832 console.log(iso);
17833 console.log(iso.elemCount);
17834 loadMore(initShow); //execute function onload
17835
17836 function loadMore(toShow) {
17837 $grid.find(".hidden").removeClass("hidden");
17838 var hiddenElems = iso.filteredItems.slice(toShow, iso.filteredItems.length).map(function (item) {
17839 console.log('hiddenElem');
17840 console.log(item.element);
17841 return item.element;
17842 });
17843 $(hiddenElems).addClass('hidden');
17844 $grid.isotope('layout');
17737 17845
17738 //**************************** 17846 //when no more to load, hide show more button
17739 // Isotope Load more button 17847 if (hiddenElems.length == 0) {
17740 //**************************** 17848 $("#load-more").hide();
17741 17849 } else {
17742 var initShow = 3; //number of images loaded on init & onclick load more button 17850 $("#load-more").show();
17743 var counter = initShow; //counter for load more button 17851 }
17744 var iso = $grid.data('isotope'); // get Isotope instance
17745 console.log('iso');
17746 console.log(iso);
17747 console.log(iso.elemCount);
17748 loadMore(initShow); //execute function onload
17749
17750 function loadMore(toShow) {
17751 $grid.find(".hidden").removeClass("hidden");
17752 var hiddenElems = iso.filteredItems.slice(toShow, iso.filteredItems.length).map(function (item) {
17753 console.log('hiddenElem');
17754 console.log(item.element);
17755 return item.element;
17756 });
17757 $(hiddenElems).addClass('hidden');
17758 $grid.isotope('layout');
17759
17760 //when no more to load, hide show more button
17761 if (hiddenElems.length == 0) {
17762 $("#load-more").hide();
17763 } else {
17764 $("#load-more").show();
17765 } 17852 }
17766 }
17767 17853
17768 //append load more button 17854 //append load more button
17769 $grid.after('<div class="view-plan"><a class="btn" href="#" id="load-more">LOAD MORE programs</a></div>'); 17855 $grid.after('<div class="view-plan"><a class="btn" href="#" id="load-more">LOAD MORE programs</a></div>');
17770 17856
17771 //when load more button clicked 17857 //when load more button clicked
17772 $(document).on("click", "#load-more", function (e) { 17858 $(document).on("click", "#load-more", function (e) {
17773 e.preventDefault(); 17859 e.preventDefault();
17774 if ($('#filters').data('clicked')) { 17860 if ($('#filters').data('clicked')) {
17775 //when filter button clicked, set initial value for counter 17861 //when filter button clicked, set initial value for counter
17776 counter = initShow; 17862 counter = initShow;
17777 j$('#filters').data('clicked', false); 17863 j$('#filters').data('clicked', false);
17778 } else { 17864 } else {
17779 counter = counter; 17865 counter = counter;
17780 } 17866 }
17781 counter = counter + initShow; 17867 counter = counter + initShow;
17782 loadMore(counter); 17868 loadMore(counter);
17783 }); 17869 });
17784 $(document).on("click", "#filter-more", function (e) { 17870 $(document).on("click", "#filter-more", function (e) {
17785 e.preventDefault(); 17871 e.preventDefault();
17786 $('.filter-group').toggleClass('open'); 17872 $('.filter-group').toggleClass('open');
17787 var span = $(this).find('.glyphicon'); 17873 var span = $(this).find('.glyphicon');
17788 span.toggleClass('glyphicon-chevron-up glyphicon-chevron-down'); 17874 span.toggleClass('glyphicon-chevron-up glyphicon-chevron-down');
17789 }); 17875 });
17876 }
17790 } 17877 }
17791 }); 17878 });
17792 17879
......
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
...@@ -7,27 +7,145 @@ jQueryBridget( 'isotope', Isotope, $ ); ...@@ -7,27 +7,145 @@ jQueryBridget( 'isotope', Isotope, $ );
7 jQuery( document ).ready(function($) { 7 jQuery( document ).ready(function($) {
8 8
9 9
10
10 if($('.grid').length){ 11 if($('.grid').length){
11 12
12 13
13 // quick search regex 14 // quick search regex
14 var qsRegex; 15 var qsRegex;
15 16 if($('.grid.course').length){
16 // init Isotope 17 // init Isotope
17 var $grid = $('.grid').isotope({ 18 var $grid = $('.grid.course').isotope({
18 itemSelector: '.element-item', 19 itemSelector: '.element-item',
19 layoutMode: 'fitRows', 20 layoutMode: 'fitRows',
20 getSortData: { 21 getSortData: {
21 coursename: '.name', 22 coursename: '.name',
22 date: '[data-ticks]', 23 date: '[data-ticks]',
23 }, 24 },
24 filter: function() { 25 filter: function() {
25 var $this = $(this); 26 var $this = $(this);
26 var filterText = qsRegex ? $(this).text().match( qsRegex ) : true; 27 var filterText = qsRegex ? $(this).text().match( qsRegex ) : true;
27 var buttonResult = filterValue ? $this.is( filterValue ) : true; 28 var buttonResult = filterValue ? $this.is( filterValue ) : true;
28 return filterText && buttonResult; 29 return filterText && buttonResult;
30 }
31 });
32 }
33
34 if($('.grid.resources').length){
35
36 var $grid = $('.grid.resources').isotope({
37 itemSelector: '.element-item',
38 layoutMode: 'vertical',
39 getSortData: {
40 coursename: '.name',
41 date: '[data-ticks]',
42 },
43 filter: function() {
44 var $this = $(this);
45 var filterText = qsRegex ? $(this).text().match( qsRegex ) : true;
46 var buttonResult = filterValue ? $this.is( filterValue ) : true;
47 return filterText && buttonResult;
48 }
49 });
50
51 var itemsPerPageDefault = 5;
52 var itemsPerPage = defineItemsPerPage();
53 var itemSelector = '.element-item';
54 var currentNumberPages = 1;
55 var currentPage = 1;
56 var currentFilter = '*';
57 var filterAtribute = 'data-filter';
58 var pageAtribute = 'data-page';
59 var pagerClass = 'isotope-pager';
60
61 setPagination();
62 goToPage(1);
63
64 var responsiveIsotope = [
65 [480, 4],
66 [720, 6]
67 ];
68
69 }
70
71 function changeFilter(selector) {
72 $grid.isotope({
73 filter: selector
74 });
75 }
76
77 function getFilterSelector() {
78 var selector = itemSelector;
79 if (currentFilter != '*') {
80 selector += `[${filterAtribute}~="${currentFilter}"]`
29 } 81 }
30 }); 82 return selector;
83 }
84
85
86 function goToPage(n) {
87 currentPage = n;
88
89 var selector = getFilterSelector();
90 selector += `[${pageAtribute}="${currentPage}"]`;
91
92 changeFilter(selector);
93 }
94
95 function defineItemsPerPage() {
96 var pages = itemsPerPageDefault;
97
98 return pages;
99 }
100
101 function setPagination() {
102
103 var SettingsPagesOnItems = function(){
104
105 var itemsLength = $grid.children(itemSelector).length;
106
107 var pages = Math.ceil(itemsLength / itemsPerPage);
108 var item = 1;
109 var page = 1;
110 var selector = getFilterSelector();
111
112 $grid.children(selector).each(function(){
113 if( item > itemsPerPage ) {
114 page++;
115 item = 1;
116 }
117 $(this).attr(pageAtribute, page);
118 item++;
119 });
120
121 currentNumberPages = page;
122
123 }();
124
125 var CreatePagers = function() {
126
127 var $isotopePager = ( $('.'+pagerClass).length == 0 ) ? $('<div class="'+pagerClass+'"></div>') : $('.'+pagerClass);
128
129 $isotopePager.html('');
130
131 for( var i = 0; i < currentNumberPages; i++ ) {
132 var $pager = $('<a href="javascript:void(0);" class="pager" '+pageAtribute+'="'+(i+1)+'"></a>');
133 $pager.html(i+1);
134
135 $pager.click(function(){
136 var page = $(this).eq(0).attr(pageAtribute);
137 goToPage(page);
138 });
139
140 $pager.appendTo($isotopePager);
141 }
142
143 $grid.after($isotopePager);
144
145 }();
146
147 }
148
31 149
32 150
33 151
...@@ -36,6 +154,11 @@ var $quicksearch = $('#quicksearch').keyup( debounce( function() { ...@@ -36,6 +154,11 @@ var $quicksearch = $('#quicksearch').keyup( debounce( function() {
36 console.log($quicksearch.val()); 154 console.log($quicksearch.val());
37 qsRegex = new RegExp( $quicksearch.val(), 'gi' ); 155 qsRegex = new RegExp( $quicksearch.val(), 'gi' );
38 $grid.isotope(); 156 $grid.isotope();
157 updateFilterCounts();
158 if($('.grid.resources').length){
159 setPagination();
160 goToPage(1);
161 }
39 }, 200 ) ); 162 }, 200 ) );
40 163
41 // debounce so filtering doesn't happen every millisecond 164 // debounce so filtering doesn't happen every millisecond
...@@ -126,7 +249,7 @@ function updateFilterCounts() { ...@@ -126,7 +249,7 @@ function updateFilterCounts() {
126 } 249 }
127 250
128 251
129 252 if($('.grid.course').length){
130 253
131 //**************************** 254 //****************************
132 // Isotope Load more button 255 // Isotope Load more button
...@@ -191,4 +314,6 @@ function updateFilterCounts() { ...@@ -191,4 +314,6 @@ function updateFilterCounts() {
191 }); 314 });
192 315
193 } 316 }
317
318 }
194 }); 319 });
......
...@@ -223,7 +223,7 @@ label[for=quicksearch]{ ...@@ -223,7 +223,7 @@ label[for=quicksearch]{
223 223
224 224
225 225
226 .course-list{ 226 .course-list:not(.resources){
227 .element-item { 227 .element-item {
228 position: relative; 228 position: relative;
229 float: left; 229 float: left;
...@@ -234,6 +234,17 @@ label[for=quicksearch]{ ...@@ -234,6 +234,17 @@ label[for=quicksearch]{
234 } 234 }
235 } 235 }
236 236
237 .course-list.resources{
238 .element-item {
239 position: relative;
240 float: left;
241 width: 100%;
242 height: 60px;
243 margin: 15px;
244 padding: 10px;
245 }
246 }
247
237 248
238 .view-plan{ 249 .view-plan{
239 width: 100%; 250 width: 100%;
...@@ -259,4 +270,10 @@ label[for=quicksearch]{ ...@@ -259,4 +270,10 @@ label[for=quicksearch]{
259 margin:0px!important; 270 margin:0px!important;
260 padding:0px!important; 271 padding:0px!important;
261 display:none; 272 display:none;
262 }
...\ No newline at end of file ...\ No newline at end of file
273 }
274
275
276 .isotope-pager .pager {
277 display: inline-block;
278 }
279
...\ No newline at end of file ...\ No newline at end of file
......