[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* eslint-disable no-unused-vars */ 2 /* global SELECTOR */ 3 var COMMENTSEARCHNAME = "commentsearch", 4 COMMENTSEARCH; 5 6 /** 7 * Provides an in browser PDF editor. 8 * 9 * @module moodle-assignfeedback_editpdf-editor 10 */ 11 12 /** 13 * This is a searchable dialogue of comments. 14 * 15 * @namespace M.assignfeedback_editpdf 16 * @class commentsearch 17 * @constructor 18 * @extends M.core.dialogue 19 */ 20 COMMENTSEARCH = function(config) { 21 config.draggable = false; 22 config.centered = true; 23 config.width = '400px'; 24 config.visible = false; 25 config.headerContent = M.util.get_string('searchcomments', 'assignfeedback_editpdf'); 26 config.footerContent = ''; 27 COMMENTSEARCH.superclass.constructor.apply(this, [config]); 28 }; 29 30 Y.extend(COMMENTSEARCH, M.core.dialogue, { 31 /** 32 * Initialise the menu. 33 * 34 * @method initializer 35 * @return void 36 */ 37 initializer: function(config) { 38 var editor, 39 container, 40 placeholder, 41 commentfilter, 42 commentlist, 43 bb; 44 45 bb = this.get('boundingBox'); 46 bb.addClass('assignfeedback_editpdf_commentsearch'); 47 48 editor = this.get('editor'); 49 container = Y.Node.create('<div/>'); 50 51 placeholder = M.util.get_string('filter', 'assignfeedback_editpdf'); 52 commentfilter = Y.Node.create('<input type="text" size="20" placeholder="' + placeholder + '"/>'); 53 container.append(commentfilter); 54 commentlist = Y.Node.create('<ul role="menu" class="assignfeedback_editpdf_menu"/>'); 55 container.append(commentlist); 56 57 commentfilter.on('keyup', this.filter_search_comments, this); 58 commentlist.delegate('click', this.focus_on_comment, 'a', this); 59 commentlist.delegate('key', this.focus_on_comment, 'enter,space', 'a', this); 60 61 // Set the body content. 62 this.set('bodyContent', container); 63 64 COMMENTSEARCH.superclass.initializer.call(this, config); 65 }, 66 67 /** 68 * Event handler to filter the list of comments. 69 * 70 * @protected 71 * @method filter_search_comments 72 */ 73 filter_search_comments: function() { 74 var filternode, 75 commentslist, 76 filtertext, 77 dialogueid; 78 79 dialogueid = this.get('id'); 80 filternode = Y.one('#' + dialogueid + SELECTOR.SEARCHFILTER); 81 commentslist = Y.one('#' + dialogueid + SELECTOR.SEARCHCOMMENTSLIST); 82 83 filtertext = filternode.get('value'); 84 85 commentslist.all('li').each(function(node) { 86 if (node.get('text').indexOf(filtertext) !== -1) { 87 node.show(); 88 } else { 89 node.hide(); 90 } 91 }); 92 }, 93 94 /** 95 * Event handler to focus on a selected comment. 96 * 97 * @param Event e 98 * @protected 99 * @method focus_on_comment 100 */ 101 focus_on_comment: function(e) { 102 e.preventDefault(); 103 var target = e.target.ancestor('li'), 104 comment = target.getData('comment'), 105 editor = this.get('editor'); 106 107 this.hide(); 108 109 if (comment.pageno === editor.currentpage) { 110 comment.drawable.nodes[0].one('textarea').focus(); 111 } else { 112 // Comment is on a different page. 113 editor.currentpage = comment.pageno; 114 editor.change_page(); 115 comment.drawable.nodes[0].one('textarea').focus(); 116 } 117 }, 118 119 /** 120 * Show the menu. 121 * 122 * @method show 123 * @return void 124 */ 125 show: function() { 126 var commentlist = this.get('boundingBox').one('ul'), 127 editor = this.get('editor'); 128 129 commentlist.all('li').remove(true); 130 131 // Rebuild the latest list of comments. 132 Y.each(editor.pages, function(page) { 133 Y.each(page.comments, function(comment) { 134 var commentnode = Y.Node.create('<li><a href="#" tabindex="-1"><pre>' + comment.rawtext + '</pre></a></li>'); 135 commentlist.append(commentnode); 136 commentnode.setData('comment', comment); 137 }, this); 138 }, this); 139 140 this.centerDialogue(); 141 COMMENTSEARCH.superclass.show.call(this); 142 } 143 }, { 144 NAME: COMMENTSEARCHNAME, 145 ATTRS: { 146 /** 147 * The editor this search window is attached to. 148 * 149 * @attribute editor 150 * @type M.assignfeedback_editpdf.editor 151 * @default null 152 */ 153 editor: { 154 value: null 155 } 156 157 } 158 }); 159 160 Y.Base.modifyAttrs(COMMENTSEARCH, { 161 /** 162 * Whether the widget should be modal or not. 163 * 164 * Moodle override: We override this for commentsearch to force it always true. 165 * 166 * @attribute Modal 167 * @type Boolean 168 * @default true 169 */ 170 modal: { 171 getter: function() { 172 return true; 173 } 174 } 175 }); 176 177 M.assignfeedback_editpdf = M.assignfeedback_editpdf || {}; 178 M.assignfeedback_editpdf.commentsearch = COMMENTSEARCH;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |