fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-11-29 02:02 pm

[dw-free] Revamp /update

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

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

Icon browser icon show in upload order.

Patch by [personal profile] fu.

Files modified:
  • htdocs/js/jquery.iconselector.js
  • htdocs/tools/endpoints/getuserpics.bml
  • views/dev/tests/iconselector.js
--------------------------------------------------------------------------------
diff -r cf3b5f17e1f8 -r 7f6e577ec7c3 htdocs/js/jquery.iconselector.js
--- a/htdocs/js/jquery.iconselector.js	Tue Nov 29 21:23:34 2011 +0800
+++ b/htdocs/js/jquery.iconselector.js	Tue Nov 29 22:02:20 2011 +0800
@@ -208,7 +208,9 @@
 
                     var $iconslist = $("<ul id='iconselector_icons_list'></ul>");
 
-                    $.each(data.pics, function(id, icon) {
+                    var pics = data.pics;
+                    $.each(data.ids, function(index,id) {
+                        var icon = pics[id];
                         var idstring = "iconselector_item_"+id;
 
                         var $img = $("<img />").attr( { src: icon.url, alt: icon.alt, height: icon.height, width: icon.width } ).wrap("<div class='icon_image'></div>").parent();
diff -r cf3b5f17e1f8 -r 7f6e577ec7c3 htdocs/tools/endpoints/getuserpics.bml
--- a/htdocs/tools/endpoints/getuserpics.bml	Tue Nov 29 21:23:34 2011 +0800
+++ b/htdocs/tools/endpoints/getuserpics.bml	Tue Nov 29 22:02:20 2011 +0800
@@ -50,7 +50,7 @@
         };
     }
 
-    $upics{ids} = [keys %{$upics{pics}}];
+    $upics{ids} = [sort { $a <=> $b } keys %{$upics{pics}}];
     sleep 1 if $LJ::IS_DEV_SERVER;
 
     return JSON::objToJson(\%upics);
diff -r cf3b5f17e1f8 -r 7f6e577ec7c3 views/dev/tests/iconselector.js
--- a/views/dev/tests/iconselector.js	Tue Nov 29 21:23:34 2011 +0800
+++ b/views/dev/tests/iconselector.js	Tue Nov 29 22:02:20 2011 +0800
@@ -10,31 +10,41 @@
 });
 
 module( "jquery" );
-test( "initialize iconselector", 4, function() {
+test( "initialize iconselector", 6, function() {
     // setup callback
     var server = sinon.sandbox.useFakeServer();
 
     var icons = {
         "pics": {},
-        "ids" : []
+        "ids" : [ 1, 5 ]
     };
     var data = [
         {
+            "id"      : 5,
+            "url"     : "/img/search.gif",
+            "state"   : "A",
+            "width"   : 16,
+            "height"  : 16,
+            "alt"     : "search",
+            "comment" : "from repo",
+            "keywords": [ "search" ]
+        },
+        {
             "id"     : 1,
             "url"    : "/img/ajax-loader.gif",
             "state"  : "A",
             "width"  : 16,
             "height" : 16,
             "alt"    : "swirling loading icon",
-            "comment": "by ...",
+            "comment": "from repo",
             "keywords": ["loading", "animated"]
         }
     ];
     var keywords = [ "" ];
+    icons.ids = [ 1, 5 ];
     for ( var i = 0; i < data.length; i++ ) {
         var icon = data[i];
         icons.pics[icon.id] = icon;
-        icons.ids.push( icon.id )
 
         for ( var k = 0; k < icon.keywords.length; k++ ) {
             keywords.push(icon.keywords[k]);
@@ -63,6 +73,12 @@
     $("#browse-icons").click();
     server.respond();
 
+    // check the icon order
+    var $li = $("#iconselector_icons li");
+    $.each(icons.ids, function(index,id) {
+        equals($li.eq(index).attr("id"), "iconselector_item_"+id, "matches expected order")
+    })
+
     $("#iconselector_icons .keyword:contains('animated')").click();
     equals( $select.val(), "", "one click doesn't do anything");
 
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org