Skip to content

Commit 3e62c83

Browse files
committed
0.0.2
1 parent 0477deb commit 3e62c83

11 files changed

Lines changed: 2130 additions & 3 deletions

‎index.html‎

Lines changed: 165 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,189 @@
1111
.main-container{
1212
padding: 40px;
1313
}
14+
.search-form .title{
15+
text-align: center;
16+
padding: 20px 100px;
17+
}
18+
.search-result{
19+
padding: 40px 0;
20+
}
21+
blockquote{
22+
text-align: center;
23+
}
1424
</style>
1525
</head>
1626
<body>
1727
<section class="main-container">
18-
<div class="row">
28+
<section class="row search-form">
29+
<header class="title">
30+
<header><h1>Codelf</h1></header>
31+
<h5>Search over projects from Github, Bitbucket, Google Code, Codeplex, Sourceforge, Fedora Projec to find a <span class="label label-success">variable name</span> for you!</h5>
32+
</header>
1933
<div class="col-lg-12">
2034
<div class="input-group">
21-
<input type="text" class="form-control" placeholder="Search for...e.g.product">
35+
<input type="text" class="form-control" placeholder="Search a variable name...e.g.product">
2236
<span class="input-group-btn">
2337
<button class="btn btn-secondary" type="button">Search</button>
2438
</span>
2539
</div>
2640
</div>
27-
</div>
41+
</section>
42+
<section class="row search-result">
43+
<div class="col-lg-12">
44+
<div class="alert alert-success bd" role="alert">
45+
<blockquote>
46+
<p>"There are only two hard things in Computer Science: cache invalidation and naming things." -- Phil Karlton</p>
47+
</blockquote>
48+
<script type="text/html">
49+
<span class="label label-{type}" data-toggle="tooltip" data-placement="top" title="{val}">{val}</span>
50+
</script>
51+
</div>
52+
</div>
53+
</section>
2854
</section>
55+
<script src="src/lib/tether/js/tether.min.js"></script>
2956
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
3057
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"
3158
integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7"
3259
crossorigin="anonymous"></script>
3360
<script>
61+
$(function () {
62+
function randomList(list, len, verify, ratio) {
63+
var rs = [], _list = list.slice(0);
64+
len = len || _list.length;
65+
ratio = ratio ? ratio : 0;
66+
function rd(_array) {
67+
_array = _array.sort(function () {
68+
return (0.5 - Math.random());
69+
});
70+
}
71+
72+
while (ratio) {
73+
rd(_list);
74+
ratio--;
75+
}
76+
if (_list.length <= len) {
77+
rs = _list;
78+
} else {
79+
while (rs.length < len) {
80+
var index = Math.floor(Math.random() * _list.length),
81+
item = _list[index];
82+
if (( verify && verify.call(this, item, _list) ) || !verify) {
83+
rs.push(item);
84+
_list.splice(index, 1);
85+
}
86+
}
87+
}
88+
return rs;
89+
}
90+
function searchPage(){
91+
var page = 1;
92+
var lastVal;
93+
var searchRequestCallback;
94+
this.resetPage = function(){
95+
page = 1;
96+
}
97+
this.request = function(val,callback){
98+
if(val==lastVal){
99+
this.resetPage();
100+
}
101+
lastVal = val;
102+
searchRequestCallback = callback;
103+
lastVal && $.ajax({
104+
type: 'GET',
105+
url: 'https://searchcode.com/api/jsonp_codesearch_I/?q=soup&lan=html,sass,js&p=1&callback=afterSearch',
106+
dataType: 'jsonp',
107+
jsonp: false,
108+
jsonpCallback: false,
109+
contentType: "application/json",
110+
data: {
111+
q: lastVal,
112+
p: page,
113+
per_page: 100,
114+
callback: 'afterSearchRequest'
115+
}
116+
});
117+
}
118+
window.afterSearchRequest = function(data){
119+
if(data){
120+
page++;
121+
searchRequestCallback && searchRequestCallback(data);
122+
}
123+
}
124+
}
125+
126+
var els = {
127+
searchForm: $('.search-form'),
128+
searchInput: $('.search-form input'),
129+
searchBtn: $('.search-form button'),
130+
131+
searchResult: $('.search-result'),
132+
searchResultTpl: $('.search-result script').html(),
133+
searchResultBd: $('.search-result .bd'),
134+
135+
lastVal: ''
136+
},
137+
searchObj;
138+
139+
function bindEvent(){
140+
els.searchInput.on('keyup',renderSearchBtn);
141+
els.searchBtn.on('click',onSearch);
142+
els.searchInput.keypress(function (e) {
143+
if (e.which == 13) {
144+
onSearch();
145+
return false;
146+
}
147+
});
148+
}
149+
function init(){
150+
bindEvent();
151+
searchObj = new searchPage(renderSearchResult);
152+
}
153+
154+
function onSearch(){
155+
var val = els.searchInput.val().trim();
156+
if(val){
157+
els.lastVal = val;
158+
els.valReg = new RegExp('(([-_\w\d]*)?'+els.lastVal+'([-_\w\d]*)?)','ig');
159+
searchObj.request(els.lastVal,renderSearchResult);
160+
renderSearchBtn();
161+
}
162+
}
163+
164+
function renderSearchResult(data){
165+
var vals = [],labels = [],allStr = [];
166+
data.results.forEach(function(rkey){
167+
for(var lkey in rkey.lines){
168+
allStr.push(rkey.lines[lkey]);
169+
}
170+
});
171+
$.each([].slice.call(allStr.join('').match(els.valReg)), function(i, el){
172+
if($.inArray(el, vals) === -1) vals.push(el);
173+
});
174+
vals.forEach(function(key){
175+
labels.push(els.searchResultTpl.replace('{type}',getRandomLabelType()).replace(/\{val\}/g,key));
176+
});
177+
if(labels.length){
178+
els.searchResultBd.html(labels.join(''));
179+
els.searchResult.find('[data-toggle="tooltip"]').tooltip();
180+
els.searchResult.show();
181+
}else{
182+
els.searchResult.hide();
183+
}
184+
}
185+
186+
function renderSearchBtn(){
187+
els.searchBtn.html(els.searchInput.val().trim()==els.lastVal?'Next Group':'Search');
188+
}
189+
190+
function getRandomLabelType(){
191+
var types = ['default','primary','success','info','warning','warning','danger'];
192+
return randomList(types,1,null,10)[0];
193+
}
34194

195+
init();
196+
})
35197
</script>
36198
</body>
37199
</html>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
.tether-element, .tether-element:after, .tether-element:before, .tether-element *, .tether-element *:after, .tether-element *:before {
2+
box-sizing: border-box; }
3+
4+
.tether-element {
5+
position: absolute;
6+
display: none; }
7+
.tether-element.tether-open {
8+
display: block; }
9+
10+
.tether-element.tether-theme-arrows-dark {
11+
max-width: 100%;
12+
max-height: 100%; }
13+
.tether-element.tether-theme-arrows-dark .tether-content {
14+
border-radius: 5px;
15+
position: relative;
16+
font-family: inherit;
17+
background: #000;
18+
color: #fff;
19+
padding: 1em;
20+
font-size: 1.1em;
21+
line-height: 1.5em; }
22+
.tether-element.tether-theme-arrows-dark .tether-content:before {
23+
content: "";
24+
display: block;
25+
position: absolute;
26+
width: 0;
27+
height: 0;
28+
border-color: transparent;
29+
border-width: 16px;
30+
border-style: solid; }
31+
.tether-element.tether-theme-arrows-dark.tether-element-attached-bottom.tether-element-attached-center .tether-content {
32+
margin-bottom: 16px; }
33+
.tether-element.tether-theme-arrows-dark.tether-element-attached-bottom.tether-element-attached-center .tether-content:before {
34+
top: 100%;
35+
left: 50%;
36+
margin-left: -16px;
37+
border-top-color: #000; }
38+
.tether-element.tether-theme-arrows-dark.tether-element-attached-top.tether-element-attached-center .tether-content {
39+
margin-top: 16px; }
40+
.tether-element.tether-theme-arrows-dark.tether-element-attached-top.tether-element-attached-center .tether-content:before {
41+
bottom: 100%;
42+
left: 50%;
43+
margin-left: -16px;
44+
border-bottom-color: #000; }
45+
.tether-element.tether-theme-arrows-dark.tether-element-attached-right.tether-element-attached-middle .tether-content {
46+
margin-right: 16px; }
47+
.tether-element.tether-theme-arrows-dark.tether-element-attached-right.tether-element-attached-middle .tether-content:before {
48+
left: 100%;
49+
top: 50%;
50+
margin-top: -16px;
51+
border-left-color: #000; }
52+
.tether-element.tether-theme-arrows-dark.tether-element-attached-left.tether-element-attached-middle .tether-content {
53+
margin-left: 16px; }
54+
.tether-element.tether-theme-arrows-dark.tether-element-attached-left.tether-element-attached-middle .tether-content:before {
55+
right: 100%;
56+
top: 50%;
57+
margin-top: -16px;
58+
border-right-color: #000; }
59+
.tether-element.tether-theme-arrows-dark.tether-element-attached-top.tether-element-attached-left.tether-target-attached-bottom .tether-content {
60+
margin-top: 16px; }
61+
.tether-element.tether-theme-arrows-dark.tether-element-attached-top.tether-element-attached-left.tether-target-attached-bottom .tether-content:before {
62+
bottom: 100%;
63+
left: 16px;
64+
border-bottom-color: #000; }
65+
.tether-element.tether-theme-arrows-dark.tether-element-attached-top.tether-element-attached-right.tether-target-attached-bottom .tether-content {
66+
margin-top: 16px; }
67+
.tether-element.tether-theme-arrows-dark.tether-element-attached-top.tether-element-attached-right.tether-target-attached-bottom .tether-content:before {
68+
bottom: 100%;
69+
right: 16px;
70+
border-bottom-color: #000; }
71+
.tether-element.tether-theme-arrows-dark.tether-element-attached-bottom.tether-element-attached-left.tether-target-attached-top .tether-content {
72+
margin-bottom: 16px; }
73+
.tether-element.tether-theme-arrows-dark.tether-element-attached-bottom.tether-element-attached-left.tether-target-attached-top .tether-content:before {
74+
top: 100%;
75+
left: 16px;
76+
border-top-color: #000; }
77+
.tether-element.tether-theme-arrows-dark.tether-element-attached-bottom.tether-element-attached-right.tether-target-attached-top .tether-content {
78+
margin-bottom: 16px; }
79+
.tether-element.tether-theme-arrows-dark.tether-element-attached-bottom.tether-element-attached-right.tether-target-attached-top .tether-content:before {
80+
top: 100%;
81+
right: 16px;
82+
border-top-color: #000; }
83+
.tether-element.tether-theme-arrows-dark.tether-element-attached-top.tether-element-attached-right.tether-target-attached-left .tether-content {
84+
margin-right: 16px; }
85+
.tether-element.tether-theme-arrows-dark.tether-element-attached-top.tether-element-attached-right.tether-target-attached-left .tether-content:before {
86+
top: 16px;
87+
left: 100%;
88+
border-left-color: #000; }
89+
.tether-element.tether-theme-arrows-dark.tether-element-attached-top.tether-element-attached-left.tether-target-attached-right .tether-content {
90+
margin-left: 16px; }
91+
.tether-element.tether-theme-arrows-dark.tether-element-attached-top.tether-element-attached-left.tether-target-attached-right .tether-content:before {
92+
top: 16px;
93+
right: 100%;
94+
border-right-color: #000; }
95+
.tether-element.tether-theme-arrows-dark.tether-element-attached-bottom.tether-element-attached-right.tether-target-attached-left .tether-content {
96+
margin-right: 16px; }
97+
.tether-element.tether-theme-arrows-dark.tether-element-attached-bottom.tether-element-attached-right.tether-target-attached-left .tether-content:before {
98+
bottom: 16px;
99+
left: 100%;
100+
border-left-color: #000; }
101+
.tether-element.tether-theme-arrows-dark.tether-element-attached-bottom.tether-element-attached-left.tether-target-attached-right .tether-content {
102+
margin-left: 16px; }
103+
.tether-element.tether-theme-arrows-dark.tether-element-attached-bottom.tether-element-attached-left.tether-target-attached-right .tether-content:before {
104+
bottom: 16px;
105+
right: 100%;
106+
border-right-color: #000; }

‎src/lib/tether/css/tether-theme-arrows-dark.min.css‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)