Skip to content

Commit

Permalink
Version 46:
Browse files Browse the repository at this point in the history
* Added "SettingChanged" custom event.
* Minor bugfixes.
  • Loading branch information
bp2008 committed Jul 18, 2018
1 parent b6d7961 commit 63a7ddc
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 35 deletions.
2 changes: 1 addition & 1 deletion ui3.htm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
};
</script>
<script type="text/javascript">
var ui_version = "45";
var ui_version = "46";
var bi_version = "%%VERSION%%";
var combined_version = ui_version + "-" + bi_version;
//if (!!navigator.userAgent.match(/ Android /))
Expand Down
124 changes: 90 additions & 34 deletions ui3/ui3.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ var togglableUIFeatures =
// High priority notes ////////////////////////////////////////
///////////////////////////////////////////////////////////////

// TODO: Properly handle playback and stream reloads of clips that are still being recorded.
// * non-BVR should refuse to open
// * when we get new clip length data for the playing clip, handle it correctly. don't just throw out the new data.
// * reloading the stream (change playback speed) should not cause the current position to change suddenly.
// * don't forget jpeg streams

///////////////////////////////////////////////////////////////
// Low priority notes /////////////////////////////////////////
///////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -464,7 +470,7 @@ var HTML5DelayCompensationOptions = {
Strong: "Strong"
}
var settings = null;
var settingsCategoryList = ["General Settings", "Video Player", "Clip / Alert Icons", "Event-Triggered Icons", "Event-Triggered Sounds", "Hotkeys", "Camera Labels", "Digital Zoom", "Extra"];
var settingsCategoryList = ["General Settings", "Video Player", "Clip / Alert Icons", "Event-Triggered Icons", "Event-Triggered Sounds", "Hotkeys", "Camera Labels", "Digital Zoom", "Extra"]; // Create corresponding "ui3_cps_uiSettings_category_" default when adding a category here.
var defaultSettings =
[
{
Expand Down Expand Up @@ -611,6 +617,10 @@ var defaultSettings =
key: "ui3_cps_uiSettings_category_General_Settings_visible"
, value: "1"
}
, {
key: "ui3_cps_uiSettings_category_Video_Player_visible"
, value: "1"
}
, {
key: "ui3_cps_uiSettings_category_Clip___Alert_Icons_visible"
, value: "1"
Expand All @@ -631,6 +641,10 @@ var defaultSettings =
key: "ui3_cps_uiSettings_category_Camera_Labels_visible"
, value: "1"
}
, {
key: "ui3_cps_uiSettings_category_Digital_Zoom_visible"
, value: "1"
}
, {
key: "ui3_cps_uiSettings_category_Extra_visible"
, value: "1"
Expand Down Expand Up @@ -1601,7 +1615,7 @@ function OverrideDefaultSetting(key, value, IncludeInOptionsWindow, AlwaysReload
function LoadDefaultSettings()
{
if (settings == null) // This null check allows local overrides to replace the settings object.
settings = GetLocalStorageWrapper();
settings = SetupStorageSniffing(GetLocalStorageWrapper());
for (var i = 0; i < defaultSettings.length; i++)
{
if (settings.getItem(defaultSettings[i].key) == null
Expand Down Expand Up @@ -1661,7 +1675,7 @@ function GetLocalStorageWrapper()
else
return GetLocalStorage();
}
return GetDummyLocalStorage()
return GetDummyLocalStorage();
}
function GetRemoteServerLocalStorage()
{
Expand All @@ -1677,29 +1691,13 @@ function GetRemoteServerLocalStorage()
{
return (myLocalStorage[serverNamePrefix + key] = value);
};
for (var i = 0; i < defaultSettings.length; i++)
{
var tmp = function (key)
{
Object.defineProperty(wrappedStorage, key,
{
get: function ()
{
return wrappedStorage.getItem(key);
},
set: function (value)
{
return wrappedStorage.setItem(key, value);
}
});
}(defaultSettings[i].key);
}
AttachDefaultSettingsProperties(wrappedStorage);
return wrappedStorage;
}
var localStorageDummy = null;
function GetDummyLocalStorage()
{
if (localStorageDummy == null)
if (localStorageDummy === null)
{
var dummy = new Object();
dummy.getItem = function (key)
Expand All @@ -1710,10 +1708,65 @@ function GetDummyLocalStorage()
{
return (dummy[key] = value);
};
AttachDefaultSettingsProperties(dummy);
localStorageDummy = dummy;
}
return localStorageDummy;
}
function SetupStorageSniffing(storageObj)
{
if (typeof Object.defineProperty === "function")
{
var isInvokingChangedEvent = {};
var storageWrapper = new Object();
storageWrapper.getItem = function (key)
{
return storageObj.getItem(key);
};
storageWrapper.setItem = function (key, value)
{
if (isInvokingChangedEvent[key])
storageObj.setItem(key, value);
else
{
var oldValue = storageObj.getItem(key);
storageObj.setItem(key, value);
isInvokingChangedEvent[key] = true;
BI_CustomEvent.Invoke("SettingChanged", { key: key, value: value, oldValue: oldValue });
isInvokingChangedEvent[key] = false;
}
};
AttachDefaultSettingsProperties(storageWrapper);
return storageWrapper;
}
else
{
console.log('The custom event "SettingChanged" requires Object.defineProperty which is not available.');
return storageObj;
}
}
function AttachDefaultSettingsProperties(storageWrapper)
{
if (typeof Object.defineProperty !== "function")
return;
for (var i = 0; i < defaultSettings.length; i++)
{
var tmp = function (key)
{
Object.defineProperty(storageWrapper, key,
{
get: function ()
{
return storageWrapper.getItem(key);
},
set: function (value)
{
return storageWrapper.setItem(key, value);
}
});
}(defaultSettings[i].key);
}
}
///////////////////////////////////////////////////////////////
// UI Loading /////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1964,7 +2017,7 @@ function SetupCollapsibleTriggers()
{
var $ele = $(ele);
var collapsibleid = $ele.attr('collapsibleid');
if (collapsibleid && collapsibleid.length > 0 && settings["ui3_collapsible_" + collapsibleid] != "1")
if (collapsibleid && collapsibleid.length > 0 && settings.getItem("ui3_collapsible_" + collapsibleid) != "1")
$ele.next().hide();
if ($ele.next().is(":visible"))
$ele.removeClass("collapsed");
Expand All @@ -1982,7 +2035,7 @@ function SetupCollapsibleTriggers()
else
$ele.addClass("collapsed");
if (collapsibleid && collapsibleid.length > 0)
settings["ui3_collapsible_" + collapsibleid] = vis ? "1" : "0";
settings.setItem("ui3_collapsible_" + collapsibleid, vis ? "1" : "0");
if ($ele.hasClass("serverStatusLabel") || $ele.attr("id") == "recordingsFilterByHeading")
resized();
}
Expand Down Expand Up @@ -13246,6 +13299,7 @@ function GenericQualityHelper()
var u = upgradeMap[profileData[i].name];
if (u)
{
profileData[i].dv = 2;
for (var key in u)
profileData[i][key] = u[key];
upgradeMade = true;
Expand Down Expand Up @@ -16745,7 +16799,7 @@ function BI_Hotkeys()
var s = hotkeysBeingRepeated[i];
if (s.allowRepeatKey)
{
var val = settings[s.key];
var val = settings.getItem(s.key);
if (!val)
continue;
var parts = val.split("|");
Expand Down Expand Up @@ -16773,7 +16827,7 @@ function BI_Hotkeys()
{
if (typeof s.actionDown == "function")
{
var val = settings[s.key];
var val = settings.getItem(s.key);
if (!val)
continue;
var parts = val.split("|");
Expand Down Expand Up @@ -18825,7 +18879,7 @@ function DragAndDropHelper($list, onItemMoved)
ClearDragTimeout();
if (drag)
{
if (success)
if (success && moved)
{
$blank.after($drag);
onItemMoved($drag);
Expand Down Expand Up @@ -19214,15 +19268,15 @@ function UISettingsPanel()
$row.addClass('everyOther');
var formFields = {
inputType: s.inputType
, value: settings[s.key]
, value: settings.getItem(s.key)
, label: s.label
, tag: s
};
if (s.hotkey)
{
var $input = $('<input type="text" />');
AddKeydownEventToElement(HandleHotkeyChange, s, $input);
var val = settings[s.key];
var val = settings.getItem(s.key);
if (!val)
val = "";
var parts = val.split("|");
Expand Down Expand Up @@ -19353,7 +19407,7 @@ function UISettingsPanel()
var s = defaultSettings[i];
if (s.category != category || !s.key)
continue;
var value = settings[s.key];
var value = settings.getItem(s.key);
if (typeof value == "string")
value = JavaScriptStringEncode(value, true);
else
Expand All @@ -19374,7 +19428,7 @@ function UISettingsPanel()
var key = s.key;
if (!key || key === "bi_rememberMe" || key === "bi_username" || key === "bi_password")
continue; // Don't write these to the file!
var value = settings[key];
var value = settings.getItem(key);
sb.Append('OverrideDefaultSetting(');
sb.Append((JavaScriptStringEncode(key, true) + ",").padRight(max_key, ' '));
sb.Append(' ')
Expand Down Expand Up @@ -19443,19 +19497,19 @@ function UISettingsPanel()
}
var CheckboxChanged = function (s, checked)
{
settings[s.key] = checked ? "1" : "0";
settings.setItem(s.key, checked ? "1" : "0");
CallOnChangeCallback(s);
}
var SelectChanged = function (e, s, $select)
{
var selectedValue = $select.val();
if (s.options.indexOf(selectedValue) != -1)
settings[s.key] = selectedValue;
settings.setItem(s.key, selectedValue);
CallOnChangeCallback(s);
}
var NumberChanged = function (e, s, $input)
{
settings[s.key] = parseFloat($input.val());
settings.setItem(s.key, parseFloat($input.val()));
CallOnChangeCallback(s);
}
var HandleHotkeyChange = function (e, s, $input)
Expand Down Expand Up @@ -19490,7 +19544,7 @@ function UISettingsPanel()
{
try
{
s.onChange(settings[s.key]);
s.onChange(settings.getItem(s.key));
}
catch (ex)
{
Expand Down Expand Up @@ -20107,6 +20161,8 @@ function Clamp(i, min, max)
return min;
if (i > max)
return max;
if (isNaN(i))
return min;
return i;
}
function getDistanceBetweenPointAndElementCenter(x, y, $ele)
Expand Down

0 comments on commit 63a7ddc

Please sign in to comment.