User:Cubgs53/common.js

/* * TODO: * 1. What actions should be recorded? Record those actions. * 2. What contextual information do we want to offer *   suggestions? What sentences/surrounding text, etc.? * 3. Un-highlight text after insertion * 4. Discuss UI. */

/* inserts the list of citation recommendations */ var buildCitations = function($elmt, dialog, sentence, refs) { var $refsList = null , refsString = fetchCitations(sentence, refs, "") ;   $elmt.html(refsString); $refsList = $elmt.find('li');

//Used when a reommended ref is clicked. Add it to the reference creation box var selectRef = function { console.log('selecting ref'); //Add reference to the text box refSurface = dialog.referenceSurface.getSurface.getModel;

//get length of current text box data in order to replace all of it       range = new ve.Range(0, refSurface.getDocument.getData.length);

//Put in new ref refSurface.getFragment(range).insertContent($(this).html);

//Highlight selected reference, un-highlight the others $elmt.find("li").removeClass('csi-selected'); $(this).addClass('csi-selected');

//Record click

},

//Used on recommended ref double click. Automatically inserts reference into article insertRef = function { dialog.close( 'insert' );

//Record double click },

//Record time at which user began hovering recordEntry = function { $(this).data('entryTime', $.now); },

//Write the time hovered to server recordExit = function { console.log($.now-$(this).data('entryTime')); };

$refsList.hover(recordEntry, recordExit); $refsList.click(selectRef); $refsList.dblclick(insertRef); }

/* Fetches reccommendations from engine */ , fetchCitations = function(sentence, refs, article) {

var suggestionMap = { 'Purdah_(pre-election_period)' : [ '1', '2', '3', '4','5','6','7','8' ], '' : ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'], }    , refsString = '' , path = window.location.pathname , index = path.lastIndexOf("/") , title = path.substring(index+1) , suggestions = suggestionMap[title] || suggestionMap[''] , details ;

console.log(title); for (var i = 0; i < suggestions.length; i++) { details = 'yolo pick meee ' refsString = refsString + '' + details + '' + suggestions[i] + ''; };

return refsString; }

, onready = function { csiReferenceDialog = function CSIReferenceDialog( surface, config ) { // Parent constructor ve.ui.MWReferenceDialog.call( this, surface, config ); };

/* Inheritance */

ve.inheritClass( csiReferenceDialog, ve.ui.MWReferenceDialog );

/* Methods */

/**    * @inheritdoc */   csiReferenceDialog.prototype.initialize = function  { // Parent method ve.ui.MWReferenceDialog.prototype.initialize.call( this );

// Construct CSI interface var $csi = $(' Citation Suggestions  ') , $list = $('Loading...') ;       $csi.append($list); this.$body.append( $csi );

};

csiReferenceDialog.prototype.onOpen = function { var references = [] , sentence = '' , surfaceModel = this.surface.getModel , selection = surfaceModel.getSelection.clone , data , $list = $ref = $('.ve-ui-frame').contents.find('.csi-list'); ;

// Fetch reference recommendations // TODO: how do we want to select the contextual info we want to send? //selection may be a section of text that was highlighted or just the cursor location selection.from = 0; selection.start = 0; data = surfaceModel.getFragment( selection ).getText; sentence = data;

buildCitations($list, this, sentence, references);

// Parent method ve.ui.MWReferenceDialog.prototype.onOpen.call( this ); };

csiReferenceDialog.prototype.onClose = function( action ) {

// Parent method ve.ui.MWReferenceDialog.prototype.onClose.call( this, action ); };

/* Registration */

ve.ui.dialogFactory.register( csiReferenceDialog ); };

$(window).load(function {   console.log('loaded');    setTimeout( function { if($('.ve-ui-surface').length > 0) {               console.log('loading CSI JS'); onready; }       }   , 2000); });