1 2 /** 3 * @class Monk.component.ChunkViewerCloneComponent 4 * @description A {@link Worbench.component.Component} for viewing text chunks. 5 * @extends Workbench.component.Component 6 * @author Stéfan Sinclair 7 * @version 0.1 8 * @since Monk 0.1 9 */ 10 Monk.component.ChunkViewerCloneComponent = function(args) { 11 12 // track the currently loaded chunk 13 this.currentChunk = null; 14 15 // has highlighting been applied (from a search) 16 this.highlighted = false; 17 18 Monk.component.ChunkViewerCloneComponent.superclass.constructor.call(this, args); 19 } 20 21 Workbench.extend(Monk.component.ChunkViewerCloneComponent, Workbench.component.Component, { 22 23 label : "Text Viewer", 24 description : "For Viewing A Text Chunk.", 25 "window" : this.window, 26 27 handle : function(monkEvent, data){ 28 if (monkEvent.instanceOf(Monk.event.chunk.ChunkSelected)) { 29 if (this.hasFocusPriority()) { 30 Workbench.component.manager.handleFocus(this); 31 this.currentChunk = data; 32 Monk.data.chunk.retrieveChunkContents(data); 33 Ext.get("componentContent").mask("loading text chunk..."); 34 } 35 } else if (monkEvent.instanceOf(Monk.event.chunk.ChunkContentsRetrieved)) { 36 if (this.hasFocusPriority()) { 37 document.getElementById("view").innerHTML = data.html; 38 this.window.scrollTo(0,0); 39 Ext.get("componentContent").unmask(); 40 } 41 } else if (monkEvent.instanceOf(Monk.event.chunk.ChunkContentsRetrievedWithFeatures)) { 42 //document.getElementById("info").innerHTML="<i>"+data.text+"</i>"; 43 document.getElementById("view").innerHTML = data.html; 44 45 // improve style of feature terms 46 var text = Ext.get('chunkText').dom; 47 var fontNodes = Ext.DomQuery.select('font[color!=#999999]', text); 48 for (var i = 0; i < fontNodes.length; i++) { 49 var node = fontNodes[i]; 50 var color = node.getAttribute('color'); 51 Ext.DomHelper.applyStyles(node, {'background-color':color}); 52 Ext.DomHelper.applyStyles(node, {padding:'1px 3px'}); 53 Ext.DomHelper.applyStyles(node, {color:'#ffffff'}); 54 } 55 56 this.window.scrollTo(0,0); 57 Ext.get("content").unmask(); 58 } else if (monkEvent.instanceOf(Monk.event.workbench.SimpleSearchQuery)) { 59 if (this.hasFocus) { 60 var query = data.featureValue.split(' (*)')[0]; 61 highlightSearchTerms(query, true, false); 62 this.highlighted = true; 63 // TODO: clear previous search highlights 64 } 65 } 66 }, 67 68 hasFocusPriority : function() { 69 var focusHistory = Workbench.component.manager.focusHistory; 70 var focusHistoryIds = []; 71 var hasFocusPriority = false; 72 73 var thisId = null; 74 75 // get the ids for the components in focus history 76 for (var i = 0; i < focusHistory.length; i++) { 77 var historyItem = focusHistory[i]; 78 this.getFeature().toolWindowRegistry.find(function(item, key) { 79 if (item.window == historyItem.window) { 80 var id = key.split('-window')[0]; 81 focusHistoryIds.push(id); 82 if (historyItem.window == this.window) { 83 thisId = id; 84 } 85 return true; 86 } else { 87 return false; 88 } 89 }, this); 90 } 91 92 if (thisId == null) { 93 // if the id is still null, the this component isn't in the focus history 94 return false; 95 } else { 96 // figure out the id for the duplicate component 97 var duplicateId = thisId.indexOf('-clone') > -1 ? thisId.split('-clone')[0] : thisId + '-clone'; 98 99 // check which id is closer to the beginning of the array 100 if (focusHistoryIds.indexOf(duplicateId) > -1) { 101 if (focusHistoryIds.indexOf(duplicateId) < focusHistoryIds.indexOf(thisId)) { 102 hasFocusPriority = false; 103 } 104 } else { 105 hasFocusPriority = true; 106 } 107 return hasFocusPriority; 108 } 109 } 110 }); 111