Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this loads the navbar
- $('#navigation').load('./assets/includes/navbar.html');
- //loads the footer
- $('#footer').load('./assets/includes/footer.html');
- //function that makes the searchbar appear and disappear
- $(function(){
- // cahce some dom
- var $searchIcon = $('#search-icon');
- var $searchinput = $('#search');
- // search icon effect
- $searchIcon.on('click', function(){
- $searchinput.animate({width:'toggle'},350);
- });
- // When you press a button in the search bar
- $searchinput.on('keydown',function(){
- // query the request that someone just entered
- console.log(this.value);
- });
- });
- //functuon that destroys the PHP session when called
- function logout(){
- $.ajax({type: "GET",url: "../assets/php/logout.php"});
- //send the user back to the login page once the session has been destroyed
- window.location.replace("index.php");
- };
- //function sem tæmir formið að öllu leiti sé þess óskað
- function wipeForm () {
- //reset the main form
- $('#data')[0].reset();
- //delete everything from the tagContainer
- $('#tagContainer').empty();
- //fix the innerHTML of the fileselector
- $('#chosenFile')[0].innerHTML = "Enginn skrá valinn";
- //remove the done class from the file selector
- $('#chosenFile').removeClass('done');
- //empty the array of tags
- tagArray = [];
- }
- //
- //
- //Here is code for addProject.php
- //
- //
- //This if statement prevents an undefined error on pages where the allTags array is unused, also I can define it as something returned by PHP
- if (typeof allTags === 'undefined') {
- allTags = new Array();
- }
- /*This function takes activates once a file has
- been selected, then it takes the name of the file
- selected and tells the user the name of the file
- then it also makes the color of the div blue, in
- order to indicate that the file has been selected*/
- $('#fileToUpload').change(function(e){
- //grab the correct textbox
- var outputTextbox = $('#chosenFile');
- var text = e.target.value;
- //split the array of text
- var arr = text.split('\\');
- //takes the last index of the array
- text = arr[arr.length - 1];
- //sets the innerHTML to the name of the file
- outputTextbox[0].innerHTML = text;
- //changes some styles
- outputTextbox.css("color", "white");
- outputTextbox.css("background-color", "#303c74");
- });
- //the jQueryUI autocomplete function
- $( "#tagMaker" ).autocomplete({
- //Select the correct sourceArray for the autocomplete function
- source: allTags
- });
- // define varibles
- var tagArray = new Array();
- /*this function contains all functionality associated with the front-side of
- tags. It generates a div based on the input from the user and adds a cancel
- button as well as an eventlistener that runs a function that removes the tag,
- both from the final array and from the user interface*/
- var textBoxToggled = function(){
- //grab the box that contains all the tags
- var box = $('#tagContainer');
- //grab the text from the input
- var tag = $('#tagMaker').val();
- //some input validations
- //if the tag is empty, alert the user
- if (tag == "") {
- swal("Tagið má ekki vera tómt");
- //exit from the function
- return;
- };
- //if the tag is already in the array, alert the user
- if ($.inArray(tag, tagArray) > -1) {
- swal("Bara er hægt að nota hvert tag einu sinni");
- return;//kill the function
- };
- //add the tag to the tagArray
- tagArray.push(tag);
- //create the elements for the div and the delete button
- var deletr = document.createElement("div");
- var thing = document.createElement("span");
- //put the element in the main container
- box.append(thing);
- //put the tag inside the tagContainer
- thing.innerHTML = tag;
- //add the appropriate class to the tag
- thing.className = "chosenTag";
- //add the appropriate tags to the cancel button
- deletr.className = "fa fa-times deleteTag";
- //add an eventlistener to the x element
- deletr.addEventListener("click", deleteThing);
- //put the delete element inside of the tag container
- thing.appendChild(deletr);
- //empty the textbox
- document.getElementById('tagMaker').value = "";
- $('#tagMaker').focus(); // put focus back on the textbox
- //remove the added tag from the source array of the autocomplete dropdown
- allTags.splice($.inArray(tag, allTags), 1);
- };
- //this runs the function if either enter or the "add" button is pressed
- $("#confirmTag").click(textBoxToggled); // if the add button is pressed
- $('#tagMaker').keypress(function(e){ // if enter is presed whilest over the text box.
- if(e.which == 13){//run the function also if enter is pressed
- textBoxToggled();
- };
- });
- //function that removed the relevant tag if the X button is pressed
- function deleteThing () {
- var soonGone = this.closest('.chosenTag');//selects the closes parent element with the .chosenTag class, in this case it will be the relevant tag
- console.log(soonGone);
- var toBeRemoved = soonGone.textContent;//this selects the text from the same tag
- console.log(toBeRemoved);
- tagArray.splice($.inArray(toBeRemoved, tagArray), 1);//remove the tag from the array that will be sent via Ajax
- allTags.push(toBeRemoved);//add the removed tag back to the dropdown
- soonGone.remove();//remove the closest tag
- console.log("lala");
- }
- /*This function runs if the correct button is submitted, the function
- takes all the information from the form, sends it via AJAX to a PHP file
- after preforming some validation checks*/
- $("#submitUpload").click(function(){
- //Here are some checks that make sure that all the inputs are filled and alerts the user if he missed any inputs
- var checkName = $('#name').val();
- var checkDescription = $('#description').val();
- var checkFile = $('#fileToUpload').val();
- var checkSubject = $('#subject').val();
- var checkGrades = $('#allGrades :checkbox:checked');
- //brutal if statment that checks if any information is missing from any inputs
- if (!checkName || !checkDescription || !checkFile || checkSubject == "Veldu fag sem hentar!" || checkGrades.length <= 0 || tagArray.length <= 0) {
- //make the soon-to-be-returned text as an array
- var subText = new Array();
- //add the first constant to an array
- subText.push("Það vantar ")
- //this could be a switch, but fuck switch statements
- //several if statments that check if the info is missing from each individual input
- //if the name is empty
- if (!checkName) {
- //add to the array
- subText.push("nafn");
- };
- //if the desciption is empty
- if (!checkDescription) {
- //add to the array
- subText.push("lýsingu");
- };
- //if the file is empty
- if (!checkFile) {
- //add to the array
- subText.push("skrá");
- };
- //if the subject is still the default
- if (checkSubject == "Veldu fag sem hentar!") {
- //add to the array
- subText.push("eitthvað fag");
- };
- //if the grade array is less than or equal to 0
- if (checkGrades.length <= 0) {
- //add to the array
- subText.push("eitthvern bekk");
- };
- //if the tagArray is less than or equal to 0
- if (tagArray.length <= 0) {
- //add to the array
- subText.push("eitthvað tag");
- };
- //define the seperator variable
- var comma = ", ";
- //make a new array to insert the mixed array into
- var realArray = new Array();
- //loop that runs as long as the array is long
- for (var i = 0; i < subText.length; i++) {
- //add the current index of the old array to the new one
- realArray.push(subText[i]);
- //if the length of the array is more than two, add commas in between
- if (subText.length > 2) {
- //if the loop is not at the first, second last or last index of the array, add a comma to the array
- if (i != 0 && i != subText.length -2 && i != subText.length -1) {
- realArray.push(comma);
- };
- //add an "og" to the second to last index of the array
- if (i == subText.length -2) {
- realArray.push(" og ");
- };
- };
- };
- //console.log(realArray);
- //alert the user if something is missing.
- swal("Það vantar eitthvað", realArray.join(""), "error");
- }
- //checks passed, do stuff and things
- else{
- /*make the users confirm that they indeed want to upload the file
- if they do, send the all of the form data to a PHP file via AJAX and
- if that is completed successfully send the tags, along with the ID of
- the upload to a different PHP file to be inserted seperately. The reason
- for this seperation is that we were having issues with uploading files and
- data at the same time so that we decided to send all the info from the
- form into a PHP document and then add the tags seperately*/
- swal({
- //all this stuff is for the sweetalert plugin
- title: "Viss ?",
- text: "Ertu viss um að þú viljir senda verkefnið inn?",
- type: "warning",
- showCancelButton: true,
- confirmButtonColor: "#20E82E",
- confirmButtonText: "Já, Senda inn",
- cancelButtonText: "Nei, Ekki senda",
- closeOnConfirm: false,
- closeOnCancel: false
- },
- //this is what happens if the user confirms the selection
- function(isConfirm){
- if (isConfirm) {
- //take all the available formdata from the form
- //this is unable to take in the tags, so they will be inserted later
- //the actual ajax
- var formData = new FormData($("form#data")[0]);
- var tagsToSend = tagArray;
- wipeForm();
- $.ajax({
- url: "assets/php/upload.php",//target the correct file
- type: 'POST',//use POST for this
- data: formData,//define the date that will be sent
- success: function (data) {//if the ajax is successful, do this
- //this is a different Ajax query that sends the information about the tags to the database
- //it only runs if the other function is successful
- var uploadID = data;
- $.ajax({
- url: 'assets/php/addTagToUpload.php',//target the correct file
- type: 'POST',//use POST
- data: {//the data array that will be sent to the PHP
- id:uploadID,
- tags:tagsToSend
- },
- success: function(tagData) {//if successful
- console.log(tagData);
- swal("Sent!", "Verkefni þitt hefur verið sent!", "success");
- }
- });
- },
- cache: false,//don't cache
- contentType: false,//don't use a specific content type
- processData: false//don't process the data specially
- });
- }
- else {
- swal("Hætt við", "Verkefnið var ekki sent", "error");
- }
- });
- return false;//don't return anything
- }
- });
- //
- //
- //Code for addProject.php is now done
- //
- //
- //
- //
- //Code for editProject.php
- //
- //
- /*this is for preventing undefined variables
- because this is a function that requires data
- returned from PHP*/
- if (typeof sendIdOverToJS === 'undefined') {
- sendIdOverToJS = null;
- }
- //is the user reject the changes, do this
- $('#rejectChanges').click(function () {
- //tell the user
- swal("Breytingum hafnað", "", "error");
- //wait 1500ms then redirect the user
- setTimeout(function() {
- //redirect backwards
- if(document.referrer.indexOf(window.location.hostname) != -1){
- parent.history.back();
- return false;
- }
- }, 1500);
- });
- //if the user decites to delete the project, this runs
- $('#deleteProject').on('click', function() {
- //tell the user to confirm the selection
- swal({
- title: "Eru viss um að þú viljir gera þetta?",
- text: "Það er ekki hægt að endurheimta eydd verkefni",
- type: "warning",
- showCancelButton: true,
- confirmButtonColor: "#303c74",
- confirmButtonText: "Já, ég vill eyða verkefninu",
- closeOnConfirm: false
- //this happens if the user presses yes
- }, function() {
- $.ajax({
- url: 'assets/php/deleteUpload.php',//target the correct file
- type: 'POST',
- data: {id:sendIdOverToJS},//send the id of the upload
- success: function(data) {
- //tell the user that the project has been removed
- swal("Eytt!", "Verkefninu þínu hefur verið eytt", "success");
- setTimeout(function() {
- window.location.href = "index.php";
- }, 1500);
- }
- });
- });
- });
- /*this sends data to a PHP document over AJAX
- in order to update the information of the upload*/
- var grades = new Array();
- $('#acceptChanges').click(function() {
- var name = $('#name').val();
- var description = $('#description').val();
- var subject = $('#subject').val();
- $.each($("input[name='grades[]']:checked"), function() {
- grades.push($(this).val());
- });
- $.ajax({
- url: 'assets/php/editProject.php',
- type: 'POST',
- data: {
- id:sendIdOverToJS,
- name:name,
- description:description,
- subject:subject,
- grades:grades,
- tags:tagArray
- },
- success: function(data) {
- console.log(data);
- swal("Breytingar mótteknar", "", "success");
- setTimeout(function() {
- // Whatever you want to do after the wait
- if(document.referrer.indexOf(window.location.hostname) != -1){
- parent.history.back();
- return false;
- }
- }, 1500);
- }
- });
- });
- //adds the delete function to the click event of the premade tags
- $('.chosenTag').each(function () {
- this.addEventListener("click", deleteThing);
- });
- //remove the currenty selected tags from the autocomplete list
- allTags = $.grep(allTags, function(value) {
- return $.inArray(value, tagArray) < 0;
- });
- //set the source of the autocomplete list
- $( "#tagMaker" ).autocomplete({
- source: allTags
- });
- //
- //
- //Here the code for editProject.php ends
- //
- //
- //
- //
- //Here the code for editSchool.php starts
- //
- //
- // fetch the school intel through ajax
- var getSchoolInfo = function(){
- $.ajax({
- url: "assets/php/getSchoolIntel.php",
- type: "GET",
- success: function(data){
- // work with the intel from the php file.
- var info = JSON.parse(data);
- // put the content in the right place
- if ($('#city').length) {//check if city exists
- $('#name')[0].value = info['name'];
- $('#city')[0].value = info['city'];
- $('#address')[0].value = info['address'];
- $('#postCode')[0].value = info['postCode'];
- }
- else{
- return;
- }
- }
- });
- }
- // send new intel to be updated
- var UpdateInfo = function(){
- // get the info
- var name = $('#name')[0].value;
- var city = $('#city')[0].value;
- var address = $('#address')[0].value;
- var postcode = $('#postCode')[0].value;
- $.ajax({
- url: "assets/php/updateSchoolInfo.php",
- type: "POST",
- data: {
- name: name,
- city: city,
- address: address,
- postCode: postcode
- },
- success: function(data){
- console.log(data);
- getSchoolInfo();
- }
- });
- };
- $('#submitChanges').on('click',function(){
- UpdateInfo();
- })
- getSchoolInfo();
- //
- //
- //Here the code for editSchool.php ends
- //
- //
- //
- //
- //Here the code for user.php starts
- //
- //
- /*Block of code that takes care of showing and hiding the tabs*/
- $('.tabs .tab-links a').on('click', function(e) {
- var currentAttrValue = $(this).attr('href');
- // Show the selected tabs and hide the ones that aren't
- $('.tabs ' + currentAttrValue).show().siblings().hide();
- // Change/remove current tab to active
- $(this).parent('li').addClass('active').siblings().removeClass('active');
- e.preventDefault();
- });
- //
- //
- //Here the code for user.php ends
- //
- //
- //
- //
- //Here the code for userSettings.php
- //
- //
- //checks if the new passwords match, and if they do sends it to the PHP
- //don't even try to modify this to pass on a bad password, the PHP also preformes validation checks
- $('#confirmPassChange').click(function() {
- //take in the three variables
- console.log("clicked");
- var oldPass = $('#oldPass').val();
- var newPass0 = $('#newPass0').val();
- var newPass1 = $('#newPass1').val();
- //if one of the fields has not been set, alert the user
- if (!newPass0 || !newPass1 || !oldPass) {
- swal("Þú þarft að filla í alla reitina", "", "error");
- //return prevents the rest of the code from executing
- return;
- };
- //if the passwords match, run the ajax
- if (newPass0 == newPass1) {
- $.ajax({
- //targets the file
- url: 'assets/php/changePass.php',
- //use post
- type: 'POST',
- //send over the data
- data: {
- oldPass:oldPass,
- newPass1:newPass1,
- newPass0:newPass0
- },
- //if successful....
- success: function(data) {
- //console.log(data);
- //if successful
- //console.log(data);
- if (data=="success") {swal("Lykilorðinu hefur verið breytt", "Notaðu það þegar þú skráir þig inn næst", "success");};
- //if the old pass was wrong
- if (data=="nofit") {swal("Gamla lykilorðið var ekki rétt", "Því hefur ekki verið breytt", "error");};
- //reset the password form
- }
- });
- };
- //if the password do not match
- if (newPass0 != newPass1){
- //alert the user
- swal("Lykilorðin eru ekki eins", "", "error");
- }
- });
- //this code sends stuff to the PHP document
- //make the arrays out of relevant scope for debugging purposes
- var grades = new Array();
- var subjects = new Array();
- //keep it in a document.ready function
- $(document).ready(function() {
- //on the click of the button
- $('#submitUserChanges').on('click', function() {
- //set the variables
- var name = $('#name').val();
- var address = $('#address').val();
- var email = $('#email').val();
- var phone = $('#phone').val();
- //load the info for grades and subjects into arrays
- $.each($("input[name='grade']:checked"), function() {
- grades.push($(this).val());
- });
- $.each($("input[name='subjects']:checked"), function() {
- subjects.push($(this).val());
- });
- //the ajax function
- $.ajax({
- url: 'assets/php/editUser.php',
- type: 'POST',
- data: {
- name:name,
- address:address,
- email:email,
- phone:phone,
- grades:grades,
- subjects:subjects
- },
- success: function(data) {
- console.log(data);
- swal("Breytingar mótteknar", "", "success");
- }
- });
- });
- });
- //
- //
- //Here userSettings.php ends
- //
- //
- //
- //
- //Here is code for project.php
- //
- //
- /*if the download link is pressed, send the appropriate date over to a PHP file*/
- $('#download').on('click', function() {
- //get the ID of the correct file
- var id = $('#download').val();
- document.location = "assets/php/download.php?id="+id;
- });
- //same delete function as before
- $('#deleteProject').on('click', function() {
- //Make the user confirm his selection
- swal({
- title: "Eru viss um að þú viljir gera þetta?",
- text: "Það er ekki hægt að endurheimta eydd verkefni",
- type: "warning",
- showCancelButton: true,
- confirmButtonColor: "#303c74",
- confirmButtonText: "Já, ég vill eyða verkefninu",
- closeOnConfirm: false
- //if the user confirms his selection, do this
- }, function() {
- //get the ID of the upload
- var id = $('#download').val();
- //send it over to the PHP document
- $.ajax({
- url: 'assets/php/deleteUpload.php',
- type: 'POST',
- data: {id:id},
- success: function(data) {
- //tell the user that his project was deleted successfully
- swal("Eytt!", "Verkefninu þínu hefur verið eytt", "success");
- setTimeout(function() {
- window.location.href = "index.php";
- }, 1500);
- }
- });
- });
- });
- //if the download element is not present, the projectID should not be undefined
- var projectID = 0;
- if ($('#download').length) {
- projectID = $('#download').val();
- }
- else{
- projectID = 1;
- }
- $('#commentButton').on('click',function(){
- var userinput = $('.commentInput')[0];
- userinputvalue = userinput.value;
- // add the comment to table
- if (userinputvalue != "") {
- $.ajax({
- url: 'assets/php/addComment.php',
- type: 'POST',
- data: {
- uploadID:projectID,
- content:userinputvalue
- },
- success: function(data) {
- // clear the input fields
- userinput.value = null;
- console.log(userinputvalue);
- // reload ajax
- loadComments();
- }
- });
- }else{
- swal('Villa',"vinsamlegast hafðu athugasemdina ekki tóma");
- }
- })
- // load ajax
- var deleteComment = function(e){
- var deleteid = e.target.id;
- swal({
- //all this stuff is for the sweetalert plugin
- title: "Viss ?",
- text: "Ertu viss um að þú viljir eyða commenti?",
- type: "warning",
- showCancelButton: true,
- confirmButtonColor: "#20E82E",
- confirmButtonText: "Já, Eyða",
- cancelButtonText: "Nei, Ekki Eyða",
- closeOnConfirm: false,
- closeOnCancel: false
- },
- //this is what happens if the user confirms the selection
- function(isConfirm){
- if (isConfirm) {
- $.ajax({
- url: 'assets/php/deleteComment.php',
- type: 'POST',
- data: {
- id: deleteid
- },
- success: function(data){
- console.log(data);
- loadComments();
- swal("commenti eytt","commenti þínu hefur verið eytt samkvæmt beiðni", "success");
- }
- });
- }
- else {
- swal("Hætt við", "commenti var ekki eytt", "error");
- }
- });
- }
- var loadComments = function(){
- $('.commentOutercontainer').remove();
- $.ajax({
- url: 'assets/php/fetchComment.php',
- type: 'POST',
- data: {
- projectID:projectID
- },
- success: function(data){
- var thing = JSON.parse(data);
- thing = thing;
- for (var i = 0; i < thing.length; i++) {
- var outerContainer = $('<div class="commentOutercontainer"></div>').appendTo($('#main'));
- var uppercontainer = $('<div class="upperCommentContent"></div>').appendTo(outerContainer);
- var time = $('<span class="commentTime">'+thing[i].time+'</span>').appendTo(uppercontainer);
- var container = $('<span><span>').appendTo(uppercontainer);
- if (thing[i].owner == '1') {
- // if the user that requsted the comments is the owner.
- // a comment delete button is added.
- var bin = $('<i class="fa fa-trash-o deleteComment" id="'+thing[i].ID+'"></i>').appendTo(container);
- }
- else{
- // if the user that requested the comments is not the owner
- };
- var user = $('<a href="user.php?id='+thing[i].userID+'"><span class="commentUser">'+thing[i].name+'</span></a>').appendTo(container);
- var content = $('<span class="commentContent">'+thing[i].content+'</span>').appendTo(outerContainer);
- };
- $('.deleteComment').on('click',function(e){
- deleteComment(e);
- })
- }
- });
- }
- loadComments();
- // functions for emailing teachers invites start
- var emailArray = new Array();
- /*this function contains all functionality associated with the front-side of
- tags. It generates a div based on the input from the user and adds a cancel
- button as well as an eventlistener that runs a function that removes the tag,
- both from the final array and from the user interface*/
- var emailToggled = function(){
- //grab the box that contains all the tags
- var box = $('#tagContainer');
- //grab the text from the input
- var tag = $('#keys').val();
- //some input validations
- //if the tag is empty, alert the user
- if (tag == "") {
- swal("Tölvupóstfangið má ekki vera tómt");
- //exit from the function
- return;
- };
- //if the tag is already in the array, alert the user
- if ($.inArray(tag, emailArray) > -1) {
- swal("Bara er hægt að nota hvert tölvupóstfang einu sinni");
- return;//kill the function
- };
- //add the tag to the emailArray
- emailArray.push(tag);
- //create the elements for the div and the delete button
- var deletr = document.createElement("div");
- var thing = document.createElement("span");
- //put the element in the main container
- box.append(thing);
- //put the tag inside the tagContainer
- thing.innerHTML = tag;
- //add the appropriate class to the tag
- thing.className = "chosenTag";
- //add the appropriate tags to the cancel button
- deletr.className = "fa fa-times deleteTag";
- //add an eventlistener to the x element
- deletr.addEventListener("click", deleteEmail);
- //put the delete element inside of the tag container
- thing.appendChild(deletr);
- //empty the textbox
- document.getElementById('keys').value = "";
- $('#keys').focus(); // put focus back on the textbox
- };
- //this runs the function if either enter or the "add" button is pressed
- $("#createtag").click(emailToggled); // if the add button is pressed
- $('#keys').keypress(function(e){ // if enter is presed whilest over the text box.
- if(e.which == 13){//run the function also if enter is pressed
- emailToggled();
- };
- });
- //function that removed the relevant tag if the X button is pressed
- function deleteEmail () {
- var soonGone = this.closest('.chosenTag');//selects the closes parent element with the .chosenTag class, in this case it will be the relevant tag
- var toBeRemoved = soonGone.textContent;//this selects the text from the same tag
- emailArray.splice($.inArray(toBeRemoved, emailArray), 1);//remove the tag from the array that will be sent via Ajax
- soonGone.remove();//remove the closest tag
- }
- $('#createKeys').on('click',function(data){
- $.ajax({
- url: "assets/php/genKeys.php",
- type: "POST",
- data:{
- count: emailArray
- },
- success: function(data){
- console.log(data);
- swal('Tölvupóstar hafa verið sendir.','Allir tölvupóstar hafa verið sendir','success');
- wipeFormEmails();
- }
- });
- })
- function wipeFormEmails () {
- //delete everything from the tagContainer
- $('#tagContainer').empty();
- //empty the array of tags
- emailArray = [];
- }
- //
- //
- //
- //Beware, starting to move front.php into this disgusting thing
- //
- //
- //
- var loadprojects = function(data){
- for (var i = 0; i < data.length; i++) {
- var tempjQuerySelector = null;
- var datadump = $('#datadump');
- var outercontainer = $('<div class="col-md-6 col-xs-12"></div>').appendTo(datadump);
- var uploadBox = $('<div class="col-md-12 uploadBox"></div>').appendTo(outercontainer);
- var flexContLeft = $('<div class="flexContLeft"></div>').appendTo(uploadBox);
- var flexContRight = $('<div class="flexContRight"></div>').appendTo(uploadBox);
- // flex contain right elements
- var usernamespan = $('<a class="frontUser" href="user.php?id=' + data[i].userID + '">'+data[i].username+'</a>').appendTo(flexContRight);
- var subjectnamespan = $('<a class="frontSubject" href="subject.php?subject=' + data[i].subjectname + '"><span>'+data[i].subjectname+'</span></a>').appendTo(flexContRight);
- var timespan = $('<span>'+data[i].time+'</span>').appendTo(flexContRight);
- var starred = checkVoteAndBookmark (data[i].ID);
- var arr = starred.split(' ');
- var numOfVotes = arr[1];
- if (arr[0] == "f") {
- var makeStar = $('<div><i class="fa fa-star-o fa-2x voter"> <span class="numOfVotes">' + numOfVotes + '</span><span class="hiddenID">' + data[i].ID + '</span></i></div>');
- makeStar.appendTo(flexContRight);
- };
- if (arr[0] == "t") {
- var makeStar = $('<div><i class="fa fa-star fa-2x voter"> <span class="numOfVotes">' + numOfVotes + '</span><span class="hiddenID">' + data[i].ID + '</span></i></div>');
- makeStar.appendTo(flexContRight);
- };
- if (arr[2] == "f") {
- var makeMark = $('<div class="bookClass"><i class="fa fa-bookmark-o fa-2x bookmark"><span class="hiddenID">' + data[i].ID + '</span></i></div>');
- makeMark.appendTo(uploadBox);
- };
- if (arr[2] == "t") {
- var makeMark = $('<div class="bookClass"><i class="fa fa-bookmark fa-2x bookmark"><span class="hiddenID">' + data[i].ID + '</span></i></div>');
- makeMark.appendTo(uploadBox);
- };
- // flex contain left elements
- var title = $('<a href="project.php?id='+data[i].ID+'"><h2 class="returnedResaultsHeaderTitle">'+data[i].name+'</h2></a>').appendTo(flexContLeft);
- var description = $('<span class="description">'+data[i].description+'</span>').appendTo(flexContLeft);
- if (i == data.length -1) {
- $('body').addClass('loaded');
- setTimeout(function() {
- $('body').removeAttr('style');
- }, 700);
- };
- if (data.length == 0 && numbofbulk == 1) {
- $('body').addClass('loaded');
- $('body').removeAttr('style');
- };
- };
- }
- function checkVoteAndBookmark(ID) {
- return $.ajax({
- type: "GET",
- url: "assets/php/checkVote.php?id="+ID,
- async: false
- }).responseText;
- }
- function vote(ID, toReturn) {
- $.ajax({
- url: 'assets/php/vote.php',
- type: 'POST',
- data: {id:ID},
- success: function(data) {
- toReturn(data);
- }
- });
- };
- function addBookmark(ID, toReturn) {
- $.ajax({
- url: 'assets/php/bookmark.php',
- type: 'POST',
- data: {id:ID},
- success: function(data) {
- toReturn(data);
- }
- });
- };
- //
- // end.
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
- ga('create', 'UA-59531056-2', 'auto');
- ga('send', 'pageview');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement