11//* TITLE Shorten Posts **//
2- //* VERSION 0.2.4 **//
2+ //* VERSION 0.2.5 **//
33//* DESCRIPTION Makes scrolling easier **//
4- //* DETAILS This extension shortens long posts, so if you are interested, you can just click on Show Full Post button to see it all, or scroll down if you are not interested. Useful for screens where long posts take a lot of space, and making it hard to scroll down.<br><br>By default, this extension shortens text posts. You can toggle settings to choose which types of posts to shorten. (This will 'cut off' long, vertical posts.) **//
4+ //* DETAILS This extension shortens long posts, so if you are interested, you can just click on Show Full Post button to see it all, or scroll down if you are not interested. Useful for screens where long posts take a lot of space, and making it hard to scroll down. **//
55//* DEVELOPER STUDIOXENIX **//
66//* FRAME false **//
77//* BETA false **//
@@ -17,163 +17,105 @@ XKit.extensions.shorten_posts = new Object({
1717 height_default : 350 ,
1818
1919 preferences : {
20- sep0 : {
21- text : "When to shorten posts" ,
22- type : "separator"
23- } ,
24- text_too : {
25- text : "Check and shorten text posts" ,
26- default : true ,
27- value : true
28- } ,
29- photos_too : {
30- text : "Check and shorten photo posts and photosets" ,
31- default : false ,
32- value : false
33- } ,
34- audio_too : {
35- text : "Check and shorten audio posts" ,
36- default : false ,
37- value : false
38- } ,
39- asks_too : {
40- text : "Check and shorten replies to asks" ,
41- default : false ,
42- value : false
43- } ,
44- videos_too : {
45- text : "Check and shorten video posts" ,
46- default : false ,
47- value : false
48- } ,
49- chat_too : {
50- text : "Check and shorten chat posts" ,
51- default : false ,
52- value : false
53- } ,
54- links_too : {
55- text : "Check and shorten link posts" ,
56- default : false ,
57- value : false
58- } ,
59- quotes_too : {
60- text : "Check and shorten quote posts" ,
61- default : false ,
62- value : false
63- } ,
6420 height : {
6521 text : "Maximum post height (<a id=\"xkit-shorten-posts-height-help\" href=\"#\" onclick=\"return false\">what is this?</a>)" ,
6622 type : "text" ,
6723 default : "350" ,
6824 value : "350"
6925 } ,
70- sep1 : {
71- text : "Appearance and behaviour options" ,
72- type : "separator"
73- } ,
7426 display_tags : {
7527 text : "Display the tags on shortened posts" ,
7628 default : true ,
7729 value : true
78- } ,
79- embiggen_on_click : {
80- text : "Embiggen photo posts when I click on the thumbnail" ,
81- default : true ,
82- value : true
8330 }
8431 } ,
8532
33+ tagsCss : null ,
34+ wrapperCss : null ,
35+ avatarCss : null ,
36+ processing : false ,
37+
8638 run : function ( ) {
8739
8840 this . running = true ;
8941 XKit . extensions . shorten_posts . cpanel_check_height ( ) ;
9042
91- if ( $ ( ".posts .post" ) . length > 0 ) {
43+ if ( $ ( "[data-id], .posts .post" ) . length > 0 ) {
9244 XKit . tools . init_css ( "shorten_posts" ) ;
93- $ ( document ) . on ( "click" , ".xkit-shorten-posts-embiggen" , XKit . extensions . shorten_posts . embiggen ) ;
94- XKit . post_listener . add ( "shorten_posts" , XKit . extensions . shorten_posts . check ) ;
95- XKit . extensions . shorten_posts . check ( ) ;
45+
46+ if ( XKit . page . react ) {
47+ XKit . css_map . getCssMap ( ) . then ( map => {
48+ this . tagsCss = XKit . css_map . keyToCss ( "tags" ) ;
49+ this . wrapperCss = XKit . css_map . keyToCss ( "impressionLoggingWrapper" ) ;
50+ this . avatarCss = XKit . css_map . keyToCss ( "stickyContainer" ) ;
51+
52+ XKit . tools . add_css ( `${ XKit . css_map . keyToCss ( "baseContainer" ) } { z-index: 99; }` , "shorten_posts" ) ;
53+ XKit . post_listener . add ( "shorten_posts" , XKit . extensions . shorten_posts . react_check ) ;
54+ XKit . extensions . shorten_posts . react_check ( ) ;
55+ } ) ;
56+ } else {
57+ $ ( document ) . on ( "click" , ".xkit-shorten-posts-embiggen" , XKit . extensions . shorten_posts . embiggen ) ;
58+ XKit . post_listener . add ( "shorten_posts" , XKit . extensions . shorten_posts . check ) ;
59+ XKit . extensions . shorten_posts . check ( ) ;
60+ }
9661 }
9762
9863 } ,
9964
100- check : function ( ) {
65+ react_check : async function ( ) {
66+ if ( XKit . extensions . shorten_posts . processing === true ) {
67+ return ;
68+ }
69+ XKit . extensions . shorten_posts . processing = true ;
70+
71+ const $posts = await XKit . interface . react . get_posts ( [ "xkit-shorten-posts-done" , "xkit-shorten-posts-embiggened" ] ) ;
72+ $posts
73+ . addClass ( "xkit-shorten-posts-done" )
74+ . each ( function ( ) {
75+ var $this = $ ( this ) ;
10176
77+ if ( $ ( this ) . hasClass ( "xblacklist_blacklisted_post" ) ) { return ; }
78+
79+ var height = $this . height ( ) ;
80+
81+ if ( height >= XKit . extensions . shorten_posts . preferences . height . value ) {
82+ XKit . extensions . shorten_posts . react_short ( $ ( this ) , height ) ;
83+ }
84+ } ) ;
85+
86+ XKit . extensions . shorten_posts . processing = false ;
87+ } ,
88+
89+ check : function ( ) {
10290 var shortened_count = 0 ;
10391
10492 $ ( ".posts .post" ) . not ( ".xkit-shorten-posts-done" ) . not ( ".xkit-shorten-posts-embiggened" ) . each ( function ( ) {
105-
10693 var m_height = $ ( this ) . height ( ) ;
10794 $ ( this ) . addClass ( "xkit-shorten-posts-done" ) ;
10895
10996 if ( $ ( this ) . hasClass ( "xblacklist_blacklisted_post" ) ) { return ; }
11097
111- var dont_return = false ;
112- if ( XKit . extensions . shorten_posts . preferences . text_too . value
113- && $ ( this ) . hasClass ( "is_regular" ) ) {
114- dont_return = true ;
115- }
116- if ( XKit . extensions . shorten_posts . preferences . photos_too . value
117- && ( $ ( this ) . hasClass ( "is_photo" ) || $ ( this ) . hasClass ( "is_photoset" ) ) ) {
118- dont_return = true ;
119- }
120- if ( XKit . extensions . shorten_posts . preferences . audio_too . value
121- && $ ( this ) . hasClass ( "is_audio" ) ) {
122- dont_return = true ;
123- }
124- if ( XKit . extensions . shorten_posts . preferences . links_too . value
125- && $ ( this ) . hasClass ( "is_link" ) ) {
126- dont_return = true ;
127- }
128- if ( XKit . extensions . shorten_posts . preferences . chat_too . value
129- && $ ( this ) . hasClass ( "is_conversation" ) ) {
130- dont_return = true ;
131- }
132- if ( XKit . extensions . shorten_posts . preferences . quotes_too . value
133- && $ ( this ) . hasClass ( "is_quote" ) ) {
134- dont_return = true ;
135- }
136- if ( XKit . extensions . shorten_posts . preferences . asks_too . value
137- && $ ( this ) . hasClass ( "is_note" ) ) {
138- dont_return = true ;
139- }
140- if ( XKit . extensions . shorten_posts . preferences . videos_too . value
141- && $ ( this ) . hasClass ( "is_video" ) ) {
142- dont_return = true ;
143- }
144-
145- if ( ! dont_return ) {
146- return ;
147- }
14898
14999 if ( m_height >= XKit . extensions . shorten_posts . preferences . height . value ) {
150100 XKit . extensions . shorten_posts . short ( $ ( this ) , m_height ) ;
151101 shortened_count ++ ;
152102 }
153-
154103 } ) ;
155104
156105 if ( shortened_count > 0 ) {
157-
158106 // Call Tumblr scroll helper update thingy.
159107 XKit . tools . add_function ( function ( ) {
160108 Tumblr . Events . trigger ( "DOMEventor:updateRect" ) ;
161109 } , true , "" ) ;
162110
163111 }
164-
165112 } ,
166113
167114 embiggen : function ( e ) {
168-
169115 var obj = e . target ;
170116
171- if ( $ ( obj ) . hasClass ( "image_thumbnail" ) === true ) {
172- obj = $ ( obj ) . parentsUntil ( ".post" ) . parent ( ) . find ( ".xkit-shorten-posts-embiggen" ) ;
173- }
174-
175117 var m_height = $ ( obj ) . attr ( 'data-old-height' ) ;
176- var post_div = $ ( obj ) . parent ( ) ;
118+ var post_div = $ ( obj ) . parents ( ".xkit-shorten-posts-shortened" ) ;
177119
178120 var m_speed = 200 + ( m_height / 2 ) ;
179121
@@ -188,13 +130,54 @@ XKit.extensions.shorten_posts = new Object({
188130 $ ( this ) . removeClass ( "xkit-shorten-posts-shortened" ) ;
189131 $ ( this ) . removeClass ( "xkit-shorten-posts-shortened-show-tags" ) ;
190132 $ ( this ) . addClass ( "xkit-shorten-posts-embiggened" ) ;
191- $ ( this ) . css ( 'height' , 'auto' ) ;
133+
134+ if ( XKit . page . react ) {
135+ const $article = $ ( this ) . find ( "article" ) ;
136+ const $avatar = $ ( this ) . find ( ".xkit-shorten-posts-shortened-avatar" ) ;
137+
138+ $avatar . contents ( ) . prependTo ( $article ) ;
139+ $avatar . remove ( ) ;
140+ $article . removeClass ( "post_wrapper" ) ;
141+ $ ( this ) . find ( ".post_tags" ) . removeClass ( "post_tags" ) ;
142+
143+ $ ( this ) . find ( XKit . extensions . shorten_posts . wrapperCss ) . css ( "height" , "auto" ) ;
144+ $ ( this ) . css ( "height" , "auto" ) ;
145+ } else {
146+ $ ( this ) . css ( 'height' , 'auto' ) ;
147+ }
192148 } ) ;
193149
194150 } ,
195151
196- short : function ( obj , m_height ) {
152+ react_short : function ( obj , height ) {
153+ var $obj = $ ( obj ) ;
154+ if ( $obj . hasClass ( "xblacklist_blacklisted_post" ) ) { $obj . removeClass ( "xkit-shorten-posts-shortened-show-tags" ) ; return ; }
155+
156+ const $article = $obj . find ( "article" ) ;
157+
158+ const container_css = $article . attr ( "class" ) ;
159+ const post_id = $obj . attr ( "data-id" ) ;
160+
161+ $obj . attr ( "data-old-height" , height ) ;
162+ $obj . find ( XKit . extensions . shorten_posts . wrapperCss ) . css ( "height" , XKit . extensions . shorten_posts . preferences . height . value + "px" ) ;
163+ $article . addClass ( "post_wrapper" ) ;
164+
165+ const $avatar_wrapper = $ ( `<div class="xkit-shorten-posts-shortened-avatar ${ container_css } "></div>` ) ;
166+ $article . find ( XKit . extensions . shorten_posts . avatarCss ) . appendTo ( $avatar_wrapper ) ;
167+ $article . before ( $avatar_wrapper ) ;
168+
169+ $obj . addClass ( "xkit-shorten-posts-shortened" ) ;
170+
171+ $article . append ( "<div class=\"xkit-shorten-posts-embiggen xkit-shorten-posts-embiggen-for-post-" + post_id + "\" data-post-id=\"" + post_id + "\" data-old-height=\"" + height + "\">This post has been shortened. Click here to show the full post</div>" ) ;
172+ $article . on ( "click" , ".xkit-shorten-posts-embiggen" , XKit . extensions . shorten_posts . embiggen ) ;
173+
174+ if ( XKit . extensions . shorten_posts . preferences . display_tags . value === true ) {
175+ $obj . find ( XKit . extensions . shorten_posts . tagsCss ) . addClass ( "post_tags" ) ;
176+ $obj . addClass ( "xkit-shorten-posts-shortened-show-tags" ) ;
177+ }
178+ } ,
197179
180+ short : function ( obj , m_height ) {
198181 if ( $ ( obj ) . hasClass ( "xblacklist_blacklisted_post" ) ) { $ ( obj ) . removeClass ( "xkit-shorten-posts-shortened-show-tags" ) ; return ; }
199182
200183 var post_id = $ ( obj ) . attr ( 'data-post-id' ) ;
@@ -211,34 +194,43 @@ XKit.extensions.shorten_posts = new Object({
211194 if ( XKit . extensions . shorten_posts . preferences . embiggen_on_click . value === true ) {
212195 $ ( obj ) . find ( ".image_thumbnail" ) . on ( "click" , XKit . extensions . shorten_posts . embiggen ) ;
213196 }
214-
215197 } ,
216198
217199 destroy : function ( ) {
218-
219200 this . running = false ;
201+ const $posts = $ ( XKit . page . react ? "[data-id]" : ".post" ) ;
220202
221- // Remove all the stuff we've added.
222- $ ( ".xkit-shorten-posts-embiggen" ) . remove ( ) ;
223-
224- $ ( ".post.xkit-shorten-posts-shortened" ) . each ( function ( ) {
203+ ( XKit . page . react ? $posts . find ( XKit . extensions . shorten_posts . wrapperCss ) : $posts ) . each ( function ( ) {
225204 $ ( this ) . css ( 'height' , 'auto' ) ;
226205 } ) ;
227206
228- $ ( ".xkit-shorten-posts-embiggen" ) . off ( "click" , XKit . extensions . shorten_posts . embiggen ) ;
207+ $posts . removeClass ( "xkit-shorten-posts-shortened-show-tags xkit-shorten-posts-done xkit-shorten-posts-embiggened xkit-shorten-posts-shortened" ) ;
208+
209+ // Remove all the stuff we've added.
210+ $ ( ".xkit-shorten-posts-embiggen" ) . remove ( ) ;
211+
212+ if ( XKit . page . react ) {
213+ $posts . find ( ".post_wrapper" ) . removeClass ( "post_wrapper" ) ;
214+ $posts . find ( ".post_tags" ) . removeClass ( "post_tags" ) ;
229215
230- $ ( ".post" ) . removeClass ( "xkit-shorten-posts-shortened" ) ;
231- $ ( ".post" ) . removeClass ( "xkit-shorten-posts-embiggened" ) ;
232- $ ( ".post" ) . removeClass ( "xkit-shorten-posts-shortened-show-tags" ) ;
233- $ ( ".post" ) . removeClass ( "xkit-shorten-posts-done" ) ;
216+ $posts . each ( function ( ) {
217+ const $avatar = $ ( this ) . find ( ".xkit-shorten-posts-shortened-avatar" ) ;
218+ $avatar . contents ( ) . prependTo ( $ ( this ) . find ( "article" ) ) ;
219+ $avatar . remove ( ) ;
220+ } ) ;
234221
235- XKit . tools . remove_css ( "shorten_posts" ) ;
222+ $posts . find ( "article" ) . off ( "click" , ".xkit-shorten-posts-embiggen" , XKit . extensions . shorten_posts . embiggen ) ;
236223
237- // Call Tumblr scroll helper update thingy.
238- XKit . tools . add_function ( function ( ) {
239- Tumblr . Events . trigger ( "DOMEventor:updateRect" ) ;
240- } , true , "" ) ;
224+ } else {
225+ $ ( document ) . off ( "click" , ".xkit-shorten-posts-embiggen" , XKit . extensions . shorten_posts . embiggen ) ;
226+ // Call Tumblr scroll helper update thingy.
227+ XKit . tools . add_function ( function ( ) {
228+ Tumblr . Events . trigger ( "DOMEventor:updateRect" ) ;
229+ } , true , "" ) ;
230+ }
241231
232+ XKit . post_listener . remove ( "shorten_posts" ) ;
233+ XKit . tools . remove_css ( "shorten_posts" ) ;
242234 } ,
243235
244236 cpanel_check_height : function ( ) {
0 commit comments