Skip to content

Commit e953bb9

Browse files
Code clean up #831899
1 parent 89439dd commit e953bb9

File tree

2 files changed

+1
-285
lines changed

2 files changed

+1
-285
lines changed

amd/build/question.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/question.js

Lines changed: 0 additions & 284 deletions
Original file line numberDiff line numberDiff line change
@@ -172,202 +172,6 @@ define([
172172
}
173173
};
174174

175-
// TODO: The below methods can be refractored for window resizing.
176-
//
177-
// /**
178-
// * Adds a dropzone line with colour, coords and link provided to the array of Lines.
179-
// *
180-
// * @param {jQuery} svg the SVG image to which to add this drop zone.
181-
// * @param {int} dropZoneNo which drop-zone to add.
182-
// * @param {string} colourClass class name
183-
// */
184-
// DrawlinesQuestion.prototype.addDropzone = function(svg, dropZoneNo, colourClass) {
185-
// var dropZone = this.visibleDropZones[dropZoneNo],
186-
// line = Line.make(dropZone.line, ''),
187-
// existingmarkertext,
188-
// bgRatio = this.bgRatio();
189-
// if (!line.parse(dropZone.coords, bgRatio)) {
190-
// return;
191-
// }
192-
//
193-
// existingmarkertext = this.getRoot().find('div.markertexts span.markerlabelstart' + dropZoneNo);
194-
// if (existingmarkertext.length) {
195-
// if (dropZone.markertext !== '') {
196-
// existingmarkertext.html(dropZone.markertext);
197-
// } else {
198-
// existingmarkertext.remove();
199-
// }
200-
// } else if (dropZone.markertext !== '') {
201-
// var classnames = 'markertext markertext' + dropZoneNo;
202-
// this.getRoot().find('div.markertexts').append('<span class="' + classnames + '">' +
203-
// dropZone.markertext + '</span>');
204-
// var markerspan = this.getRoot().find('div.ddarea div.markertexts span.markertext' + dropZoneNo);
205-
// if (markerspan.length) {
206-
// var handles = line.getHandlePositions();
207-
// var positionLeft = handles.moveHandles.x - (markerspan.outerWidth() / 2) - 4;
208-
// var positionTop = handles.moveHandles.y - (markerspan.outerHeight() / 2);
209-
// markerspan
210-
// .css('left', positionLeft)
211-
// .css('top', positionTop);
212-
// markerspan
213-
// .data('originX', markerspan.position().left / bgRatio)
214-
// .data('originY', markerspan.position().top / bgRatio);
215-
// this.handleElementScale(markerspan, 'center');
216-
// }
217-
// }
218-
//
219-
// var lineSVG = line.makeSvg(svg[0]);
220-
// lineSVG.setAttribute('class', 'dropzone ' + colourClass);
221-
//
222-
// this.lines[this.Line.length] = line;
223-
// this.lineSVGs[this.lineSVGs.length] = lineSVG;
224-
// };
225-
226-
// /**
227-
// * Draws the drag items on the page (and drop zones if required).
228-
// * The idea is to re-draw all the drags and drops whenever there is a change
229-
// * like a widow resize or an item dropped in place.
230-
// */
231-
// DrawlinesQuestion.prototype.repositionDrags = function() {
232-
// var root = this.getRoot(),
233-
// thisQ = this;
234-
//
235-
// root.find('div.draghomes .marker').not('.dragplaceholder').each(function(key, item) {
236-
// $(item).addClass('unneeded');
237-
// });
238-
//
239-
// root.find('input.choices').each(function(key, input) {
240-
// var choiceNo = thisQ.getChoiceNoFromElement(input),
241-
// imageCoords = thisQ.getImageCoords(input);
242-
//
243-
// if (imageCoords.length) {
244-
// var drag = thisQ.getRoot().find('.draghomes' + ' span.marker' + '.choice' + choiceNo).not('.dragplaceholder');
245-
// drag.remove();
246-
// for (var i = 0; i < imageCoords.length; i++) {
247-
// var dragInDrop = drag.clone();
248-
// // Convert image coords to screen coords.
249-
// const screenCoords = thisQ.convertToWindowXY(imageCoords[i]);
250-
// dragInDrop.data('pagex', screenCoords.x).data('pagey', screenCoords.y);
251-
// // Save image coords to the drag item so we can use it later.
252-
// dragInDrop.data('imageCoords', imageCoords[i]);
253-
// // We always save the coordinates in the 1:1 ratio.
254-
// // So we need to set the scale ratio to 1 for the initial load.
255-
// dragInDrop.data('scaleRatio', 1);
256-
// thisQ.sendDragToDrop(dragInDrop, false, true);
257-
// }
258-
// thisQ.getDragClone(drag).addClass('active');
259-
// thisQ.cloneDragIfNeeded(drag);
260-
// }
261-
// });
262-
//
263-
// // Save the question answer.
264-
// thisQ.questionAnswer = thisQ.getQuestionAnsweredValues();
265-
// };
266-
//
267-
// /**
268-
// * Determine what drag items need to be shown and
269-
// * return coords of all drag items except any that are currently being dragged
270-
// * based on contents of hidden inputs and whether drags are 'infinite' or how many
271-
// * drags should be shown.
272-
// *
273-
// * @param {jQuery} inputNode
274-
// * @returns {Point[]} image coordinates of however many copies of the drag item should be shown.
275-
// */
276-
// DrawlinesQuestion.prototype.getImageCoords = function(inputNode) {
277-
// var imageCoords = [],
278-
// val = $(inputNode).val();
279-
// if (val !== '') {
280-
// var coordsStrings = val.split(' ');
281-
// for (var i = 0; i < coordsStrings.length; i++) {
282-
// imageCoords[i] = Line.Point.parse(coordsStrings[i]);
283-
// }
284-
// }
285-
// return imageCoords;
286-
// };
287-
//
288-
// /**
289-
// * Converts the relative x and y position coordinates into
290-
// * absolute x and y position coordinates.
291-
// *
292-
// * @param {Point} point relative to the background image.
293-
// * @returns {Point} point relative to the page.
294-
// */
295-
// DrawlinesQuestion.prototype.convertToWindowXY = function(point) {
296-
// var bgImage = this.bgImage();
297-
// // The +1 seems rather odd, but seems to give the best results in
298-
// // the three main browsers at a range of zoom levels.
299-
// // (Its due to the 1px border around the image, that shifts the
300-
// // image pixels by 1 down and to the left.)
301-
// return point.offset(bgImage.offset().left + 1, bgImage.offset().top + 1);
302-
// };
303-
304-
// /**
305-
// * Utility function converting window coordinates to relative to the
306-
// * background image coordinates.
307-
// *
308-
// * @param {Point} point relative to the page.
309-
// * @returns {Point} point relative to the background image.
310-
// */
311-
// DrawlinesQuestion.prototype.convertToBgImgXY = function(point) {
312-
// var bgImage = this.bgImage();
313-
// return point.offset(-bgImage.offset().left - 1, -bgImage.offset().top - 1);
314-
// };
315-
//
316-
// /**
317-
// * Functionality at the end of a drag drop.
318-
// * @param {jQuery} dragged the marker that was dragged.
319-
// */
320-
// DrawlinesQuestion.prototype.dragEnd = function(dragged) {
321-
// var placed = false,
322-
// choiceNo = this.getChoiceNoFromElement(dragged),
323-
// bgRatio = this.bgRatio(),
324-
// dragXY;
325-
//
326-
// dragged.data('pagex', dragged.offset().left).data('pagey', dragged.offset().top);
327-
// dragXY = new Line.Point(dragged.data('pagex'), dragged.data('pagey'));
328-
// if (this.coordsInBgImg(dragXY)) {
329-
// this.sendDragToDrop(dragged, true);
330-
// placed = true;
331-
// // Since we already move the drag item to new position.
332-
// // Remove the image coords if this drag item have it.
333-
// // We will get the new image coords for this drag item in saveCoordsForChoice.
334-
// if (dragged.data('imageCoords')) {
335-
// dragged.data('imageCoords', null);
336-
// }
337-
// // It seems that the dragdrop sometimes leaves the drag
338-
// // one pixel out of position. Put it in exactly the right place.
339-
// var bgImgXY = this.convertToBgImgXY(dragXY);
340-
// bgImgXY = new Line.Point(bgImgXY.x / bgRatio, bgImgXY.y / bgRatio);
341-
// dragged.data('originX', bgImgXY.x).data('originY', bgImgXY.y);
342-
// }
343-
//
344-
// if (!placed) {
345-
// this.sendDragHome(dragged);
346-
// this.removeDragIfNeeded(dragged);
347-
// } else {
348-
// this.cloneDragIfNeeded(dragged);
349-
// }
350-
//
351-
// this.saveCoordsForChoice(choiceNo);
352-
// };
353-
//
354-
// /**
355-
// * Makes sure the dragged item always exists within the background image area.
356-
// *
357-
// * @param {Point} windowxy
358-
// * @returns {Point} coordinates
359-
// */
360-
// DrawlinesQuestion.prototype.constrainToBgImg = function(windowxy) {
361-
// var bgImg = this.bgImage(),
362-
// bgImgXY = this.convertToBgImgXY(windowxy);
363-
// bgImgXY.x = Math.max(0, bgImgXY.x);
364-
// bgImgXY.y = Math.max(0, bgImgXY.y);
365-
// bgImgXY.x = Math.min(bgImg.width(), bgImgXY.x);
366-
// bgImgXY.y = Math.min(bgImg.height(), bgImgXY.y);
367-
// return this.convertToWindowXY(bgImgXY);
368-
// };
369-
370-
371175
/**
372176
* Handle when the window is resized.
373177
*/
@@ -420,72 +224,6 @@ define([
420224
element.setAttribute('transform', 'scale(' + bgRatio + ')');
421225
};
422226

423-
// /**
424-
// * Animate a drag item into a given place.
425-
// *
426-
// * @param {jQuery} drag the item to place.
427-
// * @param {boolean} isScaling Scaling or not.
428-
// * @param {boolean} initialLoad Whether it is the initial load or not.
429-
// */
430-
// DrawlinesQuestion.prototype.sendDragToDrop = function(drag, isScaling, initialLoad = false) {
431-
// var dropArea = this.dropArea(),
432-
// bgRatio = this.bgRatio();
433-
// drag.removeClass('beingdragged').removeClass('unneeded');
434-
// var dragXY = this.convertToBgImgXY(new Line.Point(drag.data('pagex'), drag.data('pagey')));
435-
// if (isScaling) {
436-
// drag.data('originX', dragXY.x / bgRatio).data('originY', dragXY.y / bgRatio);
437-
// drag.css('left', dragXY.x).css('top', dragXY.y);
438-
// } else {
439-
// drag.data('originX', dragXY.x).data('originY', dragXY.y);
440-
// drag.css('left', dragXY.x * bgRatio).css('top', dragXY.y * bgRatio);
441-
// }
442-
// // We need to save the original scale ratio for each draggable item.
443-
// if (!initialLoad) {
444-
// // Only set the scale ratio for a current being-dragged item, not for the initial loading.
445-
// drag.data('scaleRatio', bgRatio);
446-
// }
447-
// dropArea.append(drag);
448-
// this.handleElementScale(drag, 'left top');
449-
// };
450-
//
451-
// /**
452-
// * Scale the drag if needed.
453-
// *
454-
// * @param {jQuery} element the item to place.
455-
// * @param {String} type scaling type
456-
// */
457-
// DrawlinesQuestion.prototype.handleElementScale = function(element, type) {
458-
// var bgRatio = parseFloat(this.bgRatio());
459-
// if (this.isPrinting) {
460-
// bgRatio = 1;
461-
// }
462-
// $(element).css({
463-
// '-webkit-transform': 'scale(' + bgRatio + ')',
464-
// '-moz-transform': 'scale(' + bgRatio + ')',
465-
// '-ms-transform': 'scale(' + bgRatio + ')',
466-
// '-o-transform': 'scale(' + bgRatio + ')',
467-
// 'transform': 'scale(' + bgRatio + ')',
468-
// 'transform-origin': type
469-
// });
470-
// };
471-
472-
// /**
473-
// * Sometimes, despite our best efforts, things change in a way that cannot
474-
// * be specifically caught (e.g. dock expanding or collapsing in Boost).
475-
// * Therefore, we need to periodically check everything is in the right position.
476-
// */
477-
// fixLayoutIfThingsMoved: function() {
478-
// if (!questionManager.isKeyboardNavigation) {
479-
// this.handleWindowResize(questionManager.isPrinting);
480-
// }
481-
// // We use setTimeout after finishing work, rather than setInterval,
482-
// // in case positioning things is slow. We want 100 ms gap
483-
// // between executions, not what setInterval does.
484-
// setTimeout(function() {
485-
// questionManager.fixLayoutIfThingsMoved(questionManager.isPrinting);
486-
// }, 100);
487-
// },
488-
489227
/**
490228
* Get the outer div for this question.
491229
*
@@ -690,28 +428,6 @@ define([
690428
if (items) {
691429
imageCoords = items.querySelector('polyline').getAttribute('points');
692430
gEleClassAttributes = items.getAttribute('class');
693-
// TODO: Kept the below comment as this could be needed for window resizing.
694-
695-
// thiQ = this,
696-
// bgRatio = this.bgRatio();
697-
// if (drag.data('scaleRatio') !== bgRatio) {
698-
// // The scale ratio for the draggable item was changed. We need to update that.
699-
// drag.data('pagex', drag.offset().left).data('pagey', drag.offset().top);
700-
// }
701-
// var dragXY = new Line.Point(drag.data('pagex'), drag.data('pagey'));
702-
// window.console.log("dragXY:" + dragXY);
703-
//
704-
// window.console.log("thiQ:" + thiQ);
705-
// if (thiQ.coordsInBgImg(dragXY)) {
706-
// var bgImgXY = thiQ.convertToBgImgXY(dragXY);
707-
// bgImgXY = new Line.Point(bgImgXY.x / bgRatio, bgImgXY.y / bgRatio);
708-
// imageCoords[imageCoords.length] = bgImgXY;
709-
// window.console.log("bgImgXY:" + bgImgXY);
710-
// }
711-
// } else if (drag.data('imageCoords')) {
712-
// imageCoords[imageCoords.length] = drag.data('imageCoords');
713-
// }
714-
715431
}
716432
if (gEleClassAttributes !== '' && gEleClassAttributes.includes('placed')) {
717433
this.getRoot().querySelector('input.choice' + choiceNo).value = imageCoords;

0 commit comments

Comments
 (0)