").attr("id", "status").html(message).css({ top: -300 }));
var status$ = $("#status");
$.fn.centerStatus = function () {
this.position({
my: "center top",
at: "center top",
of: $(".page-container"),
offset: "0 10"
});
$(this).css("top", "10px");
return this;
};
status$
.fadeIn(0, function () {
status$.centerStatus();
})
.centerStatus()
.delay(delayMessage ? delayMessage : 6000)
.fadeOut();
};
OculusStatus.SetIndefinite = function (message) {
OculusStatus.Set(message, 999999999);
};
OculusStatus.RemoveStatus = function () {
$("#status").clearQueue().remove();
};
OculusStatus.PositiveFeedback = function (message) {
message = message ? ($.isArray(message) ? message.join(", ") : message) : "Saved";
$(".module-header").after($("
").addClass("feedback-positive").append($("
").addClass("message").append($("").html(message))));
};
return OculusStatus;
}());
var OculusUtils = (function () {
function OculusUtils() {
}
OculusUtils.GetDate = function (date) {
var newDate = new Date();
if (OculusUtils.IsDate(date)) {
newDate = new Date(date);
if (newDate.getFullYear() < 1980) {
newDate.setFullYear(newDate.getFullYear() + 100);
}
}
return moment(newDate).format("M/D/YY");
};
OculusUtils.GetDateTime = function (date) {
return moment(date || new Date()).format("MM/DD/YY h:mm a").toUpperCase();
};
OculusUtils.IsDate = function (value) {
if (!value) {
return false;
}
if (value.getMonth) {
return true;
}
var bits = value.split("/");
bits = bits.length === 3 ? bits : value.split("-");
var d = new Date(bits[2], bits[0] - 1, bits[1]);
return d.getMonth() + 1 === bits[0].toString().toNumber() && d.getDate() === bits[1].toString().toNumber();
};
OculusUtils.IsStandardDateFormat = function (value) {
if (!value || !value.length) {
return false;
}
var re = /^\d{1,2}([-\/.])\d{1,2}\1((\d{4})|(\d{2}))$/;
return value.match(re);
};
OculusUtils.OnEscKey = function (fn) {
fn = fn || (function () {
});
$(document).keyup(function (e) {
if (e.keyCode === 27) {
fn();
}
});
};
OculusUtils.OnEnterKey = function (fn) {
fn = fn || (function () {
});
$(document).keyup(function (e) {
if (e.keyCode === 13) {
fn();
}
});
};
OculusUtils.IsLeapYear = function (year) {
return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
};
OculusUtils.DaysInMonth = function (month, year) {
return 32 - new Date(year, month, 32).getDate();
};
OculusUtils.IsElementInViewport = function (el$) {
if (!el$.length) {
return false;
}
if (typeof jQuery === "function" && el$ instanceof jQuery) {
el$ = el$[0];
}
var rect = el$.getBoundingClientRect();
return (rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth));
};
OculusUtils.Guid = function () {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c === "x" ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
OculusUtils.ShortID = function () {
return Math.random().toString(36).slice(-6);
};
OculusUtils.WaitFor = function (condition, callback) {
var _this = this;
if (condition()) {
callback();
return;
}
setTimeout(function () {
_this.WaitFor(condition, callback);
}, 50);
};
OculusUtils.WaitForViewModel = function (jQuerySelector, fn) {
var viewModel = null;
var viewModelExists = function () {
var ele$ = jQuerySelector instanceof jQuery ? jQuerySelector : $(jQuerySelector);
if (!ele$.length) {
return false;
}
viewModel = ko.dataFor(ele$[0]);
return !!viewModel;
};
setTimeout(function () { return OculusUtils.WaitFor(viewModelExists, function () { return fn(viewModel); }); }, 50);
};
OculusUtils.GetQueryString = function (name) {
name = name.replace(/\[/, "\\[").replace(/]/, "\\]");
var regex = new RegExp("[?&]".concat(name, "=([^]*)"));
var results = regex.exec(window.location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
};
OculusUtils.GetQueryStringParameterByName = function (name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp("[?&]".concat(name, "(=([^]*)|&|#|$)")), results = regex.exec(url);
if (!results) {
return null;
}
if (!results[2]) {
return "";
}
return decodeURIComponent(results[2].replace(/\+/g, " "));
};
OculusUtils.SmoothScrollToTop = function (ele$) {
ele$ = ele$ instanceof jQuery ? ele$ : $("html, body");
ele$.stop().animate({ scrollTop: 0 }, 500);
};
OculusUtils.Copy = function (value, message) {
var input$ = $("")
.css({
left: -100,
opacity: "0",
position: "absolute",
top: -100,
})
.val(value);
$("body").append(input$);
input$[0]["select"]();
document["execCommand"]("copy");
OculusStatus.Set(message ? message : "Copied");
setTimeout(function () { return input$.remove(); });
return false;
};
OculusUtils.BindViewModelAndRemovePageLoader = function (viewModel, pageId, delay) {
var page$ = $("#".concat(pageId));
var loading$ = $("#".concat(pageId, "-loading"));
ko.applyBindings(viewModel, page$[0]);
if (loading$.length) {
setTimeout(function () {
$("#".concat(pageId, "-loading")).remove();
page$.removeClass("hide");
}, delay || 300);
}
else {
page$.removeClass("hide");
}
};
OculusUtils.SelectTab = function (tabID, index) {
$("".concat(tabID, " li:eq(").concat(index - 1, ") a")).tab("show");
};
OculusUtils.MutuallyExclusiveObservable = function () {
var observables = [];
for (var _i = 0; _i < arguments.length; _i++) {
observables[_i] = arguments[_i];
}
if (!observables.length || observables.length < 2) {
throw "MutuallyExclusiveObservable requires at least 2 arguments";
}
var args = Array.prototype.slice.call(observables);
var makeExclusive = function (field, allFields) {
field.subscribe(function (value) {
if (!value) {
return;
}
for (var n = 0; n < allFields.length; n++) {
if (field !== args[n]) {
allFields[n](false);
}
}
});
};
for (var i = 0; i < args.length; i++) {
makeExclusive(args[i], args);
}
};
OculusUtils.EnableTextareaTabs = function (jQuerySelector) {
var jq$ = (jQuerySelector instanceof jQuery ? jQuerySelector : $(jQuerySelector));
$(document).on("keydown", jq$, function (e) {
var keyCode = e.keyCode || e.which;
if (keyCode === $.ui.keyCode.TAB) {
e.preventDefault();
document.execCommand("insertText", false, " ".repeat(4));
}
});
};
OculusUtils.MarkdownParse = function (val) {
var converter = new window["showdown"].Converter();
return converter.makeHtml(val || "");
};
OculusUtils.HideBootstrapDropdowns = function () { return $("body").click(); };
OculusUtils.GetCurrentUserAlerts = function (fn) { return OculusUtils.WaitForViewModel("#left-nav", function (vm) { return fn(vm.UserAlerts()); }); };
return OculusUtils;
}());