// details = '(' + formattedAuthor + ', ' + formattedYear + ')';
// else if (formattedYear != '')
// details = '(' + formattedYear + ')';
// else if (formattedAuthor != '')
// details = '(' + formattedAuthor + ')';
// $('td.details', newchild).html(details);  
// generate a URL based on ref type
var icon = ref.getIcon, url = '', refType = ref.type;  
switch(refType)
{
case 'web':
url = ref.params['url'];
break;
case 'book':
if(ref.params['isbn'] != null)
url = mw.config.get('wgServer') + '/w/index.php?title=Special%3ABookSources&isbn=' + ref.params['isbn'];
break;
case 'journal':
case 'conference':
if(ref.params['doi'] != null)
url = 'http://dx.doi.org/' + ref.params['doi'];
break;
case 'news':
url = ref.params['url'];
break;
case 'episode':
url = 'http://www.imdb.com/find?s=ep&q=' + escape(ref.params['title']);
break;
}
$('td.type', newchild).css('background-image','url('+icon+')');  
var authorByline = *, yearByline = *, refTypeByline = '';
if(formattedAuthor != '')
authorByline = 'By: <span>' + formattedAuthor + '</span>';
if(formattedYear != '')
yearByline = 'Date: <span>' + formattedYear + '</span>';
if(refType != null)
{
var displayType = ref.getTypeForDisplay, formattedRefType = displayType;
$('td.type', newchild).attr('title', displayType);  
if(url != '')
formattedRefType = '<a href="' + url + '" target="_blank">' + formattedRefType + '</a>';
refTypeByline = 'Type: <span>' + formattedRefType + '</span>';
}  
//alert("authorByline: " + authorByline + "\n yearByline: " + yearByline + "\n refTypeByline: " + refTypeByline);
var byline = '', separator = ' | ';
if(refType == 'raw')
{
byline = refTypeByline + separator + mw.html.escape(ref.toString);
}
else if(authorByline != '') // a??
{
if(yearByline != '') // ad?
{
if(refTypeByline != '') // adt
byline = authorByline + separator + yearByline + separator + refTypeByline;
else // ad-
byline = authorByline + separator + yearByline;
}
else // a-?
{
if(refTypeByline != '') // a-t
byline = authorByline + separator + refTypeByline;
else // a--
byline = authorByline;
}
}
else // -??
{
if(yearByline != '') // -d?
{
if(refTypeByline != '') // -dt
byline = yearByline + separator + refTypeByline;
else // -d-
byline = yearByline;
}
else // --?
{
if(refTypeByline != '') // --t
byline = refTypeByline;
// no need for ---
}
}
byline = '<p>' + byline + '</p>';
//alert(byline);  
// create expanded <div>
var expanded = $('<div />',{
"class": 'expanded'
});  
// append the infobar to the expanded info box
$(expanded).append(byline);  
// append the expanded info box to the title <td>
$('td.title', newchild).append(expanded);  
if(!isReplacement)
{
// get ref number by counting number of refs (this includes dummy ref, but not the one we're creating)
var numRefs = $('#refs tr').length;
$('td.number', newchild).text(numRefs);
$('#numRefs').text(numRefs); // update the number of refs in the view tab
}
// event handler for selecting a ref)
$(newchild).click(function {
thisproveit.highlightTargetString(ref.orig);
//thisproveit.highlightTargetString(ref.orig);
$("#refs tr").removeClass('selected');
$(newchild).addClass('selected');
});  
var doEdit = function {
thisproveit.updateEditPane(ref);  
$("#view-pane").hide;
$("#edit-pane").show;
};  
var citationStrings = ref.getCitationStrings;  
//var pointers = $('.pointers', newchild);  
var allCitations = $('<span />');  
for(var i = 0; i < citationStrings.length; i++)
{
var dividend = i + 1;
var colName = "";  
while(dividend > 0)
{
var mod = --dividend % 26;
colName = String.fromCharCode(97 + mod) + colName; // a = 97
dividend = Math.floor(dividend / 26);
}
var citationHolder = $('<a href="#">' + colName + '</a>');
// Bind i
var clickFunc = (function(i)
{
return function
{
var last = 0, j = 0;
var text = proveit.getMWEditValue;
for(j = 0; j < i; j++)
{
last = text.indexOf(citationStrings[j], last);  
// Shouldn't happen. Indicates citation strings are out of date.
if(last == -1)
{
proveit.log("citationStrings[" + j + "]: " + citationStrings[j] + " not found. Returning.");
return false;
}
last += citationStrings[j].length;
}
var startInd = text.indexOf(citationStrings[i], last);
if(startInd == -1)
{
proveit.log("citationStrings[" + i + "]: " + citationStrings[i] + " not found.");
}
else
{
proveit.highlightLengthAtIndex(startInd, citationStrings[i].length);
}
return false;
};
})(i);  
citationHolder.click(clickFunc);
allCitations.append(citationHolder);
}  
if(citationStrings.length > 1)
{
var newP = $('<p />');
newP.append('This reference is cited in the article <span>' + citationStrings.length + ' times</span>: ').append(allCitations);
expanded.append(newP);
}  
// edit buttons
if(ref.type != 'raw')
{
// SMALL EDIT BUTTON  
// create button
var smallEditBtn = $('<button />',{
text: 'edit'
});  
// transform button
$(smallEditBtn).button({
icons: {
primary: 'ui-icon-pencil'
},
text: false
});  
// button click event handler
smallEditBtn.click(doEdit);  
// append button
$('.edit', newchild).append(smallEditBtn);  
// LARGE EDIT BUTTON  
// create button
var editBtn = $('<button />',{
"class": 'edit',
text: 'edit this reference'
});  
// transform button
$(editBtn).button({
icons: {
primary: 'ui-icon-pencil'
},
text: true
});  
// button click event handler
editBtn.click(doEdit);  
// append button
expanded.append(editBtn);  
// ROW EVENT HANDLER
$(newchild).dblclick(doEdit);
}
else
{
// needed to keep all rows the same height
$('.edit', newchild).append('&nbsp;');
}  
// ibid button
if(citationStrings.length > 0)
{
// create button
var ibidBtn = $('<button />',{
"class": 'insert',
text: 'insert this reference at cursor'
});  
// transform button
$(ibidBtn).button({
icons: {
primary: 'ui-icon-arrowthick-1-e'
},
text: true
});  
// button click event handler
ibidBtn.click(function{
thisproveit.insertRefIntoMWEditBox(ref, false);
return false;
});  
// append button
expanded.append(ibidBtn);
}  
return newchild;
},  
/**
- Truncates title to fit ProveIt refbox row.
- @param {String} title title to truncate
- @return {String} truncated title
- /
truncateTitle: function(title)
{
var MAX_LENGTH = 86;
var truncated = title;
if(title.length > MAX_LENGTH)
{
truncated = truncated.substring(0, MAX_LENGTH);
var lastSpacePos = truncated.lastIndexOf(' ');
if(lastSpacePos != -1)
{
truncated = truncated.substr(0, lastSpacePos);
truncated += " ...";
}
}
return truncated;
},  
/**
- Only to be used internally to add the citations to the list
-
- @param {AbstractReference} ref the reference to add
- /
addNewElement: function(ref)
{
var refbox = this.getRefBox;
$(refbox).append(this.makeRefBoxRow(ref, false));
}
}, window.proveit);  
/**
- Static method. Returns valid Cite reference types
- @for CiteReference
- @static
- @return {Array} array of cite method types
- /
proveit.CiteReference.getTypes = function
{
return ["web", "book", "journal", "conference", "encyclopedia", "news", "newsgroup", "press release", "interview", "episode", "AV media"];
};  
proveit.split._compliantExecNpcg = /??/.exec("")[1] === undefined; // NPCG: nonparticipating capturing group
proveit.split._nativeSplit = String.prototype.split;  
proveit.setup;  
}( mediaWiki, jQuery ) );  
// Local Variables:
// js2-basic-offset: 8
// End: