@@ -12,7 +12,7 @@ var fm_show_post_type = function( $element, post_type ) {
1212var fm_show_post_date = function ( $element , post_date ) {
1313 if ( $element . data ( 'showPostDate' ) == 1 ) {
1414 $element . parent ( ) . siblings ( '.fmjs-post-date' ) . remove ( ) ;
15- $element . parent ( ) . siblings ( ".fmjs-remove, .fmjs-clear" ) . after ( '<div class="fmjs-post-date">' + post_date + '</div>' ) ;
15+ $element . parent ( ) . siblings ( ".fmjs-remove, .fmjs-clear" ) . after ( '<div class="fmjs-post-date">' + post_date + '</div>' ) ;
1616 }
1717}
1818
@@ -35,47 +35,47 @@ var fm_typeahead_action = function( $element ) {
3535 } ) ;
3636 }
3737 } ,
38- updater : function ( item ) {
38+ updater : function ( item ) {
3939 // Get the post ID and post type and store them in data attributes
4040 $element . data ( 'id' , fm_typeahead_results [ item ] [ 'id' ] ) ;
4141 $element . data ( 'postType' , fm_typeahead_results [ item ] [ 'post_type' ] ) ;
4242 $element . data ( 'postDate' , fm_typeahead_results [ item ] [ 'post_date' ] ) ;
43-
43+
4444 // If the clear handle is enabled, show it
4545 $element . parent ( ) . siblings ( '.fmjs-clear' ) . show ( ) ;
46-
46+
4747 // Show the selected post type and/or date after the clear/remove handle
4848 fm_show_post_type ( $element , fm_typeahead_results [ item ] [ 'post_type' ] ) ;
4949 fm_show_post_date ( $element , fm_typeahead_results [ item ] [ 'post_date' ] ) ;
50-
50+
5151 // Trigger that the update happened in case any other functions want to execute something here
5252 $element . trigger ( 'fm_post_update' , [ item , fm_typeahead_results [ item ] ] ) ;
53-
53+
5454 // Remove the post type and/or date from the title and return the title for the text field
5555 return fm_typeahead_results [ item ] [ 'post_title' ] ;
5656 } ,
5757 items :5
5858 } ) ;
5959}
6060
61- $ ( document ) . ready ( function ( ) {
61+ function fm_post_init ( ) {
6262 $ ( '.fm-post-element' ) . each ( function ( index ) {
6363 // Enable typeahead for each post field
6464 fm_typeahead_action ( $ ( this ) ) ;
65-
65+
6666 // Show the post type, date and/or clear handle (if exists) if the field is not empty and those fields are specified for display
67- if ( $ ( this ) . data ( 'postType' ) != '' ) {
67+ if ( $ ( this ) . data ( 'postType' ) != '' ) {
6868 fm_show_post_type ( $ ( this ) , $ ( this ) . data ( 'postType' ) ) ;
6969 }
70-
71- if ( $ ( this ) . data ( 'postDate' ) != '' ) {
70+
71+ if ( $ ( this ) . data ( 'postDate' ) != '' ) {
7272 fm_show_post_date ( $ ( this ) , $ ( this ) . data ( 'postDate' ) ) ;
7373 }
74-
75- if ( $ ( this ) . data ( 'id' ) != '' ) {
74+
75+ if ( $ ( this ) . data ( 'id' ) != '' ) {
7676 $ ( this ) . parent ( ) . siblings ( '.fmjs-clear' ) . show ( ) ;
7777 }
78-
78+
7979 } ) ;
8080 $ ( "#post" ) . submit ( function ( e ) {
8181 $ ( '.fm-post-element' ) . each ( function ( index ) {
@@ -90,6 +90,8 @@ $( document ).ready( function () {
9090 $post_element = $ ( event . target ) . find ( '.fm-post-element' ) ;
9191 if ( $post_element . length != 0 ) fm_typeahead_action ( $post_element ) ;
9292 } ) ;
93- } ) ;
93+ }
94+
95+ fmLoadModule ( fm_post_init ) ;
9496
95- } ) ( jQuery ) ;
97+ } ) ( jQuery ) ;
0 commit comments