PageSourceSearch

https://www.trubiltdoors.com/wp-content/themes/northstar/js/jquery.quicksilver.js

js trubiltdoors.com collected 2026-10-04 05:56:29 UTC 3,873 bytes, 105 lines download raw bytes

1// qs_score - Quicksilver Score
2// 
3// A port of the Quicksilver string ranking algorithm
4// 
5// Examples changed to fit jQuery model (JSK):
6// $.score("hello world", "axl") //=> 0.0
7// $.score("hello world", "ow") //=> 0.6
8// $.score("hello world", "hello world") //=> 1.0
9//
10// Tested in Firefox 2 and Safari 3
11//
12// The Quicksilver code is available here
13// http://code.google.com/p/blacktree-alchemy/
14// http://blacktree-alchemy.googlecode.com/svn/trunk/Crucible/Code/NSString+BLTRRanking.m
15//
16// The MIT License
17// 
18// Copyright (c) 2008 Lachie Cox
19// 
20// Permission is hereby granted, free of charge, to any person obtaining a copy
21// of this software and associated documentation files (the "Software"), to deal
22// in the Software without restriction, including without limitation the rights
23// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24// copies of the Software, and to permit persons to whom the Software is
25// furnished to do so, subject to the following conditions:
26// 
27// The above copyright notice and this permission notice shall be included in
28// all copies or substantial portions of the Software.
29// 
30// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
36// THE SOFTWARE.
37
38/* Ported to jQuery style by Jordan Kasper
39 * Requires: jQuery 1.0.x
40 */
41
42;(function($) {
43  
44  // JSK - Added base string argument
45  $.score = function(base, abbreviation, offset) {
46    
47    offset = offset || 0 // TODO: I think this is unused... remove
48    
49    if(abbreviation.length == 0) return 0.9
50    if(abbreviation.length > base.length) return 0.0
51    
52    for (var i = abbreviation.length; i > 0; i--) {
53      var sub_abbreviation = abbreviation.substring(0,i)
54      var index = base.indexOf(sub_abbreviation)
55      
56      
57      if(index < 0) continue;
58      if(index + abbreviation.length > base.length + offset) continue;
59      
60      var next_string       = base.substring(index+sub_abbreviation.length)
61      var next_abbreviation = null
62      
63      if(i >= abbreviation.length)
64        next_abbreviation = ''
65      else
66        next_abbreviation = abbreviation.substring(i)
67      
68      // Changed to fit new (jQuery) format (JSK)
69      var remaining_score   = $.score(next_string, next_abbreviation,offset+index)
70      
71      if (remaining_score > 0) {
72        var score = base.length-next_string.length;
73        
74        if(index != 0) {
75          var j = 0;
76          
77          var c = base.charCodeAt(index-1)
78          if(c==32 || c == 9) {
79            for(var j=(index-2); j >= 0; j--) {
80              c = base.charCodeAt(j)
81              score -= ((c == 32 || c == 9) ? 1 : 0.15)
82            }
83            
84            // XXX maybe not port this heuristic
85            // 
86            //          } else if ([[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[self characterAtIndex:matchedRange.location]]) {
87            //            for (j = matchedRange.location-1; j >= (int) searchRange.location; j--) {
88            //              if ([[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[self characterAtIndex:j]])
89            //                score--;
90            //              else
91            //                score -= 0.15;
92            //            }
93          } else {
94            score -= index
95          }
96        }
97        
98        score += remaining_score * next_string.length
99        score /= base.length;
100        return score
101      }
102    }
103    return 0.0
104  }
105})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.