Skip to content

Commit

Permalink
Merge pull request #3 from krisdb2009/master
Browse files Browse the repository at this point in the history
1.2
  • Loading branch information
krisdb2009 committed Jul 31, 2017
2 parents 63d8ba5 + d3d3ed0 commit 3985aae
Showing 1 changed file with 60 additions and 55 deletions.
115 changes: 60 additions & 55 deletions index.php
Expand Up @@ -48,6 +48,7 @@ function setNumber($PhoneNumber = 0, $description = '') { //Set/Create the descr
}
function setTags($uid = '', $tags = array()) { //Sets the tags on a number.
$db = loadDB('tags');
$tags = array_unique($tags);
foreach($db as $tag => $uids) { //Remove number from all tags. And remove any empty tags. And remove tags with special characters.
foreach($uids as $k => $tuid) { //Remove number's UID from tag.
if($tuid == $uid) {
Expand Down Expand Up @@ -83,7 +84,7 @@ function deleteNumber($uid) { //Deletes a number using ID
if($postJson !== null) { //JSON is valid
$tags = loadDB('tags');// Load tags from database
$score = array(); //Define arrays
$result = array();
$result = array();
foreach($postJson as $k => $v) { //Foreach search term recieved
$searchTag = strtolower($v); //Change caps to lower case
if(isset($tags[$searchTag]) && !empty($tags[$searchTag])) { //If search tag exists in database and has a value
Expand All @@ -103,6 +104,7 @@ function deleteNumber($uid) { //Deletes a number using ID
}
array_push($result, getNumber($k)); //Otherwise add number to the result
}
sort($result);
echo json_encode($result); //Output result in json
}
}
Expand Down Expand Up @@ -187,6 +189,7 @@ function deleteNumber($uid) { //Deletes a number using ID
};
var numberMode = false;
var descriptionMode = false;
var lastSearchTags = '[]';
//Functions
function time() { //Return unix timestamp
return Math.round((new Date()).getTime() / 1000);
Expand Down Expand Up @@ -353,43 +356,47 @@ function sendTagsAndDescription() { //Send all tags to database
}
function searchTags() { //grab all tags and search the database and return the result on screen.
var tags = [];
$('#numbers').html('');
$.each($('#input > span'), function() { //For each bubble
selectBubble($(this));
if(typeFilled()) {
tags.push($(this).text()); //push to array to send later
}
});
$.ajax({ //Send search query
type: 'post',
async: true,
url: apiURI,
dataType: 'json',
data: {
api: 'search',
filter: true,
search: JSON.stringify(tags)
},
success: function(numbers) { //On success
$.each(numbers, function() {
var num = $('<div><span class="number">'+this+'</span><span class="description">...</span></div>').appendTo('#numbers'); //Show each number on screen
$.ajax({ //Request tags
type: 'post',
async: true,
url: apiURI,
dataType: 'json',
data: {
api: 'export',
export: 'number',
number: this
},
success: function(data) {
num.find('.description').text(data.description); //Grab description and place on number
}
jtags = JSON.stringify(tags);
if(jtags !== lastSearchTags) {
lastSearchTags = jtags;
$.ajax({ //Send search query
type: 'post',
async: true,
url: apiURI,
dataType: 'json',
data: {
api: 'search',
filter: true,
search: jtags
},
success: function(numbers) { //On success
$('#numbers').html(''); //Clear numbers
$.each(numbers, function() {
var num = $('<div><span class="number">'+this+'</span><span class="description">...</span></div>').appendTo('#numbers'); //Show each number on screen
$.ajax({ //Request tags
type: 'post',
async: true,
url: apiURI,
dataType: 'json',
data: {
api: 'export',
export: 'number',
number: this
},
success: function(data) {
num.find('.description').text(data.description); //Grab description and place on number
}
});
});
});
}
});
}
});
}
}
function numberModeOff() { //Turns number mode off
$('#input').html('<span class="type"></span>');
Expand Down Expand Up @@ -459,20 +466,6 @@ function numberModeOn() { //Turns number mode on
if(!numberMode) {
searchTags();
}
} else if(e.key == 'Backspace') {
if($('#input .type').text() == '') { //If selected bubble has not text
deleteSelectedBubble();
$('#input span:last').addClass('type'); //Make the last one typeable
} else {
$('#input .type').text($('#input .type').text().slice(0, -1)); //Remove one character from end of selected bubble
}
if($('#input span:first')[0] == $('#input .type')[0] && numberMode) { //If first bubble is number and changed
loadNumberTags($('#input .type').text());
}
$('#input .type').removeClass('saved'); //Remove edited color
if(!numberMode) {
searchTags();
}
} else if(e.key == 'ArrowLeft') {
selectBubble($('#input .type').prev());
} else if(e.key == 'ArrowRight') {
Expand All @@ -483,25 +476,37 @@ function numberModeOn() { //Turns number mode on
} else if(e.key == 'End' || e.key == 'Escape') {
$('#numbers').html('');
$('#input').html('<span class="type"></span>'); //Erase all content and reset
} else if(e.key.length == 1) { //Any other key pressed
if(typeValid() || numberMode || !typeFilled()) { //If type is valid, or in number mode, or type has no text
} else if(e.key.length == 1 || e.key == 'Backspace') { //Any other key pressed
if(e.key == 'Backspace') {
if($('#input .type').text() == '') { //If selected bubble has not text
deleteSelectedBubble();
$('#input span:last').addClass('type'); //Make the last one typeable
} else {
$('#input .type').text($('#input .type').text().slice(0, -1)); //Remove one character from end of selected bubble
}
} else {
$('#input .type').append(e.key.toLowerCase()); //Type the key
}
$('#input .type .autofill').remove(); //Remove autofill
var autoFill = autoFillTag($('#input .type').text().replace($('#input .type .autofill').text(), '')); //Grab non autofilled text
if(autoFill !== '') {
$('<span class="autofill">'+autoFill+'</span>').appendTo('#input .type'); //Create autofill
$('#input .type .autofill').remove(); //Remove autofill
var autoFill = autoFillTag($('#input .type').text().replace($('#input .type .autofill').text(), '')); //Grab non autofilled text
if(autoFill !== '') {
$('<span class="autofill">'+autoFill+'</span>').appendTo('#input .type'); //Create autofill
}
}
$('#input .type').removeClass('saved');
if($('#input span:first').text().match(/^\d+$/)) { // If only a number
numberModeOn();
}
if(typeFilled() && !numberMode && !typeValid() && e.key !== 'Backspace') { //If type is valid, or in number mode, or type has no text
$('#input .type').text($('#input .type').text().slice(0, -1)); //Remove one character from end of selected bubble
}
if($('#input span:first')[0] == $('#input .type')[0] && numberMode) { //If first bubble is number and changed
loadNumberTags($('#input .type').text());
}
if(!numberMode) {
searchTags();
}
setTimeout(function() {
if(!numberMode && allValid()) {
searchTags();
}
});
}
if(!$('#input span:first').text().match(/^\d+$/) && numberMode) {
numberModeOff();
Expand Down

0 comments on commit 3985aae

Please sign in to comment.