Skip to content

Commit 366fd60

Browse files
committed
Merge branch 'EN-5' into EN-6
2 parents 7aca363 + 9f78cfe commit 366fd60

File tree

1 file changed

+29
-162
lines changed

1 file changed

+29
-162
lines changed

src/jquery.enjoyhint.js

Lines changed: 29 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,24 @@ CanvasRenderingContext2D.prototype.roundRect = function(x, y, w, h, r) {
277277
that.layer.add(that.shape);
278278
that.kinetic_stage.add(that.layer);
279279

280+
var doit;
281+
280282
$(window).on("resize", function() {
283+
clearTimeout(doit);
284+
$('.enjoyhint_next_btn').css('visibility', 'hidden');
285+
$('.enjoyhint_skip_btn').css('visibility', 'hidden');
286+
$('.enjoy_hint_label').remove()
287+
$("#enjoyhint_arrpw_line").remove()
281288
if (!$(that.stepData.enjoyHintElementSelector).is(":visible")) {
282289
that.stopFunction();
283290
$(window).off("resize");
284291
return;
285292
}
286293

287-
prevWindowWidth = window.innerWidth;
288-
prevWindowHeight = window.innerHeight;
289-
290294
var boundingClientRect = $(
291295
that.stepData.enjoyHintElementSelector
292296
)[0].getBoundingClientRect();
293-
297+
294298
that.shape.attrs.center_x = Math.round(
295299
boundingClientRect.left + boundingClientRect.width / 2
296300
);
@@ -300,170 +304,34 @@ CanvasRenderingContext2D.prototype.roundRect = function(x, y, w, h, r) {
300304
that.shape.attrs.width = boundingClientRect.width + 11;
301305
that.shape.attrs.height = boundingClientRect.height + 11;
302306

303-
var newWidth = window.innerWidth;
304-
var newHeight = window.innerHeight;
305-
var scaleX = newWidth / originalWidth;
306-
var scaleY = newHeight / originalHeight;
307-
308-
that.kinetic_stage.setAttr("width", originalWidth * scaleX);
309-
that.kinetic_stage.setAttr("height", originalHeight * scaleY);
310-
311-
if (that.stepData != null) {
312-
prevWindowWidth = window.innerWidth;
313-
prevWindowHeight = window.innerHeight;
314-
315-
/* Init */
316-
317-
if (!originalCenterX) {
318-
originalCenterX = that.shape.attrs.center_x;
319-
originalCenterY = that.shape.attrs.center_y;
320-
}
307+
function renderAfterResize(){
308+
var newDataCoords = $(that.stepData.enjoyHintElementSelector).get(0).getBoundingClientRect();
321309

322-
if (!originalArrowLeft) {
323-
originalArrowLeft = [];
324-
var attr = $("#enjoyhint_arrpw_line").attr("d");
325-
326-
if (attr) {
327-
originalArrowLeft.push(attr.substr(1).split(",")[0]);
328-
originalArrowLeft.push(
329-
attr.substr(attr.indexOf("Q") + 1).split(",")[0]
330-
);
331-
originalArrowLeft.push(attr.split(" ")[2].split(",")[0]);
332-
originalArrowTop = [];
333-
originalArrowTop.push(attr.split(",")[1].split(" ")[0]);
334-
originalArrowTop.push(attr.split(",")[2].split(" ")[0]);
335-
originalArrowTop.push(attr.split(",")[3]);
336-
}
337-
}
310+
that.stepData.center_x = newDataCoords.left + newDataCoords.width/2;
311+
that.stepData.center_y = newDataCoords.top + newDataCoords.height/2;
312+
that.stepData.width = newDataCoords.width + 11;
313+
that.stepData.height = newDataCoords.height + 11;
338314

339-
var labelElement = $(".enjoy_hint_label");
340-
341-
if (!originalLabelLeft) {
342-
originalLabelLeft = labelElement[0].getBoundingClientRect().left;
343-
originalLabelTop = labelElement[0].getBoundingClientRect().top;
344-
}
345-
346-
var skipButton = $(".enjoyhint_skip_btn");
315+
that.renderLabelWithShape(that.stepData);
316+
$('.enjoyhint_next_btn').css('visibility', 'visible');
317+
$('.enjoyhint_skip_btn').css('visibility', 'visible');
318+
}
347319

348-
if (!originalSkipbuttonLeft) {
349-
originalSkipbuttonLeft = skipButton[0].getBoundingClientRect()
350-
.left;
351-
originalSkipbuttonTop = skipButton[0].getBoundingClientRect().top;
320+
doit = setTimeout(function() {
321+
if(boundingClientRect.top < 0 || boundingClientRect.bottom > (window.innerHeight || document.documentElement.clientHeight)){
322+
$(document.body).scrollTo(that.stepData.enjoyHintElementSelector, 150, {offset: -200, onAfter:renderAfterResize});
352323
}
324+
else renderAfterResize();
325+
}, 150);
353326

354-
/* Resizing label */
355327

356-
labelElement.css(
357-
"left",
358-
window.innerWidth / 2 - labelElement.outerWidth() / 2
359-
);
360-
361-
/* Resizing arrow */
362-
363-
var labelRect = labelElement[0].getBoundingClientRect();
364-
365-
if (window.innerWidth < 640) {
366-
$("#enjoyhint_arrpw_line").hide();
367-
labelElement.css(
368-
"top",
369-
window.innerHeight / 2 - labelElement.outerHeight() / 2
370-
);
371-
} else {
372-
$("#enjoyhint_arrpw_line").show();
373-
374-
labelElement.css("top", originalLabelTop);
375-
376-
var x1, x2, y1, y2;
377-
378-
var labelLeftOfShape =
379-
labelRect.left + labelRect.width / 2 <
380-
that.shape.attrs.center_x;
381-
var labelAboveShape =
382-
labelRect.top + labelRect.height / 2 <
383-
that.shape.attrs.center_y;
384-
385-
if (window.innerWidth < 900) {
386-
x1 = Math.round(
387-
labelRect.left +
388-
(labelRect.width / 2 + 15) *
389-
(labelRect.left + labelRect.width / 2 <
390-
that.shape.attrs.center_x
391-
? 1
392-
: -1)
393-
);
394-
y1 = Math.round(
395-
labelRect.top +
396-
labelRect.height *
397-
(labelRect.top + labelRect.height / 2 <
398-
that.shape.attrs.center_y
399-
? 1
400-
: -1)
401-
);
402-
x2 = Math.round(
403-
that.shape.attrs.center_x +
404-
(that.shape.attrs.radius + 15) * (labelLeftOfShape ? -1 : 1)
405-
);
406-
y2 = Math.round(that.shape.attrs.center_y);
407-
} else {
408-
x1 = Math.round(
409-
labelRect.left +
410-
labelRect.width / 2 +
411-
(labelRect.width / 2 + 15) * (labelLeftOfShape ? 1 : -1)
412-
);
413-
y1 = Math.round(labelRect.top + labelRect.height / 2);
414-
x2 = Math.round(that.shape.attrs.center_x);
415-
y2 = Math.round(
416-
that.shape.attrs.center_y +
417-
(that.shape.attrs.height / 2 + 15) *
418-
(labelAboveShape ? -1 : 1)
419-
);
420-
}
421-
422-
var midX = x1 + (x2 - x1) / 2;
423-
var midY = y1 + (y2 - y1) / 2;
424-
425-
var bezX = x1 < x2 ? x2 : x1;
426-
var bezY = y1 < y2 ? y1 : y2;
427-
428-
if (
429-
Math.abs(
430-
labelRect.left +
431-
labelRect.width / 2 -
432-
that.shape.attrs.center_x
433-
) < 200
434-
) {
435-
x1 = x2 = labelRect.left + labelRect.width / 2;
436-
y1 = labelRect.top;
437-
bezX = x1;
438-
bezY = y1;
439-
}
440-
441-
if (window.innerWidth < 900) {
442-
bezX = x1 < x2 ? x1 : x2;
443-
bezY = y1 < y2 ? y2 : y1;
444-
}
445-
446-
var newCoordsLine = "M%d1,%d2 Q%d3,%d4 %d5,%d6"
447-
.replace("%d1", x1)
448-
.replace("%d2", y1)
449-
.replace("%d3", bezX)
450-
.replace("%d4", bezY)
451-
.replace("%d5", x2)
452-
.replace("%d6", y2);
453-
$("#enjoyhint_arrpw_line")[0].setAttribute("d", newCoordsLine);
454-
}
455-
456-
/* Resizing skip button */
328+
var newWidth = window.innerWidth;
329+
var newHeight = window.innerHeight;
330+
var scaleX = newWidth / originalWidth;
331+
var scaleY = newHeight / originalHeight;
457332

458-
var newSkipbuttonLeft =
459-
+originalSkipbuttonLeft +
460-
(that.shape.attrs.center_x - originalCenterX) / 2;
461-
skipButton.css(
462-
"left",
463-
newSkipbuttonLeft < 15 ? 15 : newSkipbuttonLeft
464-
);
465-
skipButton.css("top", labelRect.top + labelRect.height + 20);
466-
}
333+
that.kinetic_stage.setAttr("width", originalWidth * scaleX);
334+
that.kinetic_stage.setAttr("height", originalHeight * scaleY);
467335

468336
that.rect = new Kinetic.Rect({
469337
fill: options.fill,
@@ -474,7 +342,6 @@ CanvasRenderingContext2D.prototype.roundRect = function(x, y, w, h, r) {
474342
that.layer.removeChildren();
475343
that.layer.add(that.rect);
476344
that.layer.add(that.shape);
477-
that.layer.draw();
478345
that.kinetic_stage.draw();
479346
});
480347

0 commit comments

Comments
 (0)