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