mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-06-04 00:58:38 -04:00
Refactorings.
This commit is contained in:
parent
7f46dceba0
commit
8670b248a9
13 changed files with 264 additions and 1123 deletions
|
@ -28,6 +28,8 @@
|
||||||
</span>
|
</span>
|
||||||
</footer>
|
</footer>
|
||||||
<script src="/h5ai/js/lib/jquery.min.js"></script>
|
<script src="/h5ai/js/lib/jquery.min.js"></script>
|
||||||
|
<script src="/h5ai/js/lib/jquery.mousewheel.min.js"></script>
|
||||||
|
<script src="/h5ai/js/lib/jquery.fracs-core.min.js"></script>
|
||||||
<script src="/h5ai/options.js"></script>
|
<script src="/h5ai/options.js"></script>
|
||||||
<script src="/h5ai/js/main-js.js"></script>
|
<script src="/h5ai/js/main-js.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -61,6 +61,8 @@
|
||||||
</span>
|
</span>
|
||||||
</footer>
|
</footer>
|
||||||
<script src="/h5ai/js/lib/jquery.min.js"></script>
|
<script src="/h5ai/js/lib/jquery.min.js"></script>
|
||||||
|
<script src="/h5ai/js/lib/jquery.mousewheel.min.js"></script>
|
||||||
|
<script src="/h5ai/js/lib/jquery.fracs-core.min.js"></script>
|
||||||
<script src="/h5ai/options.js"></script>
|
<script src="/h5ai/options.js"></script>
|
||||||
<script src="/h5ai/js/main-php.js"></script>
|
<script src="/h5ai/js/main-php.js"></script>
|
||||||
<section id="table">
|
<section id="table">
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
/*global $, Objects */
|
||||||
|
|
||||||
var Extended = function (pathCache, h5ai) {
|
Objects.Extended = function (pathCache, h5ai) {
|
||||||
"use strict";
|
|
||||||
/*global $*/
|
|
||||||
|
|
||||||
var settings = {
|
var settings = {
|
||||||
customHeader: "h5ai.header.html",
|
customHeader: "h5ai.header.html",
|
||||||
|
@ -16,21 +15,19 @@ var Extended = function (pathCache, h5ai) {
|
||||||
},
|
},
|
||||||
initBreadcrumb = function () {
|
initBreadcrumb = function () {
|
||||||
|
|
||||||
var idx, part,
|
var $ul = $("body > nav ul"),
|
||||||
$ul = $("body > nav ul"),
|
|
||||||
pathname = "/",
|
pathname = "/",
|
||||||
path = pathCache.getPath(pathname),
|
path = pathCache.getPath(pathname),
|
||||||
pathnameParts = document.location.pathname.split("/");
|
pathnameParts = document.location.pathname.split("/");
|
||||||
|
|
||||||
$ul.append(path.updateCrumbHtml());
|
$ul.append(path.updateCrumbHtml());
|
||||||
|
|
||||||
for (idx in pathnameParts) {
|
$.each(pathnameParts, function (idx, part) {
|
||||||
part = pathnameParts[idx];
|
|
||||||
if (part !== "") {
|
if (part !== "") {
|
||||||
pathname += part + "/";
|
pathname += part + "/";
|
||||||
$ul.append(pathCache.getPath(pathname).updateCrumbHtml());
|
$ul.append(pathCache.getPath(pathname).updateCrumbHtml());
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
},
|
},
|
||||||
initExtendedView = function () {
|
initExtendedView = function () {
|
||||||
|
|
||||||
|
@ -47,11 +44,11 @@ var Extended = function (pathCache, h5ai) {
|
||||||
|
|
||||||
$ul = $("<ul/>");
|
$ul = $("<ul/>");
|
||||||
$li = $("<li class='header' />")
|
$li = $("<li class='header' />")
|
||||||
.appendTo($ul)
|
.appendTo($ul)
|
||||||
.append($("<a class='icon'></a>"))
|
.append($("<a class='icon'></a>"))
|
||||||
.append($("<a class='label' href='" + $label.attr("href") + "'><span class='l10n-name'>" + $label.text() + "</span></a>"))
|
.append($("<a class='label' href='" + $label.attr("href") + "'><span class='l10n-name'>" + $label.text() + "</span></a>"))
|
||||||
.append($("<a class='date' href='" + $date.attr("href") + "'><span class='l10n-lastModified'>" + $date.text() + "</span></a>"))
|
.append($("<a class='date' href='" + $date.attr("href") + "'><span class='l10n-lastModified'>" + $date.text() + "</span></a>"))
|
||||||
.append($("<a class='size' href='" + $size.attr("href") + "'><span class='l10n-size'>" + $size.text() + "</span></a>"));
|
.append($("<a class='size' href='" + $size.attr("href") + "'><span class='l10n-size'>" + $size.text() + "</span></a>"));
|
||||||
|
|
||||||
// header sort icons
|
// header sort icons
|
||||||
if (order.ascending) {
|
if (order.ascending) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
/*global window, $, Objects, localStorage */
|
||||||
|
|
||||||
var H5ai = function (options, langs) {
|
Objects.H5ai = function (options, langs) {
|
||||||
"use strict";
|
|
||||||
/*global $, window, localStorage*/
|
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
store: {
|
store: {
|
||||||
|
@ -29,7 +28,7 @@ var H5ai = function (options, langs) {
|
||||||
ignore: ["h5ai", "h5ai.header.html", "h5ai.footer.html"],
|
ignore: ["h5ai", "h5ai.header.html", "h5ai.footer.html"],
|
||||||
ignoreRE: ["/^\\./"],
|
ignoreRE: ["/^\\./"],
|
||||||
showThumbs: true,
|
showThumbs: true,
|
||||||
|
|
||||||
zippedDownload: true
|
zippedDownload: true
|
||||||
},
|
},
|
||||||
settings = $.extend({}, defaults, options),
|
settings = $.extend({}, defaults, options),
|
||||||
|
@ -41,11 +40,9 @@ var H5ai = function (options, langs) {
|
||||||
},
|
},
|
||||||
triggerPathClick = function (path, context) {
|
triggerPathClick = function (path, context) {
|
||||||
|
|
||||||
var i, l, a = settings.callbacks.pathClick;
|
$.each(settings.callbacks.pathClick, function (idx, callback) {
|
||||||
|
callback.call(window, path, context);
|
||||||
for (i = 0, l = a.length; i < l; i++) {
|
});
|
||||||
a[i].call(window, path, context);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
getViewmode = function () {
|
getViewmode = function () {
|
||||||
|
|
||||||
|
@ -144,14 +141,14 @@ var H5ai = function (options, langs) {
|
||||||
$(".status.default").show();
|
$(".status.default").show();
|
||||||
$(".status.dynamic").empty().hide();
|
$(".status.dynamic").empty().hide();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
shiftTree = function (forceVisible, dontAnimate) {
|
shiftTree = function (forceVisible, dontAnimate) {
|
||||||
|
|
||||||
var $tree = $("#tree"),
|
var $tree = $("#tree"),
|
||||||
$extended = $("#extended");
|
$extended = $("#extended");
|
||||||
|
|
||||||
if (settings.slideTree && $tree.outerWidth() < $extended.offset().left || forceVisible) {
|
if ((settings.slideTree && $tree.outerWidth() < $extended.offset().left) || forceVisible) {
|
||||||
if (dontAnimate) {
|
if (dontAnimate) {
|
||||||
$tree.stop().css({ left: 0 });
|
$tree.stop().css({ left: 0 });
|
||||||
} else {
|
} else {
|
||||||
|
@ -170,7 +167,7 @@ var H5ai = function (options, langs) {
|
||||||
$("#tree").hover(
|
$("#tree").hover(
|
||||||
function () { shiftTree(true); },
|
function () { shiftTree(true); },
|
||||||
function () { shiftTree(); }
|
function () { shiftTree(); }
|
||||||
);
|
);
|
||||||
$(window).resize(function () { shiftTree(); });
|
$(window).resize(function () { shiftTree(); });
|
||||||
shiftTree(false, true);
|
shiftTree(false, true);
|
||||||
},
|
},
|
||||||
|
@ -185,7 +182,7 @@ var H5ai = function (options, langs) {
|
||||||
$a.hover(
|
$a.hover(
|
||||||
function () { $("a[href='" + href + "']").addClass("hover"); },
|
function () { $("a[href='" + href + "']").addClass("hover"); },
|
||||||
function () { $("a[href='" + href + "']").removeClass("hover"); }
|
function () { $("a[href='" + href + "']").removeClass("hover"); }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -211,9 +208,9 @@ var H5ai = function (options, langs) {
|
||||||
|
|
||||||
selected = langs[lang];
|
selected = langs[lang];
|
||||||
if (selected) {
|
if (selected) {
|
||||||
for (key in selected) {
|
$.each(selected, function (key, value) {
|
||||||
$(".l10n-" + key).text(selected[key]);
|
$(".l10n-" + key).text(value);
|
||||||
}
|
});
|
||||||
$(".lang").text(lang);
|
$(".lang").text(lang);
|
||||||
$(".langOption").removeClass("current");
|
$(".langOption").removeClass("current");
|
||||||
$(".langOption." + lang).addClass("current");
|
$(".langOption." + lang).addClass("current");
|
||||||
|
@ -225,24 +222,22 @@ var H5ai = function (options, langs) {
|
||||||
sortedLangsKeys = [],
|
sortedLangsKeys = [],
|
||||||
$ul;
|
$ul;
|
||||||
|
|
||||||
for (lang in langs) {
|
$.each(langs, function (lang) {
|
||||||
sortedLangsKeys.push(lang);
|
sortedLangsKeys.push(lang);
|
||||||
}
|
});
|
||||||
sortedLangsKeys.sort();
|
sortedLangsKeys.sort();
|
||||||
|
|
||||||
$ul = $("<ul />");
|
$ul = $("<ul />");
|
||||||
for (idx in sortedLangsKeys) {
|
$.each(sortedLangsKeys, function (idx, lang) {
|
||||||
(function (lang) {
|
$("<li class='langOption' />")
|
||||||
$("<li class='langOption' />")
|
.addClass(lang)
|
||||||
.addClass(lang)
|
.text(lang + " - " + langs[lang].lang)
|
||||||
.text(lang + " - " + langs[lang].lang)
|
.appendTo($ul)
|
||||||
.appendTo($ul)
|
.click(function () {
|
||||||
.click(function () {
|
localStorage.setItem(settings.store.lang, lang);
|
||||||
localStorage.setItem(settings.store.lang, lang);
|
localize(langs, lang, false);
|
||||||
localize(langs, lang, false);
|
});
|
||||||
});
|
});
|
||||||
})(sortedLangsKeys[idx]);
|
|
||||||
}
|
|
||||||
$("#langSelector .langOptions").append($ul);
|
$("#langSelector .langOptions").append($ul);
|
||||||
$("#langSelector").hover(
|
$("#langSelector").hover(
|
||||||
function () {
|
function () {
|
||||||
|
@ -252,46 +247,47 @@ var H5ai = function (options, langs) {
|
||||||
function () {
|
function () {
|
||||||
$(".langOptions").stop(true, true).fadeOut();
|
$(".langOptions").stop(true, true).fadeOut();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
onIndicatorClick = function (event) {
|
||||||
|
|
||||||
|
var $indicator = $(this),
|
||||||
|
$entry = $indicator.closest(".entry");
|
||||||
|
|
||||||
|
if ($indicator.hasClass("unknown")) {
|
||||||
|
$.get("/h5ai/php/treecontent.php", { "href": $entry.find("> a").attr("href") }, function (html) {
|
||||||
|
|
||||||
|
var $content = $(html);
|
||||||
|
|
||||||
|
$indicator.removeClass("unknown");
|
||||||
|
if ($content.find("> li").size() === 0) {
|
||||||
|
$indicator.replaceWith($("<span class='blank' />"));
|
||||||
|
} else {
|
||||||
|
$indicator.addClass("open");
|
||||||
|
$entry.find("> .content").replaceWith($content);
|
||||||
|
$("#tree").get(0).updateScrollbar();
|
||||||
|
initIndicators();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if ($indicator.hasClass("open")) {
|
||||||
|
$indicator.removeClass("open");
|
||||||
|
$("#tree").get(0).updateScrollbar(true);
|
||||||
|
$entry.find("> .content").slideUp(function () {
|
||||||
|
$("#tree").get(0).updateScrollbar();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$indicator.addClass("open");
|
||||||
|
$("#tree").get(0).updateScrollbar(true);
|
||||||
|
$entry.find("> .content").slideDown(function () {
|
||||||
|
$("#tree").get(0).updateScrollbar();
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
initIndicators = function () {
|
initIndicators = function () {
|
||||||
|
|
||||||
$("#tree .entry.folder:not(.initiatedIndicator)").each(function () {
|
$("#tree .entry.folder .indicator:not(.initiated)").each(function () {
|
||||||
|
|
||||||
var $entry = $(this).addClass("initiatedIndicator"),
|
$(this).addClass("initiated").click(onIndicatorClick);
|
||||||
$indicator = $entry.find("> .indicator");
|
|
||||||
|
|
||||||
$indicator.click(function (event) {
|
|
||||||
|
|
||||||
var $content;
|
|
||||||
|
|
||||||
if ($indicator.hasClass("unknown")) {
|
|
||||||
$.get("/h5ai/php/treecontent.php", { "href": $entry.find("> a").attr("href") }, function (html) {
|
|
||||||
$content = $(html);
|
|
||||||
$indicator.removeClass("unknown");
|
|
||||||
if ($content.find("> li").size() === 0) {
|
|
||||||
$indicator.replaceWith($("<span class='blank' />"));
|
|
||||||
} else {
|
|
||||||
$indicator.addClass("open");
|
|
||||||
$entry.find("> .content").replaceWith($content);
|
|
||||||
$("#tree").get(0).updateScrollbar();
|
|
||||||
initIndicators();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if ($indicator.hasClass("open")) {
|
|
||||||
$indicator.removeClass("open");
|
|
||||||
$("#tree").get(0).updateScrollbar(true);
|
|
||||||
$entry.find("> .content").slideUp(function () {
|
|
||||||
$("#tree").get(0).updateScrollbar();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$indicator.addClass("open");
|
|
||||||
$("#tree").get(0).updateScrollbar(true);
|
|
||||||
$entry.find("> .content").slideDown(function () {
|
|
||||||
$("#tree").get(0).updateScrollbar();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
initZippedDownload = function () {
|
initZippedDownload = function () {
|
||||||
|
@ -302,9 +298,9 @@ var H5ai = function (options, langs) {
|
||||||
selected = function (hrefs) {
|
selected = function (hrefs) {
|
||||||
|
|
||||||
var query, idx;
|
var query, idx;
|
||||||
for (idx in hrefs) {
|
$.each(hrefs, function (idx, href) {
|
||||||
query = query ? query + ":" + hrefs[idx] : hrefs[idx];
|
query = query ? query + ":" + href : href;
|
||||||
}
|
});
|
||||||
query = "/h5ai/php/zipcontent.php?hrefs=" + query;
|
query = "/h5ai/php/zipcontent.php?hrefs=" + query;
|
||||||
$("#download").show().find("a").attr("href", query);
|
$("#download").show().find("a").attr("href", query);
|
||||||
},
|
},
|
||||||
|
@ -388,6 +384,7 @@ var H5ai = function (options, langs) {
|
||||||
linkHoverStates: linkHoverStates,
|
linkHoverStates: linkHoverStates,
|
||||||
pathClick: pathClick,
|
pathClick: pathClick,
|
||||||
triggerPathClick: triggerPathClick,
|
triggerPathClick: triggerPathClick,
|
||||||
|
initIndicators: initIndicators,
|
||||||
init: init
|
init: init
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,871 +0,0 @@
|
||||||
/*
|
|
||||||
* jQuery.fracs 0.10
|
|
||||||
* http://larsjung.de/fracs
|
|
||||||
*
|
|
||||||
* provided under the terms of the MIT License
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ModPlug 0.4
|
|
||||||
* http://larsjung.de/modplug
|
|
||||||
*
|
|
||||||
* provided under the terms of the MIT License
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function ($) {
|
|
||||||
"use strict";
|
|
||||||
/*globals jQuery */
|
|
||||||
/*jslint confusion: true */
|
|
||||||
|
|
||||||
var reference = "_mp_api";
|
|
||||||
|
|
||||||
$.ModPlug = $.ModPlug || {
|
|
||||||
plugin: function (namespace, options) {
|
|
||||||
|
|
||||||
if (!namespace || $[namespace] || $.fn[namespace]) {
|
|
||||||
// $.error("No namespace specified, or a plugin already exists on 'jQuery." + namespace + "'");
|
|
||||||
return !namespace ? 1 : ($[namespace] ? 2 : 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
var defaults = {
|
|
||||||
statics: {},
|
|
||||||
methods: {},
|
|
||||||
defaultStatic: undefined,
|
|
||||||
defaultMethod: undefined
|
|
||||||
},
|
|
||||||
settings = $.extend({}, defaults, options),
|
|
||||||
staticPlug = function () {
|
|
||||||
|
|
||||||
var args, defaultMethod;
|
|
||||||
|
|
||||||
args = Array.prototype.slice.call(arguments);
|
|
||||||
defaultMethod = settings.defaultStatic instanceof Function ? settings.defaultStatic.apply(this, args) : settings.defaultStatic;
|
|
||||||
if (staticPlug[defaultMethod] instanceof Function) {
|
|
||||||
return staticPlug[defaultMethod].apply(this, args);
|
|
||||||
}
|
|
||||||
$.error("Static method defaulted to '" + defaultMethod + "' does not exist on 'jQuery." + namespace + "'");
|
|
||||||
},
|
|
||||||
methods = {},
|
|
||||||
methodPlug = function (method) {
|
|
||||||
|
|
||||||
var args, defaultMethod;
|
|
||||||
|
|
||||||
if (methods[method] instanceof Function) {
|
|
||||||
args = Array.prototype.slice.call(arguments, 1);
|
|
||||||
return methods[method].apply(this, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
args = Array.prototype.slice.call(arguments);
|
|
||||||
defaultMethod = settings.defaultMethod instanceof Function ? settings.defaultMethod.apply(this, args) : settings.defaultMethod;
|
|
||||||
if (methods[defaultMethod] instanceof Function) {
|
|
||||||
return methods[defaultMethod].apply(this, args);
|
|
||||||
}
|
|
||||||
$.error("Method '" + method + "' defaulted to '" + defaultMethod + "' does not exist on 'jQuery." + namespace + "'");
|
|
||||||
},
|
|
||||||
api = {
|
|
||||||
addStatics: function (newStatics) {
|
|
||||||
|
|
||||||
$.extend(staticPlug, newStatics);
|
|
||||||
staticPlug[reference] = api;
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
addMethods: function (newMethods) {
|
|
||||||
|
|
||||||
$.extend(methods, newMethods);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
api.addStatics(settings.statics).addMethods(settings.methods);
|
|
||||||
$[namespace] = staticPlug;
|
|
||||||
$.fn[namespace] = methodPlug;
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
module: function (namespace, options) {
|
|
||||||
|
|
||||||
if (!$[namespace] || !$[namespace][reference]) {
|
|
||||||
// $.error("No ModPlug plugin exists on 'jQuery." + namespace + "'");
|
|
||||||
return !$[namespace] ? 1 : 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
var defaults = {
|
|
||||||
statics: {},
|
|
||||||
methods: {}
|
|
||||||
},
|
|
||||||
settings = $.extend({}, defaults, options);
|
|
||||||
|
|
||||||
$[namespace][reference].addStatics(settings.statics).addMethods(settings.methods);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}(jQuery));
|
|
||||||
|
|
||||||
/*
|
|
||||||
* jQuery.fracs - Core API
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function ($) {
|
|
||||||
"use strict";
|
|
||||||
/*globals jQuery, HTMLElement */
|
|
||||||
/*jslint browser: true, vars: true */
|
|
||||||
|
|
||||||
|
|
||||||
var FracsData = function (htmlElementOrRect) {
|
|
||||||
|
|
||||||
var target = htmlElementOrRect,
|
|
||||||
callbacks = [],
|
|
||||||
prevFracs;
|
|
||||||
|
|
||||||
this.size = function () {
|
|
||||||
|
|
||||||
return callbacks.length;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.bind = function (callback) {
|
|
||||||
|
|
||||||
if (callback instanceof Function && $.inArray(callback, callbacks) === -1) {
|
|
||||||
callbacks.push(callback);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.unbind = function (callback) {
|
|
||||||
|
|
||||||
if (callback instanceof Function) {
|
|
||||||
var idx = $.inArray(callback, callbacks);
|
|
||||||
if (idx >= 0) {
|
|
||||||
callbacks.splice(idx, 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
callbacks = [];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.check = function () {
|
|
||||||
|
|
||||||
var rect = target instanceof HTMLElement ? $.fracs.rect(target) : target,
|
|
||||||
fracs = $.fracs.fracs(rect, $.fracs.viewport());
|
|
||||||
|
|
||||||
if (!prevFracs || !prevFracs.equals(fracs)) {
|
|
||||||
$.each(callbacks, function (idx, callback) {
|
|
||||||
callback.call(target, fracs, prevFracs);
|
|
||||||
});
|
|
||||||
prevFracs = fracs;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var Rect = function (left, top, width, height) {
|
|
||||||
|
|
||||||
var fracsData;
|
|
||||||
|
|
||||||
this.left = Math.round(left);
|
|
||||||
this.top = Math.round(top);
|
|
||||||
this.width = Math.round(width);
|
|
||||||
this.height = Math.round(height);
|
|
||||||
this.right = this.left + this.width;
|
|
||||||
this.bottom = this.top + this.height;
|
|
||||||
|
|
||||||
this.equals = function (that) {
|
|
||||||
|
|
||||||
return this.left === that.left && this.top === that.top && this.width === that.width && this.height === that.height;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.area = function () {
|
|
||||||
|
|
||||||
return this.width * this.height;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.intersection = function (rect) {
|
|
||||||
|
|
||||||
var left = Math.max(this.left, rect.left),
|
|
||||||
right = Math.min(this.right, rect.right),
|
|
||||||
top = Math.max(this.top, rect.top),
|
|
||||||
bottom = Math.min(this.bottom, rect.bottom),
|
|
||||||
width = right - left,
|
|
||||||
height = bottom - top;
|
|
||||||
|
|
||||||
return (width >= 0 && height >= 0) ? new Rect(left, top, width, height) : undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.envelope = function (rect) {
|
|
||||||
|
|
||||||
var left = Math.min(this.left, rect.left),
|
|
||||||
right = Math.max(this.right, rect.right),
|
|
||||||
top = Math.min(this.top, rect.top),
|
|
||||||
bottom = Math.max(this.bottom, rect.bottom),
|
|
||||||
width = right - left,
|
|
||||||
height = bottom - top;
|
|
||||||
|
|
||||||
return new Rect(left, top, width, height);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.bind = function (callback) {
|
|
||||||
|
|
||||||
if (!fracsData) {
|
|
||||||
fracsData = new FracsData(this);
|
|
||||||
$(window).bind("scroll resize", fracsData.check);
|
|
||||||
}
|
|
||||||
fracsData.bind(callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.unbind = function (callback) {
|
|
||||||
|
|
||||||
if (fracsData) {
|
|
||||||
fracsData.unbind(callback);
|
|
||||||
if (fracsData.size() === 0) {
|
|
||||||
$(window).unbind("scroll resize", fracsData.check);
|
|
||||||
fracsData = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.check = function () {
|
|
||||||
|
|
||||||
if (fracsData) {
|
|
||||||
fracsData.check();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.fracs = function () {
|
|
||||||
|
|
||||||
$.fracs.fracs(this);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var FracsResult = function (rectDocument, rectElement, rectViewport, visible, viewport, possible) {
|
|
||||||
|
|
||||||
/*jslint confusion: true */
|
|
||||||
|
|
||||||
if (!rectDocument || !rectElement || !rectViewport || !visible || !viewport || !possible) {
|
|
||||||
this.rects = undefined;
|
|
||||||
this.visible = 0;
|
|
||||||
this.viewport = 0;
|
|
||||||
this.possible = 0;
|
|
||||||
} else {
|
|
||||||
this.rects = {
|
|
||||||
document: rectDocument,
|
|
||||||
element: rectElement,
|
|
||||||
viewport: rectViewport
|
|
||||||
};
|
|
||||||
this.visible = visible;
|
|
||||||
this.viewport = viewport;
|
|
||||||
this.possible = possible;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.equals = function (that) {
|
|
||||||
|
|
||||||
return this.fracsEqual(that) && this.rectsEqual(that);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.fracsEqual = function (that) {
|
|
||||||
|
|
||||||
return this.visible === that.visible && this.viewport === that.viewport && this.possible === that.possible;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.rectsEqual = function (that) {
|
|
||||||
|
|
||||||
if (!this.rects || !that.rects) {
|
|
||||||
return this.rects === that.rects;
|
|
||||||
}
|
|
||||||
return this.rects.document.equals(that.rects.document)
|
|
||||||
&& this.rects.element.equals(that.rects.element)
|
|
||||||
&& this.rects.viewport.equals(that.rects.viewport);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var ScrollState = function () {
|
|
||||||
|
|
||||||
var document = $.fracs.document(),
|
|
||||||
viewport = $.fracs.viewport(),
|
|
||||||
width = document.width - viewport.width,
|
|
||||||
height = document.height - viewport.height;
|
|
||||||
|
|
||||||
this.width = width <= 0 ? undefined : viewport.left / width;
|
|
||||||
this.height = height <= 0 ? undefined : viewport.top / height;
|
|
||||||
this.left = viewport.left;
|
|
||||||
this.top = viewport.top;
|
|
||||||
this.right = document.right - viewport.right;
|
|
||||||
this.bottom = document.bottom - viewport.bottom;
|
|
||||||
|
|
||||||
this.equals = function (that) {
|
|
||||||
|
|
||||||
return this.width === that.width && this.height === that.height
|
|
||||||
&& this.left === that.left && this.top === that.top
|
|
||||||
&& this.right === that.right && this.bottom === that.bottom;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var ScrollStateTracker = function () {
|
|
||||||
|
|
||||||
var prevState,
|
|
||||||
callbacks = [],
|
|
||||||
check = function () {
|
|
||||||
|
|
||||||
var state = new ScrollState();
|
|
||||||
if (!prevState || !prevState.equals(state)) {
|
|
||||||
$.each(callbacks, function (idx, callback) {
|
|
||||||
callback.call(window, state, prevState);
|
|
||||||
});
|
|
||||||
prevState = state;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$(window).bind("resize scroll load", check);
|
|
||||||
|
|
||||||
this.bind = function (callback) {
|
|
||||||
|
|
||||||
callbacks.push(callback);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// @beta
|
|
||||||
var FracsElement = function (htmlElement, fracs) {
|
|
||||||
|
|
||||||
this.element = htmlElement;
|
|
||||||
this.fracs = fracs;
|
|
||||||
|
|
||||||
this.update = function () {
|
|
||||||
|
|
||||||
var fracs = $.fracs.fracs(this.element),
|
|
||||||
changed = !this.fracs || !this.fracs.equals(fracs);
|
|
||||||
this.fracs = fracs;
|
|
||||||
return changed;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// @beta
|
|
||||||
var FracsGroup = function (htmlElements, property, callback) {
|
|
||||||
|
|
||||||
var THIS = this,
|
|
||||||
targets = [],
|
|
||||||
prevBest = null;
|
|
||||||
|
|
||||||
$.each(htmlElements, function (idx, element) {
|
|
||||||
if (element instanceof HTMLElement) {
|
|
||||||
targets.push(new FracsElement(element));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.check = function () {
|
|
||||||
|
|
||||||
var best,
|
|
||||||
viewport = $.fracs.viewport();
|
|
||||||
|
|
||||||
$.each(targets, function (idx, target) {
|
|
||||||
target.update();
|
|
||||||
if (!best || target.fracs[property] > best.fracs[property]) {
|
|
||||||
best = target;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
if (best && best.fracs[property] === 0) {
|
|
||||||
best = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prevBest !== best) {
|
|
||||||
callback.call(THIS, best, prevBest);
|
|
||||||
prevBest = best;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var $document = $(document),
|
|
||||||
$window = $(window),
|
|
||||||
$htmlBody = $("html,body"),
|
|
||||||
scrollStateTracker,
|
|
||||||
dataNs = "fracs",
|
|
||||||
statics = {
|
|
||||||
document: function () {
|
|
||||||
|
|
||||||
/*jslint confusion: true */
|
|
||||||
return new Rect(0, 0, $document.width(), $document.height());
|
|
||||||
},
|
|
||||||
viewport: function () {
|
|
||||||
|
|
||||||
/*jslint confusion: true */
|
|
||||||
return new Rect($window.scrollLeft(), $window.scrollTop(), $window.width(), $window.height());
|
|
||||||
},
|
|
||||||
rect: function (htmlElement) {
|
|
||||||
|
|
||||||
var $target = $(htmlElement),
|
|
||||||
offset = $target.offset();
|
|
||||||
|
|
||||||
if (!$target.is(":visible")) {
|
|
||||||
return new Rect(0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
return new Rect(offset.left, offset.top, $target.outerWidth(), $target.outerHeight());
|
|
||||||
},
|
|
||||||
fracs: function (rect, viewport) {
|
|
||||||
|
|
||||||
var intersection, intersectionElementSpace, intersectionViewportSpace, intersectionArea, possibleArea;
|
|
||||||
|
|
||||||
rect = rect instanceof HTMLElement ? statics.rect(rect) : rect;
|
|
||||||
viewport = viewport || statics.viewport();
|
|
||||||
intersection = rect.intersection(viewport);
|
|
||||||
|
|
||||||
if (!intersection) {
|
|
||||||
return new FracsResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
intersectionElementSpace = new Rect(intersection.left - rect.left, intersection.top - rect.top, intersection.width, intersection.height);
|
|
||||||
intersectionViewportSpace = new Rect(intersection.left - viewport.left, intersection.top - viewport.top, intersection.width, intersection.height);
|
|
||||||
intersectionArea = intersection.area();
|
|
||||||
possibleArea = Math.min(rect.width, viewport.width) * Math.min(rect.height, viewport.height);
|
|
||||||
|
|
||||||
return new FracsResult(
|
|
||||||
intersection,
|
|
||||||
intersectionElementSpace,
|
|
||||||
intersectionViewportSpace,
|
|
||||||
intersectionArea / rect.area(),
|
|
||||||
intersectionArea / viewport.area(),
|
|
||||||
intersectionArea / possibleArea
|
|
||||||
);
|
|
||||||
},
|
|
||||||
round: function (value, decs) {
|
|
||||||
|
|
||||||
if (isNaN(decs) || decs <= 0) {
|
|
||||||
return Math.round(value);
|
|
||||||
}
|
|
||||||
return Math.round(value * Math.pow(10, decs)) / Math.pow(10, decs);
|
|
||||||
},
|
|
||||||
scrollTo: function (left, top, duration) {
|
|
||||||
|
|
||||||
duration = isNaN(duration) ? 1000 : duration;
|
|
||||||
$htmlBody.stop(true).animate({ scrollLeft: left, scrollTop: top }, duration);
|
|
||||||
},
|
|
||||||
scroll: function (left, top, duration) {
|
|
||||||
|
|
||||||
duration = isNaN(duration) ? 1000 : duration;
|
|
||||||
$htmlBody.stop(true).animate({ scrollLeft: $window.scrollLeft() + left, scrollTop: $window.scrollTop() + top }, duration);
|
|
||||||
},
|
|
||||||
scrollState: function (callback) {
|
|
||||||
|
|
||||||
if (callback instanceof Function) {
|
|
||||||
scrollStateTracker = scrollStateTracker || new ScrollStateTracker();
|
|
||||||
scrollStateTracker.bind(callback);
|
|
||||||
} else {
|
|
||||||
return new ScrollState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods = {
|
|
||||||
bind: function (callback) {
|
|
||||||
|
|
||||||
return this.each(function () {
|
|
||||||
|
|
||||||
var $this = $(this),
|
|
||||||
data = $this.data(dataNs);
|
|
||||||
|
|
||||||
if (!data) {
|
|
||||||
data = new FracsData(this);
|
|
||||||
$this.data(dataNs, data);
|
|
||||||
$window.bind("scroll resize", data.check);
|
|
||||||
}
|
|
||||||
data.bind(callback);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
unbind: function (callback) {
|
|
||||||
|
|
||||||
return this.each(function () {
|
|
||||||
|
|
||||||
var $this = $(this),
|
|
||||||
data = $this.data(dataNs);
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
data.unbind(callback);
|
|
||||||
if (data.size() === 0) {
|
|
||||||
$this.removeData(dataNs);
|
|
||||||
$window.unbind("scroll resize", data.check);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
check: function () {
|
|
||||||
|
|
||||||
return this.each(function () {
|
|
||||||
|
|
||||||
var data = $(this).data(dataNs);
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
data.check();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
fracs: function () {
|
|
||||||
|
|
||||||
return statics.fracs(statics.rect(this.get(0)), statics.viewport());
|
|
||||||
},
|
|
||||||
rect: function () {
|
|
||||||
|
|
||||||
return statics.rect(this.get(0));
|
|
||||||
},
|
|
||||||
max: function (property, callback) {
|
|
||||||
|
|
||||||
if (callback instanceof Function) {
|
|
||||||
|
|
||||||
var data = new FracsGroup(this, property, callback);
|
|
||||||
|
|
||||||
$window.bind("scroll resize", data.check);
|
|
||||||
data.check();
|
|
||||||
return this;
|
|
||||||
} else {
|
|
||||||
var obj, elements, maxValue;
|
|
||||||
|
|
||||||
if ($.inArray(property, [ "possible", "visible", "viewport" ]) >= 0) {
|
|
||||||
obj = "fracs";
|
|
||||||
} else if ($.inArray(property, [ "width", "height", "left", "right", "top", "bottom" ]) >= 0) {
|
|
||||||
obj = "rect";
|
|
||||||
} else {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.each(function () {
|
|
||||||
|
|
||||||
var fracs = statics[obj](this);
|
|
||||||
|
|
||||||
if (!maxValue || fracs[property] > maxValue) {
|
|
||||||
elements = [ this ];
|
|
||||||
maxValue = fracs[property];
|
|
||||||
} else if (fracs[property] === maxValue) {
|
|
||||||
elements.push(this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return $(elements);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
min: function (property) {
|
|
||||||
|
|
||||||
var obj, elements, minValue;
|
|
||||||
|
|
||||||
if ($.inArray(property, [ "possible", "visible", "viewport" ]) >= 0) {
|
|
||||||
obj = "fracs";
|
|
||||||
} else if ($.inArray(property, [ "width", "height", "left", "right", "top", "bottom" ]) >= 0) {
|
|
||||||
obj = "rect";
|
|
||||||
} else {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.each(function () {
|
|
||||||
|
|
||||||
var fracs = statics[obj](this);
|
|
||||||
|
|
||||||
if (!minValue || fracs[property] < minValue) {
|
|
||||||
elements = [ this ];
|
|
||||||
minValue = fracs[property];
|
|
||||||
} else if (fracs[property] === minValue) {
|
|
||||||
elements.push(this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return $(elements);
|
|
||||||
},
|
|
||||||
envelope: function () {
|
|
||||||
|
|
||||||
var envelope, rect;
|
|
||||||
|
|
||||||
this.each(function () {
|
|
||||||
rect = statics.rect(this);
|
|
||||||
envelope = !envelope ? rect : envelope.envelope(rect);
|
|
||||||
});
|
|
||||||
return envelope;
|
|
||||||
},
|
|
||||||
scrollTo: function (paddingLeft, paddingTop, duration) {
|
|
||||||
|
|
||||||
var rect;
|
|
||||||
|
|
||||||
paddingLeft = paddingLeft || 0;
|
|
||||||
paddingTop = paddingTop || 0;
|
|
||||||
rect = statics.rect(this.get(0));
|
|
||||||
|
|
||||||
statics.scrollTo(rect.left - paddingLeft, rect.top - paddingTop, duration);
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
softLink: function (paddingLeft, paddingTop, duration) {
|
|
||||||
|
|
||||||
return this.filter("a[href^=#]").each(function () {
|
|
||||||
var $a = $(this),
|
|
||||||
href = $a.attr("href");
|
|
||||||
$a.click(function () {
|
|
||||||
$(href).fracs("scrollTo", paddingLeft, paddingTop, duration);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
defaultStatic = function () {
|
|
||||||
|
|
||||||
return "fracs";
|
|
||||||
},
|
|
||||||
defaultMethod = function () {
|
|
||||||
|
|
||||||
if (arguments.length === 0) {
|
|
||||||
return "fracs";
|
|
||||||
} else if (arguments[0] instanceof Function) {
|
|
||||||
return "bind";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
$.ModPlug.plugin("fracs", {
|
|
||||||
statics: statics,
|
|
||||||
methods: methods,
|
|
||||||
defaultStatic: defaultStatic,
|
|
||||||
defaultMethod: defaultMethod
|
|
||||||
});
|
|
||||||
|
|
||||||
}(jQuery));
|
|
||||||
|
|
||||||
/*
|
|
||||||
* jQuery.fracs - Outline API
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function ($) {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
/*globals jQuery */
|
|
||||||
/*jslint browser: true, vars: true */
|
|
||||||
|
|
||||||
|
|
||||||
var Outline = function (canvas, options) {
|
|
||||||
|
|
||||||
if (!(canvas instanceof HTMLElement && canvas.nodeName.toLowerCase() === "canvas")) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var defaults = {
|
|
||||||
crop: false,
|
|
||||||
duration: 0,
|
|
||||||
focusWidth: 0.5,
|
|
||||||
focusHeight: 0.5,
|
|
||||||
autoFocus: true,
|
|
||||||
styles: [ {
|
|
||||||
selector: "header,footer,section,article",
|
|
||||||
fillStyle: "rgb(230,230,230)"
|
|
||||||
}, {
|
|
||||||
selector: "h1",
|
|
||||||
fillStyle: "rgb(240,140,060)"
|
|
||||||
}, {
|
|
||||||
selector: "h2",
|
|
||||||
fillStyle: "rgb(200,100,100)"
|
|
||||||
}, {
|
|
||||||
selector: "h3",
|
|
||||||
fillStyle: "rgb(100,200,100)"
|
|
||||||
}, {
|
|
||||||
selector: "h4",
|
|
||||||
fillStyle: "rgb(100,100,200)"
|
|
||||||
} ],
|
|
||||||
viewportStyle: {
|
|
||||||
fillStyle: "rgba(228,77,38,0.3)"
|
|
||||||
},
|
|
||||||
viewportDragStyle: {
|
|
||||||
fillStyle: "rgba(228,77,38,0.6)"
|
|
||||||
},
|
|
||||||
invertViewport: false
|
|
||||||
},
|
|
||||||
settings = $.extend({}, defaults, options),
|
|
||||||
$window = $(window),
|
|
||||||
$htmlBody = $("html,body"),
|
|
||||||
$canvas = $(canvas),
|
|
||||||
width = $canvas.attr("width"),
|
|
||||||
height = $canvas.attr("height"),
|
|
||||||
context = canvas.getContext("2d"),
|
|
||||||
docRect,
|
|
||||||
vpRect,
|
|
||||||
scale,
|
|
||||||
drag = false,
|
|
||||||
focusWidth,
|
|
||||||
focusHeight,
|
|
||||||
scroll = function (event) {
|
|
||||||
|
|
||||||
var r, x, y;
|
|
||||||
|
|
||||||
r = $canvas.fracs("rect");
|
|
||||||
x = event.pageX - r.left;
|
|
||||||
y = event.pageY - r.top;
|
|
||||||
$.fracs.scrollTo(x / scale - vpRect.width * focusWidth, y / scale - vpRect.height * focusHeight, settings.duration);
|
|
||||||
},
|
|
||||||
drawRect = function (context, rect, strokeWidth, strokeStyle, fillStyle, invert) {
|
|
||||||
|
|
||||||
if (strokeWidth !== undefined && scale) {
|
|
||||||
strokeWidth = strokeWidth > 0.2 / scale ? strokeWidth : 0.2 / scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strokeStyle || fillStyle) {
|
|
||||||
if (invert !== true) {
|
|
||||||
context.beginPath();
|
|
||||||
context.rect(rect.left, rect.top, rect.width, rect.height);
|
|
||||||
if (fillStyle) {
|
|
||||||
context.fillStyle = fillStyle;
|
|
||||||
context.fill();
|
|
||||||
}
|
|
||||||
if (strokeStyle) {
|
|
||||||
context.lineWidth = strokeWidth;
|
|
||||||
context.strokeStyle = strokeStyle;
|
|
||||||
context.stroke();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (fillStyle) {
|
|
||||||
context.beginPath();
|
|
||||||
context.rect(0, 0, docRect.width, rect.top);
|
|
||||||
context.rect(0, rect.top, rect.left, rect.height);
|
|
||||||
context.rect(rect.right, rect.top, docRect.right - rect.right, rect.height);
|
|
||||||
context.rect(0, rect.bottom, docRect.width, docRect.bottom - rect.bottom);
|
|
||||||
context.fillStyle = fillStyle;
|
|
||||||
context.fill();
|
|
||||||
}
|
|
||||||
if (strokeStyle) {
|
|
||||||
context.beginPath();
|
|
||||||
context.rect(rect.left, rect.top, rect.width, rect.height);
|
|
||||||
context.lineWidth = strokeWidth;
|
|
||||||
context.strokeStyle = strokeStyle;
|
|
||||||
context.stroke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
drawElement = function (context, htmlElement, strokeWidth, strokeStyle, fillStyle) {
|
|
||||||
|
|
||||||
var $element = $(htmlElement),
|
|
||||||
rect = $element.fracs("rect");
|
|
||||||
|
|
||||||
if ($element.css("visibility") === "hidden") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
strokeWidth = strokeWidth === "auto" ? $element.css("border-top-width") : strokeWidth;
|
|
||||||
strokeStyle = strokeStyle === "auto" ? $element.css("border-top-color") : strokeStyle;
|
|
||||||
fillStyle = fillStyle === "auto" ? $element.css("background-color") : fillStyle;
|
|
||||||
drawRect(context, rect, strokeWidth, strokeStyle, fillStyle);
|
|
||||||
},
|
|
||||||
drawViewport = function () {
|
|
||||||
|
|
||||||
var strokeWidth, strokeStyle, fillStyle;
|
|
||||||
|
|
||||||
if (drag && settings.viewportDragStyle) {
|
|
||||||
strokeWidth = settings.viewportDragStyle.storkeWidth;
|
|
||||||
strokeStyle = settings.viewportDragStyle.strokeStyle;
|
|
||||||
fillStyle = settings.viewportDragStyle.fillStyle;
|
|
||||||
} else {
|
|
||||||
strokeWidth = settings.viewportStyle.storkeWidth;
|
|
||||||
strokeStyle = settings.viewportStyle.strokeStyle;
|
|
||||||
fillStyle = settings.viewportStyle.fillStyle;
|
|
||||||
}
|
|
||||||
drawRect(context, vpRect, strokeWidth, strokeStyle, fillStyle, settings.invertViewport);
|
|
||||||
},
|
|
||||||
applyStyles = function (context) {
|
|
||||||
|
|
||||||
$.each(settings.styles, function (idx, style) {
|
|
||||||
$(style.selector).each(function () {
|
|
||||||
drawElement(context, this, style.strokeWidth, style.strokeStyle, style.fillStyle);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
draw = function () {
|
|
||||||
|
|
||||||
/*jslint confusion: true */
|
|
||||||
|
|
||||||
var scaleX, scaleY;
|
|
||||||
|
|
||||||
docRect = $.fracs.document();
|
|
||||||
vpRect = $.fracs.viewport();
|
|
||||||
scaleX = width / docRect.width;
|
|
||||||
scaleY = height / docRect.height;
|
|
||||||
scale = scaleX < scaleY ? scaleX : scaleY;
|
|
||||||
|
|
||||||
if (settings.crop) {
|
|
||||||
$canvas.attr("width", docRect.width * scale).attr("height", docRect.height * scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
context.clearRect(0, 0, $canvas.width(), $canvas.height());
|
|
||||||
|
|
||||||
context.scale(scale, scale);
|
|
||||||
applyStyles(context);
|
|
||||||
drawViewport();
|
|
||||||
context.scale(1 / scale, 1 / scale);
|
|
||||||
},
|
|
||||||
init = function () {
|
|
||||||
|
|
||||||
$canvas
|
|
||||||
.css("cursor", "pointer")
|
|
||||||
.mousedown(function (event) {
|
|
||||||
|
|
||||||
var r;
|
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
drag = true;
|
|
||||||
if (settings.autoFocus) {
|
|
||||||
r = $canvas.fracs("rect");
|
|
||||||
focusWidth = (((event.pageX - r.left) / scale) - vpRect.left) / vpRect.width;
|
|
||||||
focusHeight = (((event.pageY - r.top) / scale) - vpRect.top) / vpRect.height;
|
|
||||||
}
|
|
||||||
if (!settings.autoFocus || focusWidth < 0 || focusWidth > 1 || focusHeight < 0 || focusHeight > 1) {
|
|
||||||
focusWidth = settings.focusWidth;
|
|
||||||
focusHeight = settings.focusHeight;
|
|
||||||
}
|
|
||||||
scroll(event);
|
|
||||||
$canvas.css("cursor", "crosshair").addClass("dragOn");
|
|
||||||
$htmlBody.css("cursor", "crosshair");
|
|
||||||
$window
|
|
||||||
.bind("mousemove", scroll)
|
|
||||||
.one("mouseup", function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
$canvas.css("cursor", "pointer").removeClass("dragOn");
|
|
||||||
$htmlBody.css("cursor", "auto");
|
|
||||||
$window.unbind("mousemove", scroll);
|
|
||||||
drag = false;
|
|
||||||
draw();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
canvas.onselectstart = function () {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
$window.bind("load resize scroll", draw);
|
|
||||||
draw();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
|
|
||||||
this.draw = draw;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var dataNs = "outline",
|
|
||||||
methods = {
|
|
||||||
outline: function (options) {
|
|
||||||
|
|
||||||
return this.each(function () {
|
|
||||||
|
|
||||||
var outline;
|
|
||||||
|
|
||||||
if (options === "redraw") {
|
|
||||||
outline = $(this).data(dataNs);
|
|
||||||
if (outline) {
|
|
||||||
outline.draw();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
outline = new Outline(this, options);
|
|
||||||
if (outline) {
|
|
||||||
$(this).data(dataNs, outline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
$.ModPlug.module("fracs", {
|
|
||||||
methods: methods
|
|
||||||
});
|
|
||||||
|
|
||||||
}(jQuery));
|
|
||||||
|
|
|
@ -1,139 +1,142 @@
|
||||||
|
/*global window, jQuery */
|
||||||
|
|
||||||
(function ($) {
|
(function ($) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
var init = function (htmlElement) {
|
var init = function (htmlElement) {
|
||||||
|
|
||||||
var $element = $(htmlElement),
|
var $element = $(htmlElement),
|
||||||
$scrollbar, $drag, $wrapper, $content, mouseOffsetY, updateId,
|
$scrollbar, $drag, $wrapper, $content, mouseOffsetY, updateId,
|
||||||
update, scroll;
|
update, scroll;
|
||||||
|
|
||||||
if (!$element.css("position") || $element.css("position") === "static") {
|
if (!$element.css("position") || $element.css("position") === "static") {
|
||||||
$element.css("position", "relative");
|
$element.css("position", "relative");
|
||||||
}
|
|
||||||
|
|
||||||
$scrollbar = $("<div class='scrollbar' />");
|
|
||||||
$drag = $("<div class='drag' />").appendTo($scrollbar);
|
|
||||||
$element
|
|
||||||
.wrapInner("<div class='wrapper'><div class='content' /></div>")
|
|
||||||
.append($scrollbar);
|
|
||||||
$wrapper = $element.find("> .wrapper");
|
|
||||||
$content = $wrapper.find("> .content");
|
|
||||||
mouseOffsetY = 0;
|
|
||||||
|
|
||||||
update = function (repeat) {
|
|
||||||
|
|
||||||
var visibleHeight, contentHeight, scrollTop, scrollTopFrac, visVertFrac;
|
|
||||||
|
|
||||||
if (updateId && !repeat) {
|
|
||||||
clearInterval(updateId);
|
|
||||||
updateId = undefined;
|
|
||||||
} else if (!updateId && repeat) {
|
|
||||||
updateId = setInterval(function() { update(true); }, 50);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$wrapper.css("height", $element.height());
|
$scrollbar = $("<div class='scrollbar' />");
|
||||||
visibleHeight = $element.height();
|
$drag = $("<div class='drag' />").appendTo($scrollbar);
|
||||||
contentHeight = $content.outerHeight();
|
$element
|
||||||
scrollTop = $wrapper.scrollTop();
|
.wrapInner("<div class='wrapper'><div class='content' /></div>")
|
||||||
scrollTopFrac = scrollTop / contentHeight;
|
.append($scrollbar);
|
||||||
visVertFrac = Math.min(visibleHeight / contentHeight, 1);
|
$wrapper = $element.find("> .wrapper");
|
||||||
|
$content = $wrapper.find("> .content");
|
||||||
if (visVertFrac < 1) {
|
mouseOffsetY = 0;
|
||||||
$scrollbar
|
|
||||||
.fadeIn(50)
|
update = function (repeat) {
|
||||||
.css({
|
|
||||||
height: $element.innerHeight() + $scrollbar.height() - $scrollbar.outerHeight(true)
|
var visibleHeight, contentHeight, scrollTop, scrollTopFrac, visVertFrac;
|
||||||
});
|
|
||||||
$drag
|
if (updateId && !repeat) {
|
||||||
.css({
|
clearInterval(updateId);
|
||||||
top: $scrollbar.height() * scrollTopFrac,
|
updateId = undefined;
|
||||||
height: $scrollbar.height() * visVertFrac
|
} else if (!updateId && repeat) {
|
||||||
});
|
updateId = setInterval(function() { update(true); }, 50);
|
||||||
} else {
|
}
|
||||||
$scrollbar.fadeOut(50);
|
|
||||||
}
|
$wrapper.css("height", $element.height());
|
||||||
};
|
visibleHeight = $element.height();
|
||||||
|
contentHeight = $content.outerHeight();
|
||||||
scroll = function (event) {
|
scrollTop = $wrapper.scrollTop();
|
||||||
|
scrollTopFrac = scrollTop / contentHeight;
|
||||||
var clickFrac = (event.pageY - $scrollbar.offset().top - mouseOffsetY) / $scrollbar.height();
|
visVertFrac = Math.min(visibleHeight / contentHeight, 1);
|
||||||
|
|
||||||
$wrapper.scrollTop($content.outerHeight() * clickFrac);
|
if (visVertFrac < 1) {
|
||||||
update();
|
$scrollbar
|
||||||
event.preventDefault();
|
.fadeIn(50)
|
||||||
};
|
.css({
|
||||||
|
height: $element.innerHeight() + $scrollbar.height() - $scrollbar.outerHeight(true)
|
||||||
$element
|
});
|
||||||
.mousewheel(function (event, delta) {
|
$drag
|
||||||
|
.css({
|
||||||
$wrapper.scrollTop($wrapper.scrollTop() - 50 * delta);
|
top: $scrollbar.height() * scrollTopFrac,
|
||||||
|
height: $scrollbar.height() * visVertFrac
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$scrollbar.fadeOut(50);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
scroll = function (event) {
|
||||||
|
|
||||||
|
var clickFrac = (event.pageY - $scrollbar.offset().top - mouseOffsetY) / $scrollbar.height();
|
||||||
|
|
||||||
|
$wrapper.scrollTop($content.outerHeight() * clickFrac);
|
||||||
update();
|
update();
|
||||||
event.stopPropagation();
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
})
|
};
|
||||||
.scroll(update);
|
|
||||||
$element.get(0).updateScrollbar = update;
|
$element
|
||||||
$wrapper
|
.mousewheel(function (event, delta) {
|
||||||
.css({
|
|
||||||
"padding-right": $scrollbar.outerWidth(true),
|
$wrapper.scrollTop($wrapper.scrollTop() - 50 * delta);
|
||||||
height: $element.height(),
|
update();
|
||||||
overflow: "hidden"
|
event.stopPropagation();
|
||||||
});
|
event.preventDefault();
|
||||||
$scrollbar
|
})
|
||||||
.css({
|
.scroll(update);
|
||||||
position: "absolute",
|
$element.get(0).updateScrollbar = update;
|
||||||
top: 0,
|
$wrapper
|
||||||
right: 0,
|
.css({
|
||||||
overflow: "hidden",
|
"padding-right": $scrollbar.outerWidth(true),
|
||||||
cursor: "pointer"
|
height: $element.height(),
|
||||||
})
|
overflow: "hidden"
|
||||||
.mousedown(function (event) {
|
});
|
||||||
|
$scrollbar
|
||||||
mouseOffsetY = $drag.outerHeight() / 2;
|
.css({
|
||||||
scroll(event);
|
position: "absolute",
|
||||||
$scrollbar.addClass("dragOn");
|
top: 0,
|
||||||
$(window)
|
right: 0,
|
||||||
.bind("mousemove", scroll)
|
overflow: "hidden",
|
||||||
.one("mouseup", function (event) {
|
cursor: "pointer"
|
||||||
|
})
|
||||||
$scrollbar.removeClass("dragOn");
|
.mousedown(function (event) {
|
||||||
$(window).unbind("mousemove", scroll);
|
|
||||||
scroll(event);
|
mouseOffsetY = $drag.outerHeight() / 2;
|
||||||
event.stopPropagation();
|
scroll(event);
|
||||||
});
|
$scrollbar.addClass("dragOn");
|
||||||
event.preventDefault();
|
$(window)
|
||||||
})
|
.bind("mousemove", scroll)
|
||||||
.each(function () {
|
.one("mouseup", function (event) {
|
||||||
|
|
||||||
this.onselectstart = function () {
|
$scrollbar.removeClass("dragOn");
|
||||||
|
$(window).unbind("mousemove", scroll);
|
||||||
return false;
|
scroll(event);
|
||||||
};
|
event.stopPropagation();
|
||||||
});
|
});
|
||||||
$drag
|
event.preventDefault();
|
||||||
.css({
|
})
|
||||||
position: "absolute",
|
.each(function () {
|
||||||
left: 0,
|
|
||||||
width: "100%"
|
this.onselectstart = function () {
|
||||||
})
|
|
||||||
.mousedown(function (event) {
|
return false;
|
||||||
|
};
|
||||||
mouseOffsetY = event.pageY - $drag.offset().top;
|
});
|
||||||
scroll(event);
|
$drag
|
||||||
$scrollbar.addClass("dragOn");
|
.css({
|
||||||
$(window)
|
position: "absolute",
|
||||||
.bind("mousemove", scroll)
|
left: 0,
|
||||||
.one("mouseup", function (event) {
|
width: "100%"
|
||||||
|
})
|
||||||
$scrollbar.removeClass("dragOn");
|
.mousedown(function (event) {
|
||||||
$(window).unbind("mousemove", scroll);
|
|
||||||
scroll(event);
|
mouseOffsetY = event.pageY - $drag.offset().top;
|
||||||
event.stopPropagation();
|
scroll(event);
|
||||||
});
|
$scrollbar.addClass("dragOn");
|
||||||
event.stopPropagation();
|
$(window)
|
||||||
});
|
.bind("mousemove", scroll)
|
||||||
|
.one("mouseup", function (event) {
|
||||||
update();
|
|
||||||
};
|
$scrollbar.removeClass("dragOn");
|
||||||
|
$(window).unbind("mousemove", scroll);
|
||||||
|
scroll(event);
|
||||||
|
event.stopPropagation();
|
||||||
|
});
|
||||||
|
event.stopPropagation();
|
||||||
|
});
|
||||||
|
|
||||||
|
update();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
$.fn.scrollpanel = function () {
|
$.fn.scrollpanel = function () {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
/*global window, jQuery */
|
||||||
|
|
||||||
(function ($) {
|
(function ($) {
|
||||||
"use strict";
|
"use strict";
|
||||||
/*global jQuery, window*/
|
|
||||||
|
|
||||||
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
|
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
|
||||||
// modified
|
// modified
|
||||||
|
@ -26,4 +27,4 @@
|
||||||
return timer;
|
return timer;
|
||||||
}());
|
}());
|
||||||
|
|
||||||
}(jQuery));
|
}(jQuery));
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
/*global $, Objects */
|
||||||
|
|
||||||
var Path = function (pathCache, folder, tableRow) {
|
Objects.Path = function (pathCache, folder, tableRow) {
|
||||||
"use strict";
|
|
||||||
/*global $, h5ai, tree*/
|
|
||||||
|
|
||||||
var path,
|
var path,
|
||||||
checkedDecodeUri = function (uri) {
|
checkedDecodeUri = function (uri) {
|
||||||
|
@ -11,7 +10,7 @@ var Path = function (pathCache, folder, tableRow) {
|
||||||
},
|
},
|
||||||
isEmpty = function () {
|
isEmpty = function () {
|
||||||
|
|
||||||
return path.content === undefined || $.isEmptyObject(path.content);
|
return !path.content || $.isEmptyObject(path.content);
|
||||||
},
|
},
|
||||||
onClick = function (context) {
|
onClick = function (context) {
|
||||||
|
|
||||||
|
@ -124,7 +123,7 @@ var Path = function (pathCache, folder, tableRow) {
|
||||||
if (!h5ai.settings.setParentFolderLabels) {
|
if (!h5ai.settings.setParentFolderLabels) {
|
||||||
$label.addClass("l10n-parentDirectory");
|
$label.addClass("l10n-parentDirectory");
|
||||||
}
|
}
|
||||||
$html.addClass("parentfolder");
|
$html.addClass("folder-parent");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isNaN(path.status)) {
|
if (!isNaN(path.status)) {
|
||||||
|
@ -171,6 +170,7 @@ var Path = function (pathCache, folder, tableRow) {
|
||||||
} else if (path.treeOpen) {
|
} else if (path.treeOpen) {
|
||||||
$indicator.addClass("open");
|
$indicator.addClass("open");
|
||||||
}
|
}
|
||||||
|
|
||||||
$indicator.click(function(event) {
|
$indicator.click(function(event) {
|
||||||
|
|
||||||
if ($indicator.hasClass("unknown")) {
|
if ($indicator.hasClass("unknown")) {
|
||||||
|
@ -204,9 +204,10 @@ var Path = function (pathCache, folder, tableRow) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$html.addClass("initiatedIndicator");
|
$html.addClass("initiatedIndicator");
|
||||||
|
|
||||||
$blank.replaceWith($indicator);
|
$blank.replaceWith($indicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// is path the domain?
|
// is path the domain?
|
||||||
if (path.isDomain) {
|
if (path.isDomain) {
|
||||||
$html.addClass("domain");
|
$html.addClass("domain");
|
||||||
|
@ -222,9 +223,9 @@ var Path = function (pathCache, folder, tableRow) {
|
||||||
// does it have subfolders?
|
// does it have subfolders?
|
||||||
if (!path.isEmpty()) {
|
if (!path.isEmpty()) {
|
||||||
$ul = $("<ul class='content' />").appendTo($html);
|
$ul = $("<ul class='content' />").appendTo($html);
|
||||||
for (idx in path.content) {
|
$.each(path.content, function (idx, entry) {
|
||||||
$("<li />").append(path.content[idx].updateTreeHtml()).appendTo($ul);
|
$("<li />").append(entry.updateTreeHtml()).appendTo($ul);
|
||||||
}
|
});
|
||||||
if (path.status === undefined || !path.treeOpen) {
|
if (path.status === undefined || !path.treeOpen) {
|
||||||
$ul.hide();
|
$ul.hide();
|
||||||
}
|
}
|
||||||
|
@ -342,9 +343,7 @@ var Path = function (pathCache, folder, tableRow) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var PathCache = function () {
|
Objects.PathCache = function () {
|
||||||
"use strict";
|
|
||||||
/*global $*/
|
|
||||||
|
|
||||||
var pathCache,
|
var pathCache,
|
||||||
cache = {},
|
cache = {},
|
||||||
|
@ -385,7 +384,7 @@ var PathCache = function () {
|
||||||
path = cache[absHref];
|
path = cache[absHref];
|
||||||
|
|
||||||
if (!path) {
|
if (!path) {
|
||||||
path = new Path(pathCache, folder, tableRow);
|
path = new Objects.Path(pathCache, folder, tableRow);
|
||||||
if (!path.isParentFolder) {
|
if (!path.isParentFolder) {
|
||||||
cache[path.absHref] = path;
|
cache[path.absHref] = path;
|
||||||
}
|
}
|
||||||
|
@ -397,7 +396,8 @@ var PathCache = function () {
|
||||||
pathCache = {
|
pathCache = {
|
||||||
splitPathname: splitPathname,
|
splitPathname: splitPathname,
|
||||||
pathEndsWithSlash: pathEndsWithSlash,
|
pathEndsWithSlash: pathEndsWithSlash,
|
||||||
getPath: getPath
|
getPath: getPath,
|
||||||
|
cache: cache
|
||||||
};
|
};
|
||||||
|
|
||||||
return pathCache;
|
return pathCache;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
/*global $, Objects */
|
||||||
|
|
||||||
var Tree = function (pathCache, h5ai) {
|
Objects.Tree = function (pathCache, h5ai) {
|
||||||
"use strict";
|
|
||||||
/*global $*/
|
|
||||||
|
|
||||||
var contentTypeRegEx = /^text\/html;h5ai=/,
|
var contentTypeRegEx = /^text\/html;h5ai=/,
|
||||||
pathnameStatusCache = {},
|
pathnameStatusCache = {},
|
||||||
|
@ -45,11 +44,9 @@ var Tree = function (pathCache, h5ai) {
|
||||||
},
|
},
|
||||||
updatePaths = function () {
|
updatePaths = function () {
|
||||||
|
|
||||||
var ref;
|
$.each(pathCache.cache, function (ref, cached) {
|
||||||
|
updatePath(cached);
|
||||||
for (ref in pathCache.cache) {
|
});
|
||||||
updatePath(pathCache.cache[ref]);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
fetchStatusAndContent = function (pathname, includeParent, callback) {
|
fetchStatusAndContent = function (pathname, includeParent, callback) {
|
||||||
|
|
||||||
|
|
7
src/h5ai/js/lib/jquery.fracs-core.min.js
vendored
Normal file
7
src/h5ai/js/lib/jquery.fracs-core.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,20 +1,23 @@
|
||||||
|
/*global jQuery, h5aiOptions, h5aiLangs*/
|
||||||
|
|
||||||
|
// @include "inc/jquery.scrollpanel.js"
|
||||||
|
// @include "inc/jquery.utils.js"
|
||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
"use strict";
|
"use strict";
|
||||||
/*global jQuery, h5aiOptions, h5aiLangs*/
|
|
||||||
|
|
||||||
// @include "inc/jquery.mousewheel.min.js"
|
var Objects = {},
|
||||||
// @include "inc/jquery.scrollpanel.js"
|
pathCache, h5ai, extended, tree;
|
||||||
// @include "inc/jquery.utils.js"
|
|
||||||
// @include "inc/jquery.fracs.js"
|
|
||||||
// @include "inc/path.js"
|
|
||||||
// @include "inc/h5ai.js"
|
// @include "inc/h5ai.js"
|
||||||
|
// @include "inc/path.js"
|
||||||
// @include "inc/extended.js"
|
// @include "inc/extended.js"
|
||||||
// @include "inc/tree.js"
|
// @include "inc/tree.js"
|
||||||
|
|
||||||
var pathCache = new PathCache(),
|
pathCache = new Objects.PathCache();
|
||||||
h5ai = new H5ai(h5aiOptions, h5aiLangs),
|
h5ai = new Objects.H5ai(h5aiOptions, h5aiLangs);
|
||||||
extended = new Extended(pathCache, h5ai),
|
extended = new Objects.Extended(pathCache, h5ai);
|
||||||
tree = new Tree(pathCache, h5ai);
|
tree = new Objects.Tree(pathCache, h5ai);
|
||||||
|
|
||||||
$.h5ai = {
|
$.h5ai = {
|
||||||
click: $.proxy(h5ai.pathClick, h5ai)
|
click: $.proxy(h5ai.pathClick, h5ai)
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
|
/*global jQuery, h5aiOptions, h5aiLangs*/
|
||||||
|
|
||||||
|
// @include "inc/jquery.scrollpanel.js"
|
||||||
|
// @include "inc/jquery.utils.js"
|
||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
"use strict";
|
"use strict";
|
||||||
/*global jQuery, h5aiOptions, h5aiLangs*/
|
|
||||||
|
|
||||||
// @include "inc/jquery.mousewheel.min.js"
|
var Objects = {},
|
||||||
// @include "inc/jquery.scrollpanel.js"
|
h5ai;
|
||||||
// @include "inc/jquery.utils.js"
|
|
||||||
// @include "inc/jquery.fracs.js"
|
|
||||||
// @include "inc/h5ai.js"
|
// @include "inc/h5ai.js"
|
||||||
|
|
||||||
var h5ai = new H5ai(h5aiOptions, h5aiLangs);
|
h5ai = new Objects.H5ai(h5aiOptions, h5aiLangs);
|
||||||
|
|
||||||
$.h5ai = {
|
$.h5ai = {
|
||||||
click: $.proxy(h5ai.pathClick, h5ai)
|
click: $.proxy(h5ai.pathClick, h5ai)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue