r40507 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40506‎ | r40507 | r40508 >
Date:20:50, 5 September 2008
Author:rainman
Status:old
Tags:
Comment:
* (bug 14398) mwsuggest.js: Let width of container be configurable
Dynamically change container *width* to fit as much as possible of suggestions. Width change is
animated (os_animation_steps=6), and is expands up to double of original size (os_container_max_width=2).
All of this can be overriden in site/user js.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/skins/common/mwsuggest.js (modified) (history)
  • /trunk/phase3/skins/common/shared.css (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/shared.css
@@ -161,6 +161,7 @@
162162 left: 0px;
163163 width: 0px;
164164 background-color: white;
 165+ background-color: Window;
165166 border-style: solid;
166167 border-color: #AAAAAA;
167168 border-width: 1px;
Index: trunk/phase3/skins/common/mwsuggest.js
@@ -31,6 +31,16 @@
3232 var os_is_stopped = false;
3333 // max lines to show in suggest table
3434 var os_max_lines_per_suggest = 7;
 35+// number of steps to animate expansion/contraction of container width
 36+var os_animation_steps = 6;
 37+// num of pixels of smallest step
 38+var os_animation_min_step = 2;
 39+// delay between steps (in ms)
 40+var os_animation_delay = 30;
 41+// max width of container in percent of normal size (1 == 100%)
 42+var os_container_max_width = 2;
 43+// currently active animation timer
 44+var os_animation_timer = null;
3545
3646 /** Timeout timer class that will fetch the results */
3747 function os_Timer(id,r,query){
@@ -39,6 +49,18 @@
4050 this.query = query;
4151 }
4252
 53+/** Timer user to animate expansion/contraction of container width */
 54+function os_AnimationTimer(r, target){
 55+ this.r = r;
 56+ var current = document.getElementById(r.container).offsetWidth;
 57+ this.inc = Math.round((target-current) / os_animation_steps);
 58+ if(this.inc < os_animation_min_step && this.inc >=0)
 59+ this.inc = os_animation_min_step; // minimal animation step
 60+ if(this.inc > -os_animation_min_step && this.inc <0)
 61+ this.inc = -os_animation_min_step;
 62+ this.target = target;
 63+}
 64+
4365 /** Property class for single search box */
4466 function os_Results(name, formname){
4567 this.searchform = formname; // id of the searchform
@@ -84,9 +106,9 @@
85107 function os_operaWidthFix(x){
86108 // TODO: better css2 incompatibility detection here
87109 if(is_opera || is_khtml || navigator.userAgent.toLowerCase().indexOf('firefox/1')!=-1){
88 - return x - 30; // opera&konqueror & old firefox don't understand overflow-x, estimate scrollbar width
 110+ return 30; // opera&konqueror & old firefox don't understand overflow-x, estimate scrollbar width
89111 }
90 - return x;
 112+ return 0;
91113 }
92114
93115 function os_encodeQuery(value){
@@ -217,11 +239,41 @@
218240 }
219241 /** If some entries are longer than the box, replace text with "..." */
220242 function os_trimResultText(r){
 243+ // find max width, first see if we could expand the container to fit it
 244+ var maxW = 0;
 245+ for(var i=0;i<r.resultCount;i++){
 246+ var e = document.getElementById(r.resultText+i);
 247+ if(e.offsetWidth > maxW)
 248+ maxW = e.offsetWidth;
 249+ }
221250 var w = document.getElementById(r.container).offsetWidth;
 251+ var fix = 0;
222252 if(r.containerCount < r.resultCount){
223 - w -= 20; // give 20px for scrollbar
 253+ fix = 20; // give 20px for scrollbar
224254 } else
225 - w = os_operaWidthFix(w);
 255+ fix = os_operaWidthFix(w);
 256+ if(fix < 4)
 257+ fix = 4; // basic padding
 258+ maxW += fix;
 259+
 260+ // resize container to fit more data if permitted
 261+ var normW = document.getElementById(r.searchbox).offsetWidth;
 262+ var prop = maxW / normW;
 263+ if(prop > os_container_max_width)
 264+ prop = os_container_max_width;
 265+ else if(prop < 1)
 266+ prop = 1;
 267+ var newW = Math.round( normW * prop );
 268+ if( w != newW ){
 269+ w = newW;
 270+ if( os_animation_timer != null )
 271+ clearInterval(os_animation_timer.id)
 272+ os_animation_timer = new os_AnimationTimer(r,w);
 273+ os_animation_timer.id = setInterval("os_animateChangeWidth()",os_animation_delay);
 274+ w -= fix; // this much is reserved
 275+ }
 276+
 277+ // trim results
226278 if(w < 10)
227279 return;
228280 for(var i=0;i<r.resultCount;i++){
@@ -245,6 +297,25 @@
246298 }
247299 }
248300
 301+/** Invoked on timer to animate change in container width */
 302+function os_animateChangeWidth(){
 303+ var r = os_animation_timer.r;
 304+ var c = document.getElementById(r.container);
 305+ var w = c.offsetWidth;
 306+ var inc = os_animation_timer.inc;
 307+ var target = os_animation_timer.target;
 308+ var nw = w + inc;
 309+ if( (inc > 0 && nw >= target) || (inc <= 0 && nw <= target) ){
 310+ // finished !
 311+ c.style.width = target+"px";
 312+ clearInterval(os_animation_timer.id)
 313+ os_animation_timer = null;
 314+ } else{
 315+ // in-progress
 316+ c.style.width = nw+"px";
 317+ }
 318+}
 319+
249320 /** Handles data from XMLHttpRequest, and updates the suggest results */
250321 function os_updateResults(r, query, text, cacheKey){
251322 os_cache[cacheKey] = text;
@@ -271,6 +342,7 @@
272343 var t = document.getElementById(r.resultTable);
273344 r.containerTotal = t.offsetHeight;
274345 r.containerRow = t.offsetHeight / r.resultCount;
 346+ os_fitContainer(r);
275347 os_trimResultText(r);
276348 os_showResults(r);
277349 } catch(e){
@@ -284,7 +356,7 @@
285357 /** Create the result table to be placed in the container div */
286358 function os_createResultTable(r, results){
287359 var c = document.getElementById(r.container);
288 - var width = os_operaWidthFix(c.offsetWidth);
 360+ var width = c.offsetWidth - os_operaWidthFix(c.offsetWidth);
289361 var html = "<table class=\"os-suggest-results\" id=\""+r.resultTable+"\" style=\"width: "+width+"px;\">";
290362 r.results = new Array();
291363 r.resultCount = results.length;
Index: trunk/phase3/RELEASE-NOTES
@@ -180,6 +180,7 @@
181181 tables, and have been disabled by default.
182182 * (bug 15482) Special:Recentchangeslinked has no longer two submit buttons
183183 * (bug 15292) New message notification for unregistred users now works again
 184+* (bug 14398) mwsuggest.js: Let width of container be configurable
184185
185186
186187 === API changes in 1.14 ===

Follow-up revisions

RevisionCommit summaryAuthorDate
r40512Bump $wgStyleVersion for r40507demon02:46, 6 September 2008