/** * This method extracts all strings within curly brackets * in the passed json string. This method is used in conjunction * with getExistingImageNotes(matches) below to load in and * display any existing image annotations. **/ function getImageNoteMatches(imageJson){ var matches = []; var regex = /{([^}]+)}/g; var currMatch; while(currMatch = regex.exec(imageJson)){ matches.push(currMatch[1]); } return matches; } /** * This method extracts all notes from an array of * strings and creates an associative array with the * information from these notes. This is for loading * and displaying any existing image annotations. **/ function getExistingImageNotes(matches,pageNum){ var existing_notes = new Array(); //split each string stored in matches at the comma. for(var i = 0; i < matches.length; i++){ var a = {}; var split = matches[i].split(','); for(var j =0; j < split.length; j++){ //split each string by the colon mark. var splitAgain = split[j].split(':'); var val; //check word in first string of splitAgain if(splitAgain[0].indexOf("top") != -1){ val = splitAgain[1].substring(1); a['top'] = val; }else if(splitAgain[0].indexOf("left") != -1){ val = splitAgain[1].substring(1); a['left'] = val; }else if(splitAgain[0].indexOf("width") != -1){ val = splitAgain[1].substring(1); a['width'] = val; }else if(splitAgain[0].indexOf("height") != -1){ val = splitAgain[1].substring(1); a['height'] = val; }else if(splitAgain[0].indexOf("text") != -1){ val = splitAgain[1].substring(2,splitAgain[1].length-1); a['text'] = val; }else if(splitAgain[0].indexOf("id") != -1){ val = splitAgain[1].substring(1); a['id'] = val; }else if(splitAgain[0].indexOf("editable") != -1){ val = splitAgain[1].substring(1,splitAgain[1].length-1); a['editable'] = val; }else if(splitAgain[0].indexOf("page") != -1){ val = splitAgain[1].substring(1,splitAgain[1].length-1); a['page'] = val; } if(a['page'] === null || a['page'] == undefined){ if(pageNum !== undefined && pageNum !== null) a['page'] = pageNum; } } //only obtain the notes associated with the given page number. if(a['page'] == pageNum) existing_notes.push(a); } return existing_notes; } function addSocialLinks(){ }