fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-07-05 07:34 am

[dw-free] refactor icon browser and related code

[commit: http://hg.dwscoalition.org/dw-free/rev/e94fdc24e89c]

http://bugs.dwscoalition.org/show_bug.cgi?id=2754

Maintain the list of required libraries for the icon browser in only one
place.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/S2/EntryPage.pm
  • cgi-bin/LJ/S2/ReplyPage.pm
  • cgi-bin/LJ/Talk.pm
  • cgi-bin/LJ/Widget/UserpicSelector.pm
  • cgi-bin/weblib.pl
  • htdocs/talkpost.bml
  • htdocs/talkpost_do.bml
  • htdocs/talkread.bml
--------------------------------------------------------------------------------
diff -r d070c49a0028 -r e94fdc24e89c cgi-bin/LJ/S2/EntryPage.pm
--- a/cgi-bin/LJ/S2/EntryPage.pm	Mon Jul 05 15:38:18 2010 +0800
+++ b/cgi-bin/LJ/S2/EntryPage.pm	Mon Jul 05 15:40:40 2010 +0800
@@ -78,22 +78,8 @@ sub EntryPage
     $p->{head_content} .= LJ::canonical_link( $permalink, $get->{thread} );
 
     # quickreply js libs
-    LJ::need_res(qw(
-                    js/core.js
-                    js/dom.js
-                    js/json.js
-                    js/template.js
-                    js/ippu.js
-                    js/lj_ippu.js
-                    js/userpicselect.js
-                    js/httpreq.js
-                    js/hourglass.js
-                    js/inputcomplete.js
-                    stc/ups.css
-                    stc/lj_base.css
-                    js/datasource.js
-                    js/selectable_table.js
-                    )) if $remote && $remote->can_use_userpic_select;
+    LJ::need_res( LJ::Talk::init_iconbrowser_js( 'stc/lj_base.css' ) )
+        if $remote && $remote->can_use_userpic_select;
 
     LJ::need_res(qw(
                     js/x_core.js
diff -r d070c49a0028 -r e94fdc24e89c cgi-bin/LJ/S2/ReplyPage.pm
--- a/cgi-bin/LJ/S2/ReplyPage.pm	Mon Jul 05 15:38:18 2010 +0800
+++ b/cgi-bin/LJ/S2/ReplyPage.pm	Mon Jul 05 15:40:40 2010 +0800
@@ -65,21 +65,8 @@ sub ReplyPage
     LJ::need_res('stc/display_none.css');
     
     # libs for userpicselect
-    LJ::need_res(qw(
-                    js/core.js
-                    js/dom.js
-                    js/json.js
-                    js/template.js
-                    js/ippu.js
-                    js/lj_ippu.js
-                    js/userpicselect.js
-                    js/httpreq.js
-                    js/hourglass.js
-                    js/inputcomplete.js
-                    stc/ups.css
-                    js/datasource.js
-                    js/selectable_table.js
-                    )) if $remote && $remote->can_use_userpic_select;
+    LJ::need_res( LJ::Talk::init_iconbrowser_js() )
+        if $remote && $remote->can_use_userpic_select;
 
     if ($u->should_block_robots || $entry->should_block_robots) {
         $p->{'head_content'} .= LJ::robot_meta_tags();
diff -r d070c49a0028 -r e94fdc24e89c cgi-bin/LJ/Talk.pm
--- a/cgi-bin/LJ/Talk.pm	Mon Jul 05 15:38:18 2010 +0800
+++ b/cgi-bin/LJ/Talk.pm	Mon Jul 05 15:40:40 2010 +0800
@@ -1921,6 +1921,39 @@ LOGIN
     $ret .= "</form>\n";
 
     return $ret;
+}
+
+# load the javascript libraries for the icon browser
+# args: names of any additional files to load
+# returns: full list of arguments to pass to LJ::need_res
+sub init_iconbrowser_js {
+    my @additional = @_;
+
+    my @list = (
+        # base libraries
+        'js/core.js',
+        'js/dom.js',
+        'js/json.js',
+        # for the formatting of the icon selector popup
+        'js/template.js',
+        'js/ippu.js',
+        'js/lj_ippu.js',
+        # logic for the icon selector
+        'js/userpicselect.js',
+        # fetching the userpic information
+        'js/httpreq.js',
+        'js/hourglass.js',
+        # autocomplete
+        'js/inputcomplete.js',
+        'stc/ups.css',
+        # selecting an icon by clicking on a row
+        'js/datasource.js',
+        'js/selectable_table.js',
+        # additional files from arguments
+        @additional,
+    );
+
+    return @list;
 }
 
 # generate the javascript code for the quick quote button
diff -r d070c49a0028 -r e94fdc24e89c cgi-bin/LJ/Widget/UserpicSelector.pm
--- a/cgi-bin/LJ/Widget/UserpicSelector.pm	Mon Jul 05 15:38:18 2010 +0800
+++ b/cgi-bin/LJ/Widget/UserpicSelector.pm	Mon Jul 05 15:40:40 2010 +0800
@@ -17,24 +17,10 @@ use base qw(LJ::Widget);
 use base qw(LJ::Widget);
 use Carp qw(croak);
 
+use LJ::Talk;
+
 sub need_res {
-
-   return qw( js/core.js
-              js/dom.js
-              js/json.js
-              js/template.js
-              js/ippu.js
-              js/lj_ippu.js
-              js/userpicselect.js
-              js/httpreq.js
-              js/hourglass.js
-              js/inputcomplete.js
-              stc/ups.css
-              stc/entry.css
-              js/datasource.js
-              js/selectable_table.js
-              );
-
+   return LJ::Talk::init_iconbrowser_js( 'stc/entry.css' );
 }
 
 sub handle_post {
diff -r d070c49a0028 -r e94fdc24e89c cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl	Mon Jul 05 15:38:18 2010 +0800
+++ b/cgi-bin/weblib.pl	Mon Jul 05 15:40:40 2010 +0800
@@ -1185,21 +1185,8 @@ sub entry_form {
                 } if $remote->can_use_userpic_select;
 
                 # libs for userpicselect
-                LJ::need_res(qw(
-                                js/core.js
-                                js/dom.js
-                                js/json.js
-                                js/template.js
-                                js/ippu.js
-                                js/lj_ippu.js
-                                js/userpicselect.js
-                                js/httpreq.js
-                                js/hourglass.js
-                                js/inputcomplete.js
-                                stc/ups.css
-                                js/datasource.js
-                                js/selectable_table.js
-                                )) if $remote->can_use_userpic_select;
+                LJ::need_res( LJ::Talk::init_iconbrowser_js() )
+                    if $remote->can_use_userpic_select;
 
                 $out .= "<div id='userpic' style='display: none;'><p id='userpic_preview'><a href='javascript:void(0);' id='lj_userpicselect_img'><img src='' alt='selected userpic' id='userpic_preview_image' /><span id='lj_userpicselect_img_txt'>$userpic_link_text</span></a></p></div>";
                 $out .= "\n";
diff -r d070c49a0028 -r e94fdc24e89c htdocs/talkpost.bml
--- a/htdocs/talkpost.bml	Mon Jul 05 15:38:18 2010 +0800
+++ b/htdocs/talkpost.bml	Mon Jul 05 15:40:40 2010 +0800
@@ -29,21 +29,8 @@ body<=
     my $errtxt;
 
     # libs for userpicselect
-    LJ::need_res(qw(
-                    js/core.js
-                    js/dom.js
-                    js/json.js
-                    js/template.js
-                    js/ippu.js
-                    js/lj_ippu.js
-                    js/userpicselect.js
-                    js/httpreq.js
-                    js/hourglass.js
-                    js/inputcomplete.js
-                    stc/ups.css
-                    js/datasource.js
-                    js/selectable_table.js
-                    )) if $remote && $remote->can_use_userpic_select;
+    LJ::need_res( LJ::Talk::init_iconbrowser_js() )
+        if $remote && $remote->can_use_userpic_select;
 
     my $pics = LJ::Talk::get_subjecticons();
 
diff -r d070c49a0028 -r e94fdc24e89c htdocs/talkpost_do.bml
--- a/htdocs/talkpost_do.bml	Mon Jul 05 15:38:18 2010 +0800
+++ b/htdocs/talkpost_do.bml	Mon Jul 05 15:40:40 2010 +0800
@@ -119,21 +119,8 @@ body<=
 
     LJ::need_res('stc/display_none.css');
     # libs for userpicselect
-    LJ::need_res(qw(
-                    js/core.js
-                    js/dom.js
-                    js/json.js
-                    js/template.js
-                    js/ippu.js
-                    js/lj_ippu.js
-                    js/userpicselect.js
-                    js/httpreq.js
-                    js/hourglass.js
-                    js/inputcomplete.js
-                    stc/ups.css
-                    js/datasource.js
-                    js/selectable_table.js
-                    )) if $remote && $remote->can_use_userpic_select;
+    LJ::need_res( LJ::Talk::init_iconbrowser_js() )
+        if $remote && $remote->can_use_userpic_select;
 
     # FIXME: this isn't entirely correct, if ecphash is present but ignored/incorrect
     # that fix would need to be done in talklib.pl
diff -r d070c49a0028 -r e94fdc24e89c htdocs/talkread.bml
--- a/htdocs/talkread.bml	Mon Jul 05 15:38:18 2010 +0800
+++ b/htdocs/talkread.bml	Mon Jul 05 15:40:40 2010 +0800
@@ -206,27 +206,12 @@ body<=
 
     if ( ( $remote && ! $remote->prop( "opt_no_quickreply" ) ) && ! $nocomments ) {
        # quickreply js libs
-       LJ::need_res(qw(
-                       js/core.js
-                       js/dom.js
-                       js/json.js
-                       js/template.js
-                       js/ippu.js
-                       js/lj_ippu.js
-                       js/userpicselect.js
-                       js/httpreq.js
-                       js/hourglass.js
-                       js/inputcomplete.js
-                       stc/ups.css
-                       stc/lj_base.css
-                       js/datasource.js
-                       js/selectable_table.js
-                       )) if $remote->can_use_userpic_select;
-
-         LJ::need_res(qw(
+        LJ::need_res( qw(
                          js/x_core.js
                          js/quickreply.js
-                         ));
+                        ) );
+        LJ::need_res( LJ::Talk::init_iconbrowser_js( 'stc/lj_base.css' ) )
+            if $remote->can_use_userpic_select;
     }
 
     my $showmultiform = $remote && ( ( $up && $remote->equals( $up) ) ||
--------------------------------------------------------------------------------