Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] maintenance and refactorings #1023

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 2 additions & 115 deletions src/core/jquery-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var methods = {
var settings = {
time: 3 /* time it will wait before moving to "timeout" after a move event */,
initialTime: 8 /* time it will wait before first adding the "timeout" class */,
exceptionAreas: [] /* IDs of elements that, if the mouse is over them, will reset the timer */,
exceptionAreas:
[] /* IDs of elements that, if the mouse is over them, will reset the timer */,
};
return this.each(function () {
var $this = $(this),
Expand Down Expand Up @@ -156,43 +157,6 @@ $.extend($.expr[":"], {
},
});

// Make Visible in scroll
$.fn.makeVisibleInScroll = function (parent_id) {
var absoluteParent = null;
if (typeof parent_id === "string") {
absoluteParent = $("#" + parent_id);
} else if (parent_id) {
absoluteParent = $(parent_id);
}

return this.each(function () {
var $this = $(this),
parent;
if (!absoluteParent) {
parent = $this.parents(":scrollable");
if (parent.length > 0) {
parent = $(parent[0]);
} else {
parent = $(window);
}
} else {
parent = absoluteParent;
}

var elemTop = $this.position().top;
var elemBottom = $this.height() + elemTop;

var viewTop = parent.scrollTop();
var viewBottom = parent.height() + viewTop;

if (elemTop < viewTop) {
parent.scrollTop(elemTop);
} else if (elemBottom > viewBottom - parent.height() / 2) {
parent.scrollTop(elemTop - (parent.height() - $this.height()) / 2);
}
});
};

//Work around warning for jQuery 3.x:
//JQMIGRATE: jQuery.fn.offset() requires an element connected to a document
$.fn.safeOffset = function () {
Expand All @@ -212,67 +176,6 @@ $.fn.safeOffset = function () {
return $.fn.offset.apply(this, arguments);
};

//Make absolute location
$.fn.setPositionAbsolute = function (element, offsettop, offsetleft) {
return this.each(function () {
// set absolute location for based on the element passed
// dynamically since every browser has different settings
var $this = $(this);
var thiswidth = $(this).width();
var pos = element.safeOffset();
var width = element.width();
var height = element.height();
var setleft = pos.left + width - thiswidth + offsetleft;
var settop = pos.top + height + offsettop;
$this.css({
"z-index": 1,
"position": "absolute",
"marginLeft": 0,
"marginTop": 0,
"left": setleft + "px",
"top": settop + "px",
"width": thiswidth,
});
$this.remove().appendTo("body").show();
});
};

$.fn.positionAncestor = function (selector) {
var left = 0;
var top = 0;
this.each(function () {
// check if current element has an ancestor matching a selector
// and that ancestor is positioned
var $ancestor = $(this).closest(selector);
if ($ancestor.length && $ancestor.css("position") !== "static") {
var $child = $(this);
var childMarginEdgeLeft =
$child.safeOffset().left - parseInt($child.css("marginLeft"), 10);
var childMarginEdgeTop =
$child.safeOffset().top - parseInt($child.css("marginTop"), 10);
var ancestorPaddingEdgeLeft =
$ancestor.safeOffset().left +
parseInt($ancestor.css("borderLeftWidth"), 10);
var ancestorPaddingEdgeTop =
$ancestor.safeOffset().top +
parseInt($ancestor.css("borderTopWidth"), 10);
left = childMarginEdgeLeft - ancestorPaddingEdgeLeft;
top = childMarginEdgeTop - ancestorPaddingEdgeTop;
// we have found the ancestor and computed the position
// stop iterating
return false;
}
});
return {
left: left,
top: top,
};
};

$.fn.findInclusive = function (selector) {
return this.find("*").addBack().filter(selector);
};

$.fn.slideIn = function (speed, easing, callback) {
return this.animate({ width: "show" }, speed, easing, callback);
};
Expand All @@ -281,20 +184,4 @@ $.fn.slideOut = function (speed, easing, callback) {
return this.animate({ width: "hide" }, speed, easing, callback);
};

// case-insensitive :contains
$.expr[":"].Contains = function (a, i, m) {
return $(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
};

$.fn.scopedFind = function (selector) {
/* If the selector starts with an object id do a global search,
* otherwise do a local search.
*/
if (selector.indexOf("#") === 0) {
return $(selector);
} else {
return this.find(selector);
}
};

export default undefined;
17 changes: 0 additions & 17 deletions src/core/jquery-ext.test.js

This file was deleted.

1 change: 1 addition & 0 deletions src/core/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import $ from "jquery";
import dom from "./dom";
import logging from "./logging";
import utils from "./utils";
import "./remove";

const log = logging.getLogger("registry");
const disable_re = /patterns-disable=([^&]+)/g;
Expand Down
63 changes: 0 additions & 63 deletions src/core/url.js

This file was deleted.

68 changes: 0 additions & 68 deletions src/core/url.test.js

This file was deleted.

8 changes: 5 additions & 3 deletions src/pat/inject/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,11 @@ const inject = {
$src = $source.safeClone();
}

$src.findInclusive("img").on("load", (e) => {
$(e.currentTarget).trigger("pat-inject-content-loaded");
});
for (const img of dom.querySelectorAllAndMe($src[0], "img")) {
$(img).on("load", (e) => {
$(e.currentTarget).trigger("pat-inject-content-loaded");
});
}

const $injected = cfg.$injected || $src;
// Now the injection actually happens.
Expand Down
Loading