resources/src/js/zotero.js
// node: the node currently selected in the left nav
the node currently selected in the left nav
the node currently selected in the left nav
function createMain(node) {
	console.log('create main: ' + node);
	var cont = document.getElementById("zotero-main-content");
	while (cont.firstChild) {
	    cont.removeChild(cont.firstChild);
	}
	if (node) {
	    var meta = node.metadata;
	    var sel = node.state.selected;
	    var nodeType;
	    var hasContent;
	    console.log('node: ' + node.text);
	    if (node.item_type == 'attachment') {
		nodeType = 'attachment';
	    } else if (node.item_type == 'note') {
		nodeType = 'note';
	    } else if (meta != null) {
		nodeType = 'meta';
	    }
	    hasNote = ((nodeType == 'note') && sel);
	    hasContent = (((nodeType == 'attachment') && sel) ||
			  (nodeType == 'meta'));
	    cont.className = '';
	} else {
	    hasContent = false;
	    hasNote = false;
	    nodeType = null;
	}
	if (hasContent) {
	    headerPane(node, cont);
	} else if (!hasNote) {
	    var noc = document.createElement('div');
	    cont.classList.add('center-cell');
	    noc.classList.add('disabled-text');
	    noc.appendChild(document.createTextNode('No Content'));
	    cont.appendChild(noc);
	}
	if (meta &&
	    (((nodeType == 'attachment') && sel) || !(nodeType == 'attachment'))) {
	    var metaTable = createMetaTable(meta);
	    cont.appendChild(metaTable);
	}
	if (hasNote) {
	    console.log('adding note: ' + node.resource);
	    var card = document.createElement('div');
	    var cardBlock = document.createElement('div');
	    var h = document.createElement('h3');
	    card.classList.add('card');
	    card.classList.add('center-pane');
	    card.classList.add('note-pane');
	    h.classList.add('card-header');
	    h.appendChild(document.createTextNode(node.item_title));
	    card.appendChild(h);
	    cardBlock.classList.add('card-block');
	    var p = document.createElement('p');
	    p.classList.add('card-text');
	    var divElem = document.createElement('div');
	    var text = node.item_note;
	    divElem.innerHTML = text;
	    p.appendChild(divElem);
	    cardBlock.appendChild(p);
	    card.appendChild(cardBlock);
	    cont.classList.add('content-note');
	    cont.appendChild(card);
	}
	if ((nodeType == 'attachment') && sel) {
	    console.log('adding resource: ' + node.resource);
	    var aelem = document.createElement('div');
	    if (node.resource.endsWith('.html')) {
		$.ajax({
		    url: node.resource,
		    type: 'GET',
		    dataType: 'html',
		    success: function(data) {              
			aelem.innerHTML = data;
		    }});
	    } else {
		var objElem = document.createElement('object');
		aelem.classList.add('embed-responsive');
		aelem.classList.add('border');
		aelem.classList.add('rounded');
		aelem.classList.add('pdf-pane');
		objElem.setAttribute('data', node.resource);
		objElem.setAttribute('type', 'application/pdf');
		objElem.appendChild(document.createTextNode('No PDF plugin'));
		aelem.appendChild(objElem);
	    }
	    cont.appendChild(aelem);
	}
	updateLink(node);
    }
function createMain ( node ) { console . log ( 'create main: ' + node ) ; var cont = document . getElementById ( "zotero-main-content" ) ; while ( cont . firstChild ) { cont . removeChild ( cont . firstChild ) ; } if ( node ) { var meta = node . metadata ; var sel = node . state . selected ; var nodeType ; var hasContent ; console . log ( 'node: ' + node . text ) ; if ( node . item_type == 'attachment' ) { nodeType = 'attachment' ; } else if ( node . item_type == 'note' ) { nodeType = 'note' ; } else if ( meta != null ) { nodeType = 'meta' ; } hasNote = ( ( nodeType == 'note' ) && sel ) ; hasContent = ( ( ( nodeType == 'attachment' ) && sel ) || ( nodeType == 'meta' ) ) ; cont . className = '' ; } else { hasContent = false ; hasNote = false ; nodeType = null ; } if ( hasContent ) { headerPane ( node , cont ) ; } else if ( ! hasNote ) { var noc = document . createElement ( 'div' ) ; cont . classList . add ( 'center-cell' ) ; noc . classList . add ( 'disabled-text' ) ; noc . appendChild ( document . createTextNode ( 'No Content' ) ) ; cont . appendChild ( noc ) ; } if ( meta && ( ( ( nodeType == 'attachment' ) && sel ) || ! ( nodeType == 'attachment' ) ) ) { var metaTable = createMetaTable ( meta ) ; cont . appendChild ( metaTable ) ; } if ( hasNote ) { console . log ( 'adding note: ' + node . resource ) ; var card = document . createElement ( 'div' ) ; var cardBlock = document . createElement ( 'div' ) ; var h = document . createElement ( 'h3' ) ; card . classList . add ( 'card' ) ; card . classList . add ( 'center-pane' ) ; card . classList . add ( 'note-pane' ) ; h . classList . add ( 'card-header' ) ; h . appendChild ( document . createTextNode ( node . item_title ) ) ; card . appendChild ( h ) ; cardBlock . classList . add ( 'card-block' ) ; var p = document . createElement ( 'p' ) ; p . classList . add ( 'card-text' ) ; var divElem = document . createElement ( 'div' ) ; var text = node . item_note ; divElem . innerHTML = text ; p . appendChild ( divElem ) ; cardBlock . appendChild ( p ) ; card . appendChild ( cardBlock ) ; cont . classList . add ( 'content-note' ) ; cont . appendChild ( card ) ; } if ( ( nodeType == 'attachment' ) && sel ) { console . log ( 'adding resource: ' + node . resource ) ; var aelem = document . createElement ( 'div' ) ; if ( node . resource . endsWith ( '.html' ) ) { $ . ajax ( { url : node . resource , type : 'GET' , dataType : 'html' , success : function ( data ) { aelem . innerHTML = data ; } } ) ; } else { var objElem = document . createElement ( 'object' ) ; aelem . classList . add ( 'embed-responsive' ) ; aelem . classList . add ( 'border' ) ; aelem . classList . add ( 'rounded' ) ; aelem . classList . add ( 'pdf-pane' ) ; objElem . setAttribute ( 'data' , node . resource ) ; objElem . setAttribute ( 'type' , 'application/pdf' ) ; objElem . appendChild ( document . createTextNode ( 'No PDF plugin' ) ) ; aelem . appendChild ( objElem ) ; } cont . appendChild ( aelem ) ; } updateLink ( node ) ; }
node: the node currently selected in the left nav
node : the node currently selected in the left nav
// determine the type of node in the tree we're visiting //if (node.resource != null) { // add the header pane // add metadata if there is any // add notes if there are any // add the (usually PDF orsnapshot site) attachemnt // var html = $('#stage').load(node.resource); // console.log(html)