Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cribjs-editor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
cribjs-editor
Commits
1c804868
Commit
1c804868
authored
Aug 10, 2020
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Basic Grep to search among files
parent
1b2cb43d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
205 additions
and
1 deletion
+205
-1
gadget/gadget_cribjs_page_grep.html
gadget/gadget_cribjs_page_grep.html
+41
-0
gadget/gadget_cribjs_page_grep.js
gadget/gadget_cribjs_page_grep.js
+162
-0
gadget/gadget_cribjs_page_tools.html
gadget/gadget_cribjs_page_tools.html
+1
-0
gadget/gadget_cribjs_page_tools.js
gadget/gadget_cribjs_page_tools.js
+1
-1
No files found.
gadget/gadget_cribjs_page_grep.html
0 → 100644
View file @
1c804868
<!DOCTYPE html>
<html>
<head>
<meta
http-equiv=
"Content-type"
content=
"text/html; charset=utf-8"
/>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no"
/>
<title>
CribJS Header
</title>
<!-- renderjs -->
<script
src=
"../lib/rsvp.js"
type=
"text/javascript"
></script>
<script
src=
"../lib/renderjs.js"
type=
"text/javascript"
></script>
<script
src=
"./gadget_global.js"
type=
"text/javascript"
></script>
<!-- Custom -->
<script
src=
"./gadget_cribjs_page_grep.js"
type=
"text/javascript"
></script>
</head>
<body>
<div
class=
"nav_content url_list container"
>
<form
class=
"crib-url-list-content"
>
<h3>
Grep URL List
</h3>
<label>
Search:
<input
name=
"search-pattern"
class=
"search-pattern form-control"
type=
"text"
size=
"50"
value=
""
>
</label>
<button
type=
"submit"
name=
"list-contents"
class=
"btn btn-default"
>
Search
</button>
<table
class=
"table table-striped table-condensed"
>
<thead>
<tr>
<th>
Found
</th>
<th>
Url
</th>
<th>
Go
</th>
</tr>
</thead>
<tfoot>
</tfoot>
<tbody>
</tbody>
</table>
</form>
</div>
</body>
</html>
\ No newline at end of file
gadget/gadget_cribjs_page_grep.js
0 → 100644
View file @
1c804868
/*global window, rJS, RSVP, jIO, document, loopEventListener, RegExp */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(
function
(
window
,
rJS
,
jIO
,
loopEventListener
)
{
"
use strict
"
;
function
getURLContentAsText
(
gadget
,
url
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
gadget
.
crib_sw_get
(
url
);
})
.
push
(
function
(
data
)
{
var
type
;
type
=
data
.
type
;
return
jIO
.
util
.
readBlobAsText
(
data
,
type
);
})
.
push
(
function
(
event
)
{
return
event
.
target
.
result
;
});
}
function
displayURLList
(
gadget
,
event
)
{
var
url_list
=
[],
grep_pattern
=
gadget
.
props
.
element
.
querySelector
(
"
.search-pattern
"
).
value
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
gadget
.
crib_sw_allDocs
();
})
.
push
(
function
(
data
)
{
var
promise_list
=
[],
tmp_url_list
=
[],
url
;
if
(
data
.
hasOwnProperty
(
"
urls
"
))
{
tmp_url_list
=
data
.
urls
;
}
else
{
tmp_url_list
=
data
;
}
for
(
url
in
tmp_url_list
)
{
if
(
tmp_url_list
.
hasOwnProperty
(
url
))
{
// XXX-CLN Ugly way to filter
if
(
url
.
endsWith
(
"
.js
"
)
||
url
.
endsWith
(
"
.html
"
)
||
url
.
endsWith
(
"
.json
"
)
||
url
.
endsWith
(
"
.css
"
))
{
url_list
.
push
(
url
);
promise_list
.
push
(
RSVP
.
all
([
gadget
.
getUrlFor
({
page
:
'
editor
'
,
url
:
url
}),
grep_pattern
?
getURLContentAsText
(
gadget
,
url
)
:
""
]));
}
}
}
return
RSVP
.
all
(
promise_list
);
})
.
push
(
function
(
result_list
)
{
var
contentsElement
=
gadget
.
props
.
element
.
querySelector
(
'
.crib-url-list-content tbody
'
),
footer_element
=
gadget
.
props
.
element
.
querySelector
(
'
.crib-url-list-content tfoot
'
),
url_number
,
result_number
=
0
,
url
,
trElement
,
tdElement
;
// Clear out the existing items from the list.
while
(
contentsElement
.
firstChild
)
{
contentsElement
.
removeChild
(
contentsElement
.
firstChild
);
}
if
(
grep_pattern
)
{
grep_pattern
=
new
RegExp
(
grep_pattern
);
}
// Add each cached URL to the list, one by one.
for
(
url_number
=
0
;
url_number
<
url_list
.
length
;
url_number
++
)
{
url
=
url_list
[
url_number
];
var
element
,
is_present
=
grep_pattern
?
grep_pattern
.
test
(
result_list
[
url_number
][
1
])
:
true
;
if
(
is_present
)
{
trElement
=
document
.
createElement
(
'
tr
'
);
tdElement
=
document
.
createElement
(
'
td
'
);
tdElement
.
innerHTML
=
"
<span>✔</span>
"
;
trElement
.
appendChild
(
tdElement
);
tdElement
=
document
.
createElement
(
'
td
'
);
element
=
document
.
createElement
(
'
a
'
);
element
.
setAttribute
(
'
href
'
,
result_list
[
url_number
][
0
]);
element
.
textContent
=
url
;
tdElement
.
appendChild
(
element
);
trElement
.
appendChild
(
tdElement
);
tdElement
=
document
.
createElement
(
'
td
'
);
element
=
document
.
createElement
(
'
a
'
);
element
.
textContent
=
"
Go
"
;
element
.
setAttribute
(
'
href
'
,
url
);
element
.
setAttribute
(
'
target
'
,
"
_blank
"
);
element
.
setAttribute
(
"
class
"
,
"
btn btn-primary btn-xs
"
);
tdElement
.
appendChild
(
element
);
trElement
.
appendChild
(
tdElement
);
contentsElement
.
appendChild
(
trElement
);
result_number
+=
1
;
}
}
while
(
footer_element
.
firstChild
)
{
footer_element
.
removeChild
(
footer_element
.
firstChild
);
}
trElement
=
document
.
createElement
(
'
tr
'
);
tdElement
=
document
.
createElement
(
'
td
'
);
tdElement
.
innerHTML
=
"
<span>
"
+
result_number
+
"
✔</span>
"
;
trElement
.
appendChild
(
tdElement
);
tdElement
=
document
.
createElement
(
'
td
'
);
tdElement
.
innerHTML
=
url_number
+
"
URLs
"
;
trElement
.
appendChild
(
tdElement
);
tdElement
=
document
.
createElement
(
'
td
'
);
trElement
.
appendChild
(
tdElement
);
footer_element
.
appendChild
(
trElement
);
});
}
rJS
(
window
)
.
ready
(
function
(
g
)
{
g
.
props
=
{};
return
g
.
getElement
()
.
push
(
function
(
element
)
{
g
.
props
.
element
=
element
;
g
.
props
.
start_deferred
=
RSVP
.
defer
();
});
})
.
declareAcquiredMethod
(
"
crib_sw_allDocs
"
,
"
crib_sw_allDocs
"
)
.
declareAcquiredMethod
(
"
crib_sw_get
"
,
"
crib_sw_get
"
)
.
declareAcquiredMethod
(
"
redirect
"
,
"
redirect
"
)
.
declareAcquiredMethod
(
"
getUrlFor
"
,
"
getUrlFor
"
)
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
gadget
=
this
;
if
(
options
===
undefined
)
options
=
{};
gadget
.
props
.
options
=
options
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
pattern
=
""
;
if
(
options
.
grep_pattern
!==
undefined
)
{
pattern
=
options
.
grep_pattern
;
}
gadget
.
props
.
element
.
querySelector
(
"
.search-pattern
"
)
.
value
=
pattern
;
return
displayURLList
(
gadget
,
undefined
);
})
.
push
(
function
()
{
return
gadget
.
props
.
start_deferred
.
resolve
();
});
})
.
declareService
(
function
()
{
var
gadget
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
gadget
.
props
.
start_deferred
.
promise
;
})
.
push
(
function
()
{
return
loopEventListener
(
gadget
.
props
.
element
.
querySelector
(
"
.crib-url-list-content
"
),
'
submit
'
,
false
,
function
(
event
)
{
gadget
.
redirect
({
page
:
"
grep
"
,
grep_pattern
:
gadget
.
props
.
element
.
querySelector
(
"
.search-pattern
"
)
.
value
});
}
);
});
});
}(
window
,
rJS
,
jIO
,
loopEventListener
));
\ No newline at end of file
gadget/gadget_cribjs_page_tools.html
View file @
1c804868
...
...
@@ -20,6 +20,7 @@
<li>
Check
<a
class=
"jslint"
href=
"#page=jslint"
>
JSLint
</a></li>
<li><a
class=
"mass_remove"
href=
"#page=mass_remove"
>
Remove
</a>
uncessary URLs
</li>
<li><a
class=
"select_site"
href=
"#page=select_site"
>
Select Site to Edit
</a></li>
<li><a
class=
"grep"
href=
"#page=grep"
>
Grep
</a>
among js and html files
</li>
</ul>
</div>
</body>
...
...
gadget/gadget_cribjs_page_tools.js
View file @
1c804868
...
...
@@ -22,7 +22,7 @@
.
declareAcquiredMethod
(
"
getUrlFor
"
,
"
getUrlFor
"
)
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
gadget
=
this
,
page_list
=
[
"
select_site
"
,
"
jslint
"
,
"
mass_remove
"
],
page_list
=
[
"
select_site
"
,
"
jslint
"
,
"
mass_remove
"
,
"
grep
"
],
promise_list
=
[];
page_list
.
forEach
(
function
(
page
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment