Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BRIC
dokuwiki
Commits
f9328d30
Commit
f9328d30
authored
11 years ago
by
Gerrit Uitslag
Browse files
Options
Downloads
Patches
Plain Diff
Reformat qsearch.js
parent
7647d877
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/scripts/qsearch.js
+145
-137
145 additions, 137 deletions
lib/scripts/qsearch.js
with
145 additions
and
137 deletions
lib/scripts/qsearch.js
+
145
−
137
View file @
f9328d30
...
...
@@ -6,163 +6,171 @@
* @author Adrian Lang <lang@cosmocode.de>
* @author Michal Rezler <m.rezler@centrum.cz>
*/
jQuery
.
fn
.
dw_qsearch
=
function
(
overrides
)
{
jQuery
.
fn
.
dw_qsearch
=
function
(
overrides
)
{
var
dw_qsearch
=
{
output_id
:
'
#qsearch__out
'
,
$inObj
:
this
,
$outObj
:
null
,
timer
:
null
,
curRequest
:
null
,
/**
* initialize the quick search
*
* Attaches the event handlers
*
*/
init
:
function
()
{
var
do_qsearch
;
dw_qsearch
.
$outObj
=
jQuery
(
dw_qsearch
.
output_id
);
// objects found?
if
(
dw_qsearch
.
$inObj
.
length
===
0
||
dw_qsearch
.
$outObj
.
length
===
0
)
{
return
;
}
// attach eventhandler to search field
do_qsearch
=
function
()
{
// abort any previous request
if
(
dw_qsearch
.
curRequest
!=
null
)
{
dw_qsearch
.
curRequest
.
abort
();
}
var
value
=
dw_qsearch
.
$inObj
.
val
();
if
(
value
===
''
)
{
dw_qsearch
.
clear_results
();
$inObj
:
this
,
$outObj
:
null
,
timer
:
null
,
curRequest
:
null
,
/**
* initialize the quick search
*
* Attaches the event handlers
*
*/
init
:
function
()
{
var
do_qsearch
;
dw_qsearch
.
$outObj
=
jQuery
(
dw_qsearch
.
output_id
);
// objects found?
if
(
dw_qsearch
.
$inObj
.
length
===
0
||
dw_qsearch
.
$outObj
.
length
===
0
)
{
return
;
}
dw_qsearch
.
curRequest
=
jQuery
.
post
(
DOKU_BASE
+
'
lib/exe/ajax.php
'
,
{
call
:
'
qsearch
'
,
q
:
encodeURI
(
value
)
},
dw_qsearch
.
onCompletion
,
'
html
'
);
};
dw_qsearch
.
$inObj
.
keyup
(
function
()
{
if
(
dw_qsearch
.
timer
){
window
.
clearTimeout
(
dw_qsearch
.
timer
);
dw_qsearch
.
timer
=
null
;
// attach eventhandler to search field
do_qsearch
=
function
()
{
// abort any previous request
if
(
dw_qsearch
.
curRequest
!=
null
)
{
dw_qsearch
.
curRequest
.
abort
()
;
}
dw_qsearch
.
timer
=
window
.
setTimeout
(
do_qsearch
,
500
);
}
);
// attach eventhandler to output field
dw_qsearch
.
$outObj
.
click
(
dw_qsearch
.
clear_results
);
},
/**
* Empty and hide the output div
*/
clear_results
:
function
(){
dw_qsearch
.
$outObj
.
hide
();
dw_qsearch
.
$outObj
.
text
(
''
);
},
/**
* Callback. Reformat and display the results.
*
* Namespaces are shortened here to keep the results from overflowing
* or wrapping
*
* @param data The result HTML
*/
onCompletion
:
function
(
data
)
{
var
max
,
$links
,
too_big
;
dw_qsearch
.
curRequest
=
null
;
if
(
data
===
''
)
{
dw_qsearch
.
clear_results
();
return
;
}
dw_qsearch
.
$outObj
.
html
(
data
)
.
show
()
.
css
(
'
white-space
'
,
'
nowrap
'
);
// disable overflow during shortening
dw_qsearch
.
$outObj
.
find
(
'
li
'
).
css
(
'
overflow
'
,
'
visible
'
);
$links
=
dw_qsearch
.
$outObj
.
find
(
'
a
'
);
max
=
dw_qsearch
.
$outObj
[
0
].
clientWidth
;
// maximum width allowed (but take away paddings below)
if
(
document
.
documentElement
.
dir
===
'
rtl
'
){
max
-=
parseInt
(
dw_qsearch
.
$outObj
.
css
(
'
padding-left
'
));
too_big
=
function
(
l
)
{
return
l
.
offsetLeft
<
0
;
};
}
else
{
max
-=
parseInt
(
dw_qsearch
.
$outObj
.
css
(
'
padding-right
'
));
too_big
=
function
(
l
)
{
return
l
.
offsetWidth
+
l
.
offsetLeft
>
max
;
};
}
$links
.
each
(
function
()
{
var
start
,
length
,
replace
,
nsL
,
nsR
,
eli
,
runaway
;
var
value
=
dw_qsearch
.
$inObj
.
val
();
if
(
value
===
''
)
{
dw_qsearch
.
clear_results
();
return
;
}
dw_qsearch
.
curRequest
=
jQuery
.
post
(
DOKU_BASE
+
'
lib/exe/ajax.php
'
,
{
call
:
'
qsearch
'
,
q
:
encodeURI
(
value
)
},
dw_qsearch
.
onCompletion
,
'
html
'
);
};
dw_qsearch
.
$inObj
.
keyup
(
function
()
{
if
(
dw_qsearch
.
timer
)
{
window
.
clearTimeout
(
dw_qsearch
.
timer
);
dw_qsearch
.
timer
=
null
;
}
dw_qsearch
.
timer
=
window
.
setTimeout
(
do_qsearch
,
500
);
}
);
if
(
!
too_big
(
this
))
{
// attach eventhandler to output field
dw_qsearch
.
$outObj
.
click
(
dw_qsearch
.
clear_results
);
},
/**
* Empty and hide the output div
*/
clear_results
:
function
()
{
dw_qsearch
.
$outObj
.
hide
();
dw_qsearch
.
$outObj
.
text
(
''
);
},
/**
* Callback. Reformat and display the results.
*
* Namespaces are shortened here to keep the results from overflowing
* or wrapping
*
* @param data The result HTML
*/
onCompletion
:
function
(
data
)
{
var
max
,
$links
,
too_big
;
dw_qsearch
.
curRequest
=
null
;
if
(
data
===
''
)
{
dw_qsearch
.
clear_results
();
return
;
}
// make IE's innerText available to W3C conform browsers
if
(
this
.
textContent
){
this
.
__defineGetter__
(
'
innerText
'
,
function
(){
return
this
.
textContent
});
this
.
__defineSetter__
(
'
innerText
'
,
function
(
val
){
this
.
textContent
=
val
});
dw_qsearch
.
$outObj
.
html
(
data
)
.
show
()
.
css
(
'
white-space
'
,
'
nowrap
'
);
// disable overflow during shortening
dw_qsearch
.
$outObj
.
find
(
'
li
'
).
css
(
'
overflow
'
,
'
visible
'
);
$links
=
dw_qsearch
.
$outObj
.
find
(
'
a
'
);
max
=
dw_qsearch
.
$outObj
[
0
].
clientWidth
;
// maximum width allowed (but take away paddings below)
if
(
document
.
documentElement
.
dir
===
'
rtl
'
)
{
max
-=
parseInt
(
dw_qsearch
.
$outObj
.
css
(
'
padding-left
'
));
too_big
=
function
(
l
)
{
return
l
.
offsetLeft
<
0
;
};
}
else
{
max
-=
parseInt
(
dw_qsearch
.
$outObj
.
css
(
'
padding-right
'
));
too_big
=
function
(
l
)
{
return
l
.
offsetWidth
+
l
.
offsetLeft
>
max
;
};
}
nsL
=
this
.
innerText
.
indexOf
(
'
(
'
);
nsR
=
this
.
innerText
.
indexOf
(
'
)
'
);
eli
=
0
;
runaway
=
0
;
while
((
nsR
-
nsL
>
3
)
&&
too_big
(
this
)
&&
runaway
++
<
500
)
{
if
(
eli
!==
0
){
// elipsis already inserted
if
(
(
eli
-
nsL
)
>
(
nsR
-
eli
)
){
// cut left
start
=
eli
-
2
;
length
=
2
;
}
else
{
// cut right
start
=
eli
+
1
;
length
=
1
;
}
replace
=
''
;
}
else
{
// replace middle with ellipsis
start
=
Math
.
floor
(
nsL
+
((
nsR
-
nsL
)
/
2
)
);
length
=
1
;
replace
=
'
…
'
;
$links
.
each
(
function
()
{
var
start
,
length
,
replace
,
nsL
,
nsR
,
eli
,
runaway
;
if
(
!
too_big
(
this
))
{
return
;
}
// make IE's innerText available to W3C conform browsers
if
(
this
.
textContent
)
{
this
.
__defineGetter__
(
'
innerText
'
,
function
()
{
return
this
.
textContent
});
this
.
__defineSetter__
(
'
innerText
'
,
function
(
val
)
{
this
.
textContent
=
val
});
}
this
.
innerText
=
substr_replace
(
this
.
innerText
,
replace
,
start
,
length
);
eli
=
this
.
innerText
.
indexOf
(
'
…
'
);
nsL
=
this
.
innerText
.
indexOf
(
'
(
'
);
nsR
=
this
.
innerText
.
indexOf
(
'
)
'
);
}
});
eli
=
0
;
runaway
=
0
;
while
((
nsR
-
nsL
>
3
)
&&
too_big
(
this
)
&&
runaway
++
<
500
)
{
if
(
eli
!==
0
)
{
// elipsis already inserted
if
((
eli
-
nsL
)
>
(
nsR
-
eli
))
{
// cut left
start
=
eli
-
2
;
length
=
2
;
}
else
{
// cut right
start
=
eli
+
1
;
length
=
1
;
}
replace
=
''
;
}
else
{
// replace middle with ellipsis
start
=
Math
.
floor
(
nsL
+
((
nsR
-
nsL
)
/
2
));
length
=
1
;
replace
=
'
…
'
;
}
this
.
innerText
=
substr_replace
(
this
.
innerText
,
replace
,
start
,
length
);
// reenable overflow
dw_qsearch
.
$outObj
.
find
(
'
li
'
).
css
(
'
overflow
'
,
'
hidden
'
).
css
(
'
text-overflow
'
,
'
ellipsis
'
);
}
eli
=
this
.
innerText
.
indexOf
(
'
…
'
);
nsL
=
this
.
innerText
.
indexOf
(
'
(
'
);
nsR
=
this
.
innerText
.
indexOf
(
'
)
'
);
}
});
// reenable overflow
dw_qsearch
.
$outObj
.
find
(
'
li
'
).
css
(
'
overflow
'
,
'
hidden
'
).
css
(
'
text-overflow
'
,
'
ellipsis
'
);
}
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment