PDA

View Full Version : So i made this in my free time...



Plusle2019
21st January 2017, 20:51
http://i.imgur.com/GFPWas1.png

This is a global search bar. It doesn't really work. It's supposed to take you to a custom Google search but when I loaded it up on Liveweaver, it loaded the UI twice! So I am not sure if it actually works or not. Anyways, here's the code if the site admins wanna use it. It's actually a series of free to use tutorials involving the search bar but I changed them to fit the navbar. The Liveweaver did not let me edit the Navbar but I changed it's height a bit too.



HTML:

<form class="form-wrapper">
<input type="text" id="search" placeholder="Search for..." required>
<input type="submit" value="go" id="submit">
</form>

CSS:



.form-wrapper {

}

.form-wrapper #search {
border: 1px solid #CCC;
-webkit-box-shadow: 0 1px 1px #ddd inset, 0 1px 0 #FFF;
-moz-box-shadow: 0 1px 1px #ddd inset, 0 1px 0 #FFF;
box-shadow: 0 1px 1px #ddd inset, 0 1px 0 #FFF;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 12px;
color: #999;
float: left;
font: 16px Lucida Sans, Trebuchet MS, Tahoma, sans-serif;
height: 12px;
padding: 11px;
width: 320px;
}

.form-wrapper #search:focus {
border-color: #aaa;
-webkit-box-shadow: 0 1px 1px #bbb inset;
-moz-box-shadow: 0 1px 1px #bbb inset;
box-shadow: 0 1px 1px #bbb inset;
outline: 1;
}

.form-wrapper #search:-moz-placeholder,
.form-wrapper #search:-ms-input-placeholder,
.form-wrapper #search::-webkit-input-placeholder {
color: #666;
font-weight: normal;
}

.form-wrapper #submit {
background-color: #FFEBCD
background-image: -webkit-gradient(linear, left top, left bottom, from(#ADFF2F), to( #FFEBCD));
background-image: -webkit-linear-gradient(top, #ADFF2F, #FFEBCD);
background-image: -moz-linear-gradient(top, #31b2c3, #0483a0);
background-image: -ms-linear-gradient(top, #31b2c3, #0483a0);
background-image: -o-linear-gradient(top, #31b2c3, #0483a0);
background-image: linear-gradient(top, #31b2c3, #0483a0);
border: 1px solid #00748f;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 1px 0 #FFF;
-moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 1px 0 #FFF;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 1px 0 #FFF;
color: #F5F5DC;
cursor: pointer;
height: 32px;
float: left;
width: 50px;
font: 18px Arial, Helvetica;
padding: 0;
text-transform: uppercase;
text-shadow: 0 1px 0 rgba(0, 0 ,0, .3);

}



.form-wrapper #submit:hover,
.form-wrapper #submit:focus {
background-color: #31b2c3;
background-image: -webkit-gradient(linear, left top, left bottom, from(#0483a0), to(#31b2c3));
background-image: -webkit-linear-gradient(top, #0483a0, #31b2c3);
background-image: -moz-linear-gradient(top, #0483a0, #31b2c3);
background-image: -ms-linear-gradient(top, #0483a0, #31b2c3);
background-image: -o-linear-gradient(top, #0483a0, #31b2c3);
background-image: linear-gradient(top, #0483a0, #31b2c3);
}

.form-wrapper #submit:active {
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
outline: 0;
}

.form-wrapper #submit::-moz-focus-inner {
border: 0;
}

.navbar {
position:relative;
height: 73px;
background:#2f4456 none ;
margin:10px 0px 0px 0px;
color:rgb(255, 255, 255);
font: 11px Arial, Calibri, Verdana, Geneva, sans-serif;
border:0px solid rgb(255, 255, 255);
-moz-border-radius-bottomleft:5px;
-moz-border-radius-bottomright:5px;
-webkit-border-bottom-left-radius:5px;
-webkit-border-bottom-right-radius:5px;
border-bottom-left-radius:5px;
border-bottom-right-radius:5px;
}


Javascript

$(document).ready(function(){

var config = {
siteURL : 'mugenarchive.com', // Change this to your site
searchSite : true,
type : 'web',
append : false,
perPage : 8, // A maximum of 8 is allowed by Google
page : 0 // The start page
}

// The small arrow that marks the active search icon:
var arrow = $('<span>',{className:'arrow'}).appendTo('ul.icons');

$('ul.icons li').click(function(){
var el = $(this);

if(el.hasClass('active')){
// The icon is already active, exit
return false;
}

el.siblings().removeClass('active');
el.addClass('active');

// Move the arrow below this icon
arrow.stop().animate({
left : el.position().left,
marginLeft : (el.width()/2)-4
});

// Set the search type
config.type = el.attr('data-searchType');
$('#more').fadeOut();
});

// Adding the site domain as a label for the first radio button:
$('#siteNameLabel').append(' '+config.siteURL);

// Marking the Search tutorialzine.com radio as active:
$('#searchSite').click();

// Marking the web search icon as active:
$('li.web').click();

// Focusing the input text box:
$('#s').focus();

$('#searchForm').submit(function(){
googleSearch();
return false;
});

$('#searchSite,#searchWeb').change(function(){
// Listening for a click on one of the radio buttons.
// config.searchSite is either true or false.

config.searchSite = this.id == 'searchSite';
});

function googleSearch(settings){

// If no parameters are supplied to the function,
// it takes its defaults from the config object above:

settings = $.extend({},config,settings);
settings.term = settings.term || $('#s').val();

if(settings.searchSite){
// Using the Google site:example.com to limit the search to a
// specific domain:
settings.term = 'site:'+settings.siteURL+' '+settings.term;
}

// URL of Google's AJAX search API
var apiURL = 'http://ajax.googleapis.com/ajax/services/search/'+settings.type+
'?v=1.0&callback=?';
var resultsDiv = $('#resultsDiv');

$.getJSON(apiURL,{
q : settings.term,
rsz : settings.perPage,
start : settings.page*settings.perPage
},function(r){

var results = r.responseData.results;
$('#more').remove();

if(results.length){

// If results were returned, add them to a pageContainer div,
// after which append them to the #resultsDiv:

var pageContainer = $('<div>',{className:'pageContainer'});

for(var i=0;i<results.length;i++){
// Creating a new result object and firing its toString method:
pageContainer.append(new result(results[i]) + '');
}

if(!settings.append){
// This is executed when running a new search,
// instead of clicking on the More button:
resultsDiv.empty();
}

pageContainer.append('<div class="clear"></div>')
.hide().appendTo(resultsDiv)
.fadeIn('slow');

var cursor = r.responseData.cursor;

// Checking if there are more pages with results,
// and deciding whether to show the More button:

if( +cursor.estimatedResultCount > (settings.page+1)*settings.perPage){
$('<div>',{id:'more'}).appendTo(resultsDiv).click(function (){
googleSearch({append:true,page:settings.page+1});
$(this).fadeOut();
});
}
}
else {

// No results were found for this search.

resultsDiv.empty();
$('<p>',{
className : 'notFound',
html : 'No Results Were Found!'
}).hide().appendTo(resultsDiv).fadeIn();
}
});
}

function result(r){

// This is class definition. Object of this class are created for
// each result. The markup is generated by the .toString() method.

var arr = [];

// GsearchResultClass is passed by the google API
switch(r.GsearchResultClass){

case 'GwebSearch':
arr = [
'<div class="webResult">',
'<h2><a href="',r.url,'">',r.title,'</a></h2>',
'<p>',r.content,'</p>',
'<a href="',r.url,'">',r.visibleUrl,'</a>',
'</div>'
];
break;
case 'GimageSearch':
arr = [
'<div class="imageResult">',
'<a href="',r.url,'" title="',r.titleNoFormatting,
'" class="pic" style="width:',r.tbWidth,'px;height:',r.tbHeight,'px;">',
'<img src="',r.tbUrl,'" width="',r.tbWidth,'" height="',
r.tbHeight,'" /></a>','<div class="clear"></div>',
'<a href="',r.originalContextUrl,'">',r.visibleUrl,'</a>',
'</div>'
];
break;
case 'GvideoSearch':
arr = [
'<div class="imageResult">',
'<a href="',r.url,'" title="',r.titleNoFormatting,'
" class="pic" style="width:150px;height:auto;">',
'<img src="',r.tbUrl,'" width="100%" /></a>',
'<div class="clear"></div>','<a href="',
r.originalContextUrl,'">',r.publisher,'</a>',
'</div>'
];
break;
case 'GnewsSearch':
arr = [
'<div class="webResult">',
'<h2><a href="',r.unescapedUrl,'">',r.title,'</a></h2>',
'<p>',r.content,'</p>',
'<a href="',r.unescapedUrl,'">',r.publisher,'</a>',
'</div>'
];
break;
}

// The toString method.
this.toString = function(){
return arr.join('');
}
}
});