Quantcast

Converted all xml files to use the direct function call syntax for script handlers

Kevin Lyles [01-25-14 - 18:43]
Converted all xml files to use the direct function call syntax for script handlers
Filename
HiddenTooltip.xml
WeightsWatcher.xml
config-calculation.lua
config-calculation.xml
config-display.lua
config-display.xml
config-enchants.lua
config-enchants.xml
config-gems.lua
config-gems.xml
config.lua
config.xml
init.lua
weights.lua
weights.xml
widgets.lua
widgets.xml
diff --git a/HiddenTooltip.xml b/HiddenTooltip.xml
index e3b2f95..3ceb503 100644
--- a/HiddenTooltip.xml
+++ b/HiddenTooltip.xml
@@ -2,9 +2,7 @@
 		xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
 	<GameTooltip name="WeightsWatcherHiddenTooltip" inherits="GameTooltipTemplate">
 		<Scripts>
-			<Onload>
-				self:SetOwner(WorldFrame, "ANCHOR_NONE")
-			</Onload>
+			<Onload function="ww_setHiddenTooltipOwner"/>
 		</Scripts>
 	</GameTooltip>
 </Ui>
diff --git a/WeightsWatcher.xml b/WeightsWatcher.xml
index a69305c..94c2f70 100644
--- a/WeightsWatcher.xml
+++ b/WeightsWatcher.xml
@@ -1,16 +1,10 @@
 <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 		xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
+	<Script file="init.lua"/>
 	<Frame name="WeightsWatcher" hidden="true">
 		<Scripts>
-			<OnLoad>
-				self:RegisterEvent("ADDON_LOADED")
-			</OnLoad>
-			<OnEvent>
-				if event == "ADDON_LOADED" and ... == "WeightsWatcher" then
-					self:OnInitialize()
-					self:UnregisterEvent("ADDON_LOADED")
-				end
-			</OnEvent>
+			<OnLoad function="ww_load"/>
+			<OnEvent function="ww_event"/>
 		</Scripts>
 	</Frame>
 </Ui>
diff --git a/config-calculation.lua b/config-calculation.lua
new file mode 100644
index 0000000..34b41df
--- /dev/null
+++ b/config-calculation.lua
@@ -0,0 +1,50 @@
+function ww_uptimeRatioTextChanged(self)
+	local text = self:GetText()
+	if self:GetNumber() ~= 0 or text:match("^[0.]+$") or text == "" then
+		self.number = text
+		ww_vars.options.calculation.useEffectUptimeRatio = self:GetNumber() / 100
+		ww_weightCache = setmetatable({}, ww_weightCacheMetatable)
+		ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+	end
+end
+
+function ww_uptimeRatioOnChar(self, text)
+	if ww_validateNumber(text, self:GetText()) then
+		self.number = self:GetText()
+		ww_vars.options.calculation.useEffectUptimeRatio = self:GetNumber() / 100
+		ww_weightCache = setmetatable({}, ww_weightCacheMetatable)
+		ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+	else
+		local cursorPosition = self:GetCursorPosition() - 1
+		self:SetText(self.number)
+		self:SetCursorPosition(cursorPosition)
+	end
+end
+
+function ww_uptimeRatioOnLoad(self)
+	if ww_cooldownUseEffects then
+		self.label:SetText(ww_localization["IDEAL_USE_UPTIME"])
+	else
+		self:SetParent(nil)
+		self:Hide()
+	end
+end
+
+local function default()
+	ww_vars.options.calculation = ww_deepTableCopy(ww_defaultVars.options.calculation)
+	ww_weightCache = setmetatable({}, ww_weightCacheMetatable)
+	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+end
+
+function ww_configCalculationOnLoad(self)
+	local function refresh()
+		self.useEffectUptimeRatio.ratio:SetText(ww_vars.options.calculation.useEffectUptimeRatio * 100)
+	end
+
+	self.title:SetText(ww_localization["CALC_OPTS"])
+	self.name = ww_localization["CALC_NAME"]
+	self.parent = "WeightsWatcher"
+	self.default = default
+	self.refresh = refresh
+	InterfaceOptions_AddCategory(self)
+end
diff --git a/config-calculation.xml b/config-calculation.xml
index 0a7f30b..1925da6 100644
--- a/config-calculation.xml
+++ b/config-calculation.xml
@@ -1,5 +1,6 @@
 <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 		xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
+	<Script file="config-calculation.lua"/>
 	<Frame name="ww_configCalculationOptions" inherits="ww_borderedFrame" hidden="true">
 		<Anchors>
 			<Anchor point="TOPLEFT"/>
@@ -70,63 +71,20 @@
 							</Anchors>
 						</FontString>
 						<Scripts>
-							<OnLoad>
-								self:SetTextInsets(5, 5, 0, 0)
-							</OnLoad>
-							<OnTextChanged>
-								local text = self:GetText()
-								if self:GetNumber() ~= 0 or text:match("^[0.]+$") or text == "" then
-									self.number = text
-									ww_vars.options.calculation.useEffectUptimeRatio = self:GetNumber() / 100
-									ww_weightCache = setmetatable({}, ww_weightCacheMetatable)
-									ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-								end
-							</OnTextChanged>
-							<OnChar>
-								if ww_validateNumber(text, self:GetText()) then
-									self.number = self:GetText()
-									ww_vars.options.calculation.useEffectUptimeRatio = self:GetNumber() / 100
-									ww_weightCache = setmetatable({}, ww_weightCacheMetatable)
-									ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-								else
-									local cursorPosition = self:GetCursorPosition() - 1
-									self:SetText(self.number)
-									self:SetCursorPosition(cursorPosition)
-								end
-							</OnChar>
-							<OnEscapePressed>
-								self:ClearFocus()
-							</OnEscapePressed>
+							<OnLoad function="ww_editBoxTextInsets"/>
+							<OnTextChanged function="ww_uptimeRatioTextChanged"/>
+							<OnChar function="ww_uptimeRatioOnChar"/>
+							<OnEscapePressed function="ww_clearFocus"/>
 						</Scripts>
 					</EditBox>
 				</Frames>
 				<Scripts>
-					<OnLoad>
-						if ww_cooldownUseEffects then
-							self.label:SetText(ww_localization["IDEAL_USE_UPTIME"])
-						else
-							self:SetParent(nil)
-							self:Hide()
-						end
-					</OnLoad>
+					<OnLoad function="ww_uptimeRatioOnLoad"/>
 				</Scripts>
 			</Frame>
 		</Frames>
 		<Scripts>
-			<OnLoad>
-				self.title:SetText(ww_localization["CALC_OPTS"])
-				self.name = ww_localization["CALC_NAME"]
-				self.parent = "WeightsWatcher"
-				self.default = function(...)
-						ww_vars.options.calculation = ww_deepTableCopy(ww_defaultVars.options.calculation)
-						ww_weightCache = setmetatable({}, ww_weightCacheMetatable)
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					end
-				self.refresh = function(...)
-						self.useEffectUptimeRatio.ratio:SetText(ww_vars.options.calculation.useEffectUptimeRatio * 100)
-					end
-				InterfaceOptions_AddCategory(self)
-			</OnLoad>
+			<OnLoad function="ww_configCalculationOnLoad"/>
 		</Scripts>
 	</Frame>
 </Ui>
diff --git a/config-display.lua b/config-display.lua
new file mode 100644
index 0000000..8a37e87
--- /dev/null
+++ b/config-display.lua
@@ -0,0 +1,145 @@
+function ww_configShowWeights(self)
+	self.label:SetText(ww_localization["SHOW_WTS"])
+	self.dropdown:SetText("showWeights")
+end
+
+function ww_configShowIdealWeights(self)
+	self.label:SetText(ww_localization["SHOW_IDEAL_WTS"])
+	self.dropdown:SetText("showIdealWeights")
+end
+
+function ww_configShowEnhancements(self)
+	self.label:SetText(ww_localization["SHOW_IDEAL_ENHANCEMENTS"])
+	self.dropdown:SetText("showEnhancements")
+end
+
+function ww_configShowAlternateEnhancements(self)
+	self.label:SetText(ww_localization["SHOW_ALT_IDEAL_ENHANCEMENTS"])
+	self.dropdown:SetText("showAlternateEnhancements")
+end
+
+function ww_configShowEnhancementStats(self)
+	self.label:SetText(ww_localization["SHOW_IDEAL_ENHANCEMENT_STATS"])
+	self.dropdown:SetText("showEnhancementStats")
+end
+
+function ww_configShowDebugInfo(self)
+	self.label:SetText(ww_localization["SHOW_DEBUG"])
+	self.dropdown:SetText("showDebugInfo")
+end
+
+function ww_configShowEnhancementsWhenDropdownLoad(self)
+	UIDropDownMenu_Initialize(self, ww_ShowEnhancementsWhenDropDownInitialize)
+	UIDropDownMenu_SetSelectedValue(self, ww_vars.options.tooltip.showEnhancementsWhen)
+end
+
+function ww_configShowEnhancementsWhenLabel(self)
+	self.label:SetText(ww_localization["SHOW_ENHANCEMENTS_WHEN"])
+end
+
+function ww_configHideTooltipHintsClick(self)
+	if self:GetChecked() then
+		ww_vars.options.tooltip.hideHints = true
+	else
+		ww_vars.options.tooltip.hideHints = false
+	end
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.tooltip.hideHints
+end
+
+function ww_configHideTooltipHintsLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["HIDE_HINTS_TT"]
+	self:SetText(ww_localization["HIDE_HINTS"])
+end
+
+function ww_configShowClassNamesDropdownLoad(self)
+	UIDropDownMenu_Initialize(self, ww_ShowClassNameDropDownInitialize)
+	UIDropDownMenu_SetSelectedValue(self, ww_vars.options.tooltip.showClassNames)
+end
+
+function ww_configShowClassNamesLabel(self)
+	self.label:SetText(ww_localization["SHOW_CLASS"])
+end
+
+function ww_configShowZeroScoresClick(self)
+	if self:GetChecked() then
+		ww_vars.options.tooltip.showZeroScores = true
+	else
+		ww_vars.options.tooltip.showZeroScores = false
+	end
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.tooltip.showZeroScores
+end
+
+function ww_configShowZeroScoresLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["SHOW_ZEROES_TT"]
+	self:SetText(ww_localization["SHOW_ZEROES"])
+end
+
+function ww_configShowDifferencesClick(self)
+	if self:GetChecked() then
+		ww_vars.options.tooltip.showDifferences = true
+	else
+		ww_vars.options.tooltip.showDifferences = false
+	end
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.tooltip.showDifferences
+end
+
+function ww_configShowDifferencesLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["SHOW_DIFF_TT"]
+	self:SetText(ww_localization["SHOW_DIFF"])
+end
+
+function ww_configNormalizeWeightsClick(self)
+	if self:GetChecked() then
+		ww_vars.options.tooltip.normalizeWeights = true
+	else
+		ww_vars.options.tooltip.normalizeWeights = false
+	end
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.tooltip.normalizeWeights
+end
+
+function ww_configNormalizeWeightsLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["NORMALIZE_TT"]
+	self:SetText(ww_localization["NORMALIZE"])
+end
+
+local function default()
+	ww_vars.options.tooltip = ww_defaultVars.options.tooltip
+	ww_weightCache = setmetatable({}, ww_weightCacheMetatable)
+	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+end
+
+function ww_configDisplayLoad(self)
+	local checkBoxes = {
+		hideHints = self.hideTooltipHints,
+		showZeroScores = self.showZeroScores,
+		showDifferences = self.showDifference,
+		normalizeWeights = self.normalizeWeights,
+	}
+
+	local function refresh()
+		ww_refreshCheckBoxes(checkBoxes)
+	end
+
+	self.header:SetText(ww_localization["DISPLAY_OPTS"])
+	self.name = ww_localization["DISPLAY_NAME"]
+	self.parent = "WeightsWatcher"
+	self.default = default
+	self.refresh = refresh
+	InterfaceOptions_AddCategory(self)
+end
diff --git a/config-display.xml b/config-display.xml
index f441719..626d8ab 100644
--- a/config-display.xml
+++ b/config-display.xml
@@ -1,5 +1,6 @@
 <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 		xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
+	<Script file="config-display.lua"/>
 	<Frame name="ww_configDisplayOptions" inherits="ww_borderedFrame" hidden="true">
 		<Anchors>
 			<Anchor point="TOPLEFT"/>
@@ -31,10 +32,7 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnLoad>
-						self.label:SetText(ww_localization["SHOW_WTS"])
-						self.dropdown:SetText("showWeights")
-					</OnLoad>
+					<OnLoad function="ww_configShowWeights"/>
 				</Scripts>
 			</Frame>
 			<Frame name="$parentShowIdealWeights" parentKey="showIdealWeights" inherits="ww_modifierKeyDropDown">
@@ -46,10 +44,7 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnLoad>
-						self.label:SetText(ww_localization["SHOW_IDEAL_WTS"])
-						self.dropdown:SetText("showIdealWeights")
-					</OnLoad>
+					<OnLoad function="ww_configShowIdealWeights"/>
 				</Scripts>
 			</Frame>
 			<Frame name="$parentShowEnhancements" parentKey="showEnhancements" inherits="ww_modifierKeyDropDown">
@@ -61,10 +56,7 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnLoad>
-						self.label:SetText(ww_localization["SHOW_IDEAL_ENHANCEMENTS"])
-						self.dropdown:SetText("showEnhancements")
-					</OnLoad>
+					<OnLoad function="ww_configShowEnhancements"/>
 				</Scripts>
 			</Frame>
 			<Frame name="$parentShowAlternateEnhancements" parentKey="showAlternateEnhancements" inherits="ww_modifierKeyDropDown">
@@ -76,10 +68,7 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnLoad>
-						self.label:SetText(ww_localization["SHOW_ALT_IDEAL_ENHANCEMENTS"])
-						self.dropdown:SetText("showAlternateEnhancements")
-					</OnLoad>
+					<OnLoad function="ww_configShowAlternateEnhancements"/>
 				</Scripts>
 			</Frame>
 			<Frame name="$parentShowEnhancementStats" parentKey="showEnhancementStats" inherits="ww_modifierKeyDropDown">
@@ -87,10 +76,7 @@
 					<Anchor point="TOPLEFT" relativePoint="BOTTOMLEFT" relativeTo="$parentShowAlternateEnhancements"/>
 				</Anchors>
 				<Scripts>
-					<OnLoad>
-						self.label:SetText(ww_localization["SHOW_IDEAL_ENHANCEMENT_STATS"])
-						self.dropdown:SetText("showEnhancementStats")
-					</OnLoad>
+					<OnLoad function="ww_configShowEnhancementStats"/>
 				</Scripts>
 			</Frame>
 			<Frame name="$parentShowDebugInfo" parentKey="showDebugInfo" inherits="ww_modifierKeyDropDown">
@@ -103,10 +89,7 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnLoad>
-						self.label:SetText(ww_localization["SHOW_DEBUG"])
-						self.dropdown:SetText("showDebugInfo")
-					</OnLoad>
+					<OnLoad function="ww_configShowDebugInfo"/>
 				</Scripts>
 			</Frame>
 			<Frame name="$parentShowEnhancementsWhen" parentKey="showEnhancementsWhen" inherits="ww_labeledElement">
@@ -131,20 +114,13 @@
 							</Anchor>
 						</Anchors>
 						<Scripts>
-							<OnLoad>
-								UIDropDownMenu_JustifyText(self, "LEFT")
-							</OnLoad>
-							<OnShow>
-								UIDropDownMenu_Initialize(self, ww_ShowEnhancementsWhenDropDownInitialize)
-								UIDropDownMenu_SetSelectedValue(self, ww_vars.options.tooltip.showEnhancementsWhen)
-							</OnShow>
+							<OnLoad function="ww_leftJustifyDropDownText"/>
+							<OnShow function="ww_configShowEnhancementsWhenDropdownLoad"/>
 						</Scripts>
 					</Button>
 				</Frames>
 				<Scripts>
-					<OnLoad>
-						self.label:SetText(ww_localization["SHOW_ENHANCEMENTS_WHEN"])
-					</OnLoad>
+					<OnLoad function="ww_configShowEnhancementsWhenLabel"/>
 				</Scripts>
 			</Frame>
 			<CheckButton name="$parentHideTooltipHints" parentKey="hideTooltipHints" inherits="ww_checkButton">
@@ -152,18 +128,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentShowEnhancementsWhen"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.tooltip.hideHints = true
-						else
-							ww_vars.options.tooltip.hideHints = false
-						end
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.tooltip.hideHints end
-						self.ttText = ww_localization["HIDE_HINTS_TT"]
-						self:SetText(ww_localization["HIDE_HINTS"])
-					</OnLoad>
+					<OnClick function="ww_configHideTooltipHintsClick"/>
+					<OnLoad function="ww_configHideTooltipHintsLoad"/>
 				</Scripts>
 			</CheckButton>
 			<Frame name="$parentShowClassNames" parentKey="showClassNames" inherits="ww_labeledElement">
@@ -188,20 +154,13 @@
 							</Anchor>
 						</Anchors>
 						<Scripts>
-							<OnLoad>
-								UIDropDownMenu_JustifyText(self, "LEFT")
-							</OnLoad>
-							<OnShow>
-								UIDropDownMenu_Initialize(self, ww_ShowClassNameDropDownInitialize)
-								UIDropDownMenu_SetSelectedValue(self, ww_vars.options.tooltip.showClassNames)
-							</OnShow>
+							<OnLoad function="ww_leftJustifyDropDownText"/>
+							<OnShow function="ww_configShowClassNamesDropdownLoad"/>
 						</Scripts>
 					</Button>
 				</Frames>
 				<Scripts>
-					<OnLoad>
-						self.label:SetText(ww_localization["SHOW_CLASS"])
-					</OnLoad>
+					<OnLoad function="ww_configShowClassNamesLabel"/>
 				</Scripts>
 			</Frame>
 			<CheckButton name="$parentShowZeroScores" parentKey="showZeroScores" inherits="ww_checkButton">
@@ -209,18 +168,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentShowClassNames"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.tooltip.showZeroScores = true
-						else
-							ww_vars.options.tooltip.showZeroScores = false
-						end
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.tooltip.showZeroScores end
-						self.ttText = ww_localization["SHOW_ZEROES_TT"]
-						self:SetText(ww_localization["SHOW_ZEROES"])
-					</OnLoad>
+					<OnClick function="ww_configShowZeroScoresClick"/>
+					<OnLoad function="ww_configShowZeroScoresLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentShowDifference" parentKey="showDifference" inherits="ww_checkButton">
@@ -228,18 +177,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentShowZeroScores"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.tooltip.showDifferences = true
-						else
-							ww_vars.options.tooltip.showDifferences = false
-						end
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.tooltip.showDifferences end
-						self.ttText = ww_localization["SHOW_DIFF_TT"]
-						self:SetText(ww_localization["SHOW_DIFF"])
-					</OnLoad>
+					<OnClick function="ww_configShowDifferencesClick"/>
+					<OnLoad function="ww_configShowDifferencesLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentNormalizeWeights" parentKey="normalizeWeights" inherits="ww_checkButton">
@@ -247,58 +186,13 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentShowDifference"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.tooltip.normalizeWeights = true
-						else
-							ww_vars.options.tooltip.normalizeWeights = false
-						end
-						ww_weightCache = setmetatable({}, ww_weightCacheMetatable)
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.tooltip.normalizeWeights end
-						self.ttText = ww_localization["NORMALIZE_TT"]
-						self:SetText(ww_localization["NORMALIZE"])
-					</OnLoad>
+					<OnClick function="ww_configNormalizeWeightsClick"/>
+					<OnLoad function="ww_configNormalizeWeightsLoad"/>
 				</Scripts>
 			</CheckButton>
 		</Frames>
 		<Scripts>
-			<OnLoad>
-				self.header:SetText(ww_localization["DISPLAY_OPTS"])
-				self.name = ww_localization["DISPLAY_NAME"]
-				self.parent = "WeightsWatcher"
-				self.default = function()
-						ww_vars.options.tooltip = ww_defaultVars.options.tooltip
-						ww_weightCache = setmetatable({}, ww_weightCacheMetatable)
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					end
-				local checkBoxes = {
-					"hideHints",
-					"showZeroScores",
-					"showDifferences",
-					"normalizeWeights",
-					hideHints = self.hideTooltipHints,
-					showZeroScores = self.showZeroScores,
-					showDifferences = self.showDifference,
-					normalizeWeights = self.normalizeWeights,
-				}
-				self.refresh = function()
-						for _, option in ipairs(checkBoxes) do
-							local checkBox = checkBoxes[option]
-							checkBox:SetChecked(checkBox.shouldBeChecked())
-							if checkBox.shouldBeEnabled then
-								if checkBox.shouldBeEnabled() then
-									checkBox:Enable()
-								else
-									checkBox:Disable()
-								end
-							end
-						end
-					end
-				InterfaceOptions_AddCategory(self)
-			</OnLoad>
+			<OnLoad function="ww_configDisplayLoad"/>
 		</Scripts>
 	</Frame>
 </Ui>
diff --git a/config-enchants.lua b/config-enchants.lua
new file mode 100644
index 0000000..d7a89fc
--- /dev/null
+++ b/config-enchants.lua
@@ -0,0 +1,131 @@
+local function enchantSourceOnClick(self, source)
+	if self:GetChecked() then
+		ww_vars.options.enchants.sources[source] = true
+	else
+		ww_vars.options.enchants.sources[source] = false
+	end
+	WeightsWatcher.ResetEnchantCache()
+	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+end
+
+function ww_configEnchantsCraftedClick(self)
+	enchantSourceOnClick(self, "Crafted")
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.enchants.sources["Crafted"]
+end
+
+function ww_configEnchantsCraftedLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["USE_PC_ENCH_TT"]
+	self:SetText(ww_localization["USE_PC_ENCH"])
+end
+
+function ww_configEnchantsPVPVendorClick(self)
+	enchantSourceOnClick(self, "PVP-Vendor")
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.enchants.sources["PVP-Vendor"]
+end
+
+function ww_configEnchantsPVPVendorLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["USE_PVPVP_ENCH_TT"]
+	self:SetText(ww_localization["USE_PVPVP_ENCH"])
+end
+
+function ww_configEnchantsQuestClick(self)
+	enchantSourceOnClick(self, "Quest")
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.enchants.sources["Quest"]
+end
+
+function ww_configEnchantsQuestLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["USE_QR_ENCH_TT"]
+	self:SetText(ww_localization["USE_QR_ENCH"])
+end
+
+function ww_configEnchantsVendorClick(self)
+	enchantSourceOnClick(self, "Vendor")
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.enchants.sources["Vendor"]
+end
+
+function ww_configEnchantsVendorLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["USE_VP_ENCH_TT"]
+	self:SetText(ww_localization["USE_VP_ENCH"])
+end
+
+function ww_configEnchantsConsiderRepShow(self)
+	UIDropDownMenu_Initialize(self, ww_RepOptionsDropDownInitialize)
+	UIDropDownMenu_SetSelectedValue(self, ww_vars.options.enchants.considerRep)
+	if ww_vars.options.enchants.considerRep == "Any" then
+		ww_configEnchantOptions.considerBoa:Disable()
+	else
+		ww_configEnchantOptions.considerBoa:Enable()
+	end
+end
+
+function ww_configEnchantsConsiderRepLabel(self)
+	self.label:SetText(ww_localization["USE_REP_ENCH"])
+end
+
+function ww_configEnchantsConsiderBoaClick(self)
+	if self:GetChecked() then
+		ww_vars.options.enchants.considerBoa = true
+	else
+		ww_vars.options.enchants.considerBoa = false
+	end
+	WeightsWatcher.ResetEnchantCache()
+	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+end
+
+function ww_configEnchantsConsiderBoaLoad(self)
+	self.shouldBeChecked = function() return ww_vars.options.enchants.considerBoa end
+	self.ttText = ww_localization["USE_BTA_ENCH_TT"]
+	self:SetText(ww_localization["USE_BTA_ENCH"])
+end
+
+function ww_configEnchantsConsiderProfessionsShow(self)
+	UIDropDownMenu_Initialize(self, ww_ProfessionOptionsDropDownInitialize)
+	UIDropDownMenu_SetSelectedValue(self, ww_vars.options.enchants.considerProfessions)
+end
+
+function ww_configEnchantsConsiderProfessionsLabel(self)
+	self.label:SetText(ww_localization["USE_PROF_ENCH"])
+end
+
+local function default()
+	ww_vars.options.enchants = ww_defaultVars.options.enchants
+	WeightsWatcher.ResetEnchantCache()
+	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+end
+
+function ww_configEnchantsLoad(self)
+	local checkBoxes = {
+		["Vendor"] = self.useVendorEnchants,
+		["PVP-Vendor"] = self.usePVPVendorEnchants,
+		["Crafted"] = self.useCraftedEnchants,
+		["Quest"] = self.useQuestEnchants,
+		["considerBoa"] = self.considerBoa,
+	}
+
+	local function refresh()
+		ww_refreshCheckBoxes(checkBoxes)
+	end
+
+	self.header:SetText(ww_localization["IDEAL_ENCHANT_OPTS"])
+	self.name = ww_localization["IDEAL_ENCHANT_NAME"]
+	self.parent = "WeightsWatcher"
+	self.default = default
+	self.refresh = refresh
+	InterfaceOptions_AddCategory(self)
+end
diff --git a/config-enchants.xml b/config-enchants.xml
index ff8fc24..642a0df 100644
--- a/config-enchants.xml
+++ b/config-enchants.xml
@@ -1,5 +1,6 @@
 <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 		xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
+	<Script file="config-enchants.lua"/>
 	<Frame name="ww_configEnchantOptions" inherits="ww_borderedFrame" hidden="true">
 		<Anchors>
 			<Anchor point="TOPLEFT"/>
@@ -22,20 +23,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentHeader"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.enchants.sources["Crafted"] = true
-						else
-							ww_vars.options.enchants.sources["Crafted"] = false
-						end
-						WeightsWatcher.ResetEnchantCache()
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.enchants.sources["Crafted"] end
-						self.ttText = ww_localization["USE_PC_ENCH_TT"]
-						self:SetText(ww_localization["USE_PC_ENCH"])
-					</OnLoad>
+					<OnClick function="ww_configEnchantsCraftedClick"/>
+					<OnLoad function="ww_configEnchantsCraftedLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentUsePVPVendorEnchants" parentKey="usePVPVendorEnchants" inherits="ww_checkButton">
@@ -43,20 +32,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentUseCraftedEnchants"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.enchants.sources["PVP-Vendor"] = true
-						else
-							ww_vars.options.enchants.sources["PVP-Vendor"] = false
-						end
-						WeightsWatcher.ResetEnchantCache()
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.enchants.sources["PVP-Vendor"] end
-						self.ttText = ww_localization["USE_PVPVP_ENCH_TT"]
-						self:SetText(ww_localization["USE_PVPVP_ENCH"])
-					</OnLoad>
+					<OnClick function="ww_configEnchantsPVPVendorClick"/>
+					<OnLoad function="ww_configEnchantsPVPVendorLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentUseQuestEnchants" parentKey="useQuestEnchants" inherits="ww_checkButton">
@@ -64,20 +41,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentUsePVPVendorEnchants"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.enchants.sources["Quest"] = true
-						else
-							ww_vars.options.enchants.sources["Quest"] = false
-						end
-						WeightsWatcher.ResetEnchantCache()
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.enchants.sources["Quest"] end
-						self.ttText = ww_localization["USE_QR_ENCH_TT"]
-						self:SetText(ww_localization["USE_QR_ENCH"])
-					</OnLoad>
+					<OnClick function="ww_configEnchantsQuestClick"/>
+					<OnLoad function="ww_configEnchantsQuestLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentUseVendorEnchants" parentKey="useVendorEnchants" inherits="ww_checkButton">
@@ -85,20 +50,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentUseQuestEnchants"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.enchants.sources["Vendor"] = true
-						else
-							ww_vars.options.enchants.sources["Vendor"] = false
-						end
-						WeightsWatcher.ResetEnchantCache()
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.enchants.sources["Vendor"] end
-						self.ttText = ww_localization["USE_VP_ENCH_TT"]
-						self:SetText(ww_localization["USE_VP_ENCH"])
-					</OnLoad>
+					<OnClick function="ww_configEnchantsVendorClick"/>
+					<OnLoad function="ww_configEnchantsVendorLoad"/>
 				</Scripts>
 			</CheckButton>
 			<Frame name="$parentConsiderRep" parentKey="considerRep" inherits="ww_labeledElement">
@@ -123,25 +76,13 @@
 							</Anchor>
 						</Anchors>
 						<Scripts>
-							<OnLoad>
-								UIDropDownMenu_JustifyText(self, "LEFT")
-							</OnLoad>
-							<OnShow>
-								UIDropDownMenu_Initialize(self, ww_RepOptionsDropDownInitialize)
-								UIDropDownMenu_SetSelectedValue(self, ww_vars.options.enchants.considerRep)
-								if ww_vars.options.enchants.considerRep == "Any" then
-									ww_configEnchantOptions.considerBoa:Disable()
-								else
-									ww_configEnchantOptions.considerBoa:Enable()
-								end
-							</OnShow>
+							<OnLoad function="ww_leftJustifyDropDownText"/>
+							<OnShow function="ww_configEnchantsConsiderRepShow"/>
 						</Scripts>
 					</Button>
 				</Frames>
 				<Scripts>
-					<OnLoad>
-						self.label:SetText(ww_localization["USE_REP_ENCH"])
-					</OnLoad>
+					<OnLoad function="ww_configEnchantsConsiderRepLabel"/>
 				</Scripts>
 			</Frame>
 			<CheckButton name="$parentConsiderBoa" parentKey="considerBoa" inherits="ww_checkButton">
@@ -153,20 +94,8 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.enchants.considerBoa = true
-						else
-							ww_vars.options.enchants.considerBoa = false
-						end
-						WeightsWatcher.ResetEnchantCache()
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.enchants.considerBoa end
-						self.ttText = ww_localization["USE_BTA_ENCH_TT"]
-						self:SetText(ww_localization["USE_BTA_ENCH"])
-					</OnLoad>
+					<OnClick function="ww_configEnchantsConsiderBoaClick"/>
+					<OnLoad function="ww_configEnchantsConsiderBoaLoad"/>
 				</Scripts>
 			</CheckButton>
 			<Frame name="$parentConsiderProfessions" parentKey="considerProfessions" inherits="ww_labeledElement">
@@ -191,53 +120,18 @@
 							</Anchor>
 						</Anchors>
 						<Scripts>
-							<OnLoad>
-								UIDropDownMenu_JustifyText(self, "LEFT")
-							</OnLoad>
-							<OnShow>
-								UIDropDownMenu_Initialize(self, ww_ProfessionOptionsDropDownInitialize)
-								UIDropDownMenu_SetSelectedValue(self, ww_vars.options.enchants.considerProfessions)
-							</OnShow>
+							<OnLoad function="ww_leftJustifyDropDownText"/>
+							<OnShow function="ww_configEnchantsConsiderProfessionsShow"/>
 						</Scripts>
 					</Button>
 				</Frames>
 				<Scripts>
-					<OnLoad>
-						self.label:SetText(ww_localization["USE_PROF_ENCH"])
-					</OnLoad>
+					<OnLoad function="ww_configEnchantsConsiderProfessionsLabel"/>
 				</Scripts>
 			</Frame>
 		</Frames>
 		<Scripts>
-			<OnLoad>
-				self.header:SetText(ww_localization["IDEAL_ENCHANT_OPTS"])
-				self.name = ww_localization["IDEAL_ENCHANT_NAME"]
-				self.parent = "WeightsWatcher"
-				self.default = function()
-						ww_vars.options.enchants = ww_defaultVars.options.enchants
-						WeightsWatcher.ResetEnchantCache()
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					end
-				local checkBoxes = {
-					"Crafted",
-					"PVP-Vendor",
-					"Quest",
-					"Vendor",
-					"considerBoa",
-					["Vendor"] = self.useVendorEnchants,
-					["PVP-Vendor"] = self.usePVPVendorEnchants,
-					["Crafted"] = self.useCraftedEnchants,
-					["Quest"] = self.useQuestEnchants,
-					["considerBoa"] = self.considerBoa,
-				}
-				self.refresh = function()
-						for _, option in ipairs(checkBoxes) do
-							local checkBox = checkBoxes[option]
-							checkBox:SetChecked(checkBox.shouldBeChecked())
-						end
-					end
-				InterfaceOptions_AddCategory(self)
-			</OnLoad>
+			<OnLoad function="ww_configEnchantsLoad"/>
 		</Scripts>
 	</Frame>
 </Ui>
diff --git a/config-gems.lua b/config-gems.lua
new file mode 100644
index 0000000..176a02d
--- /dev/null
+++ b/config-gems.lua
@@ -0,0 +1,223 @@
+function ww_configGemsQualityDropdownLoad(self)
+	UIDropDownMenu_SetWidth(self, 200, 15)
+	ww_leftJustifyDropDownText(self)
+end
+
+function ww_configGemsQualityDropdownShow(self)
+	UIDropDownMenu_Initialize(self, ww_GemQualityDropDownInitialize)
+	UIDropDownMenu_SetSelectedValue(self, ww_vars.options.gems.qualityLimit)
+end
+
+function ww_configGemsQualityDropDownLabel(self)
+	self.label:SetText(ww_localization["MAX_GEM_QUAL"])
+	self:SetBackdropColor(1, 0, 0, 0.5)
+end
+
+local function gemTypeOnClick(self, type)
+	if self:GetChecked() then
+		ww_vars.options.gems.types[type] = true
+	else
+		ww_vars.options.gems.types[type] = false
+	end
+	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+end
+
+function ww_configGemsUEClick(self)
+	gemTypeOnClick(self, "Unique-Equipped")
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.gems.types["Unique-Equipped"]
+end
+
+function ww_configGemsUELoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["USE_UE_GEMS_TT"]
+	self:SetText(ww_localization["USE_UE_GEMS"])
+end
+
+function ww_configGemsJCClick(self)
+	gemTypeOnClick(self, "Jewelcrafter-Only")
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.gems.types["Jewelcrafter-Only"]
+end
+
+function ww_configGemsJCLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["USE_JC_GEMS_TT"]
+	self:SetText(ww_localization["USE_JC_GEMS"])
+end
+
+function ww_configGemsVendorClick(self)
+	gemTypeOnClick(self, "Vendor")
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.gems.types["Vendor"]
+end
+
+function ww_configGemsVendorLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["USE_VP_GEMS_TT"]
+	self:SetText(ww_localization["USE_VP_GEMS"])
+end
+
+function ww_configGemsPVPVendorClick(self)
+	gemTypeOnClick(self, "PVP-Vendor")
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.gems.types["PVP-Vendor"]
+end
+
+function ww_configGemsPVPVendorLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["USE_PVPVP_GEMS_TT"]
+	self:SetText(ww_localization["USE_PVPVP_GEMS"])
+end
+
+function ww_configGemsCraftedClick(self)
+	if self:GetChecked() then
+		ww_vars.options.gems.sources["Crafted"] = true
+		self:GetParent().useProcGems:Enable()
+	else
+		ww_vars.options.gems.sources["Crafted"] = false
+		self:GetParent().useProcGems:Disable()
+	end
+	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.gems.types["Crafted"]
+end
+
+function ww_configGemsCraftedLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["USE_PC_GEMS_TT"]
+	self:SetText(ww_localization["USE_PC_GEMS"])
+end
+
+function ww_configGemsProcClick(self)
+	gemTypeOnClick(self, "Procced")
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.gems.types["Procced"]
+end
+
+local function shouldBeEnabled()
+	return ww_vars.options.gems.sources["Crafted"]
+end
+
+function ww_configGemsProcLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.shouldBeEnabled = shouldBeEnabled
+	self.ttText = ww_localization["USE_P_GEMS_TT"]
+	self:SetText(ww_localization["USE_P_GEMS"])
+end
+
+function ww_configGemsDropClick(self)
+	gemTypeOnClick(self, "Drop")
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.gems.types["Drop"]
+end
+
+function ww_configGemsDropLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["USE_D_GEMS_TT"]
+	self:SetText(ww_localization["USE_D_GEMS"])
+end
+
+function ww_configGemsQuestClick(self)
+	gemTypeOnClick(self, "Quest")
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.gems.types["Quest"]
+end
+
+function ww_configGemsQuestLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["USE_QR_GEMS_TT"]
+	self:SetText(ww_localization["USE_QR_GEMS"])
+end
+
+function ww_configGemsBreakSocketColorsClick(self)
+	if self:GetChecked() then
+		ww_vars.options.gems.breakSocketColors = false
+		self:GetParent().alwaysObeySocketColors:Enable()
+	else
+		ww_vars.options.gems.breakSocketColors = true
+		self:GetParent().alwaysObeySocketColors:Disable()
+	end
+	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+end
+
+local function shouldBeChecked()
+	return not ww_vars.options.gems.breakSocketColors
+end
+
+function ww_configGemsBreakSocketColorsLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.ttText = ww_localization["MATCH_SOCKET_TT"]
+	self:SetText(ww_localization["MATCH_SOCKET"])
+end
+
+function ww_configGemsNeverBreakSocketColorsClick(self)
+	if self:GetChecked() then
+		ww_vars.options.gems.neverBreakSocketColors = true
+	else
+		ww_vars.options.gems.neverBreakSocketColors = false
+	end
+	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+end
+
+local function shouldBeChecked()
+	return ww_vars.options.gems.neverBreakSocketColors
+end
+
+local function shouldBeEnabled()
+	return not ww_vars.options.gems.breakSocketColors
+end
+
+function ww_configGemsNeverBreakSocketColorsLoad(self)
+	self.shouldBeChecked = shouldBeChecked
+	self.shouldBeEnabled = shouldBeEnabled
+	self.ttText = ww_localization["ALWAYS_MATCH_SOCKET_TT"]
+	self:SetText(ww_localization["ALWAYS_MATCH_SOCKET"])
+end
+
+local function default()
+	ww_vars.options.gems = ww_defaultVars.options.gems
+	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+end
+
+function ww_configGemsLoad(self)
+	local checkBoxes = {
+		["Unique-Equipped"] = self.useUEGems,
+		["Jewelcrafter-Only"] = self.useJCOnlyGems,
+		["Vendor"] = self.useVendorGems,
+		["PVP-Vendor"] = self.usePVPVendorGems,
+		["Crafted"] = self.useCraftedGems,
+		["Procced"] = self.useProcGems,
+		["Drop"] = self.useDropGems,
+		["Quest"] = self.useQuestGems,
+		["obeySocketColors"] = self.obeySocketColors,
+		["alwaysObeySocketColors"] = self.alwaysObeySocketColors,
+	}
+
+	local function refresh()
+		ww_refreshCheckBoxes(checkBoxes)
+	end
+
+	self.header:SetText(ww_localization["IDEAL_GEM_OPTS"])
+	self.name = ww_localization["IDEAL_GEM_NAME"]
+	self.parent = "WeightsWatcher"
+	self.default = default
+	self.refresh = refresh
+	InterfaceOptions_AddCategory(self)
+end
diff --git a/config-gems.xml b/config-gems.xml
index 3078f00..6041c5b 100644
--- a/config-gems.xml
+++ b/config-gems.xml
@@ -1,5 +1,6 @@
 <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 		xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
+	<Script file="config-gems.lua"/>
 	<Frame name="ww_configGemOptions" inherits="ww_borderedFrame" hidden="true">
 		<Anchors>
 			<Anchor point="TOPLEFT"/>
@@ -43,22 +44,13 @@
 							</Anchor>
 						</Anchors>
 						<Scripts>
-							<OnLoad>
-								UIDropDownMenu_SetWidth(self, 200, 15)
-								UIDropDownMenu_JustifyText(self, "LEFT")
-							</OnLoad>
-							<OnShow>
-								UIDropDownMenu_Initialize(self, ww_GemQualityDropDownInitialize)
-								UIDropDownMenu_SetSelectedValue(self, ww_vars.options.gems.qualityLimit)
-							</OnShow>
+							<OnLoad function="ww_configGemsQualityDropdownLoad"/>
+							<OnShow function="ww_configGemsQualityDropdownShow"/>
 						</Scripts>
 					</Button>
 				</Frames>
 				<Scripts>
-					<OnLoad>
-						self.label:SetText(ww_localization["MAX_GEM_QUAL"])
-						self:SetBackdropColor(1, 0, 0, 0.5)
-					</OnLoad>
+					<OnLoad function="ww_configGemsQualityDropDownLabel"/>
 				</Scripts>
 			</Frame>
 			<CheckButton name="$parentUseUEGems" parentKey="useUEGems" inherits="ww_checkButton">
@@ -66,19 +58,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentGemQuality"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.gems.types["Unique-Equipped"] = true
-						else
-							ww_vars.options.gems.types["Unique-Equipped"] = false
-						end
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.gems.types["Unique-Equipped"] end
-						self.ttText = ww_localization["USE_UE_GEMS_TT"]
-						self:SetText(ww_localization["USE_UE_GEMS"])
-					</OnLoad>
+					<OnClick function="ww_configGemsUEClick"/>
+					<OnLoad function="ww_configGemsUELoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentUseJCOnlyGems" parentKey="useJCOnlyGems" inherits="ww_checkButton">
@@ -86,19 +67,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentUseUEGems"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.gems.types["Jewelcrafter-Only"] = true
-						else
-							ww_vars.options.gems.types["Jewelcrafter-Only"] = false
-						end
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.gems.types["Jewelcrafter-Only"] end
-						self.ttText = ww_localization["USE_JC_GEMS_TT"]
-						self:SetText(ww_localization["USE_JC_GEMS"])
-					</OnLoad>
+					<OnClick function="ww_configGemsJCClick"/>
+					<OnLoad function="ww_configGemsJCLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentUseVendorGems" parentKey="useVendorGems" inherits="ww_checkButton">
@@ -106,19 +76,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentUseJCOnlyGems"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.gems.sources["Vendor"] = true
-						else
-							ww_vars.options.gems.sources["Vendor"] = false
-						end
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.gems.sources["Vendor"] end
-						self.ttText = ww_localization["USE_VP_GEMS_TT"]
-						self:SetText(ww_localization["USE_VP_GEMS"])
-					</OnLoad>
+					<OnClick function="ww_configGemsVendorClick"/>
+					<OnLoad function="ww_configGemsVendorLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentUsePVPVendorGems" parentKey="usePVPVendorGems" inherits="ww_checkButton">
@@ -126,19 +85,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentUseVendorGems"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.gems.sources["PVP-Vendor"] = true
-						else
-							ww_vars.options.gems.sources["PVP-Vendor"] = false
-						end
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.gems.sources["PVP-Vendor"] end
-						self.ttText = ww_localization["USE_PVPVP_GEMS_TT"]
-						self:SetText(ww_localization["USE_PVPVP_GEMS"])
-					</OnLoad>
+					<OnClick function="ww_configGemsPVPVendorClick"/>
+					<OnLoad function="ww_configGemsPVPVendorLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentUseCraftedGems" parentKey="useCraftedGems" inherits="ww_checkButton">
@@ -146,21 +94,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentUsePVPVendorGems"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.gems.sources["Crafted"] = true
-							self:GetParent().useProcGems:Enable()
-						else
-							ww_vars.options.gems.sources["Crafted"] = false
-							self:GetParent().useProcGems:Disable()
-						end
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.gems.sources["Crafted"] end
-						self.ttText = ww_localization["USE_PC_GEMS_TT"]
-						self:SetText(ww_localization["USE_PC_GEMS"])
-					</OnLoad>
+					<OnClick function="ww_configGemsCraftedClick"/>
+					<OnLoad function="ww_configGemsCraftedLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentUseProcGems" parentKey="useProcGems" inherits="ww_checkButton">
@@ -172,20 +107,8 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.gems.sources["Procced"] = true
-						else
-							ww_vars.options.gems.sources["Procced"] = false
-						end
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.gems.sources["Procced"] end
-						self.shouldBeEnabled = function() return ww_vars.options.gems.sources["Crafted"] end
-						self.ttText = ww_localization["USE_P_GEMS_TT"]
-						self:SetText(ww_localization["USE_P_GEMS"])
-					</OnLoad>
+					<OnClick function="ww_configGemsProcClick"/>
+					<OnLoad function="ww_configGemsProcLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentUseDropGems" parentKey="useDropGems" inherits="ww_checkButton">
@@ -193,19 +116,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentUseProcGems"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.gems.sources["Drop"] = true
-						else
-							ww_vars.options.gems.sources["Drop"] = false
-						end
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.gems.sources["Drop"] end
-						self.ttText = ww_localization["USE_D_GEMS_TT"]
-						self:SetText(ww_localization["USE_D_GEMS"])
-					</OnLoad>
+					<OnClick function="ww_configGemsDropClick"/>
+					<OnLoad function="ww_configGemsDropLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentUseQuestGems" parentKey="useQuestGems" inherits="ww_checkButton">
@@ -213,19 +125,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentUseDropGems"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.gems.sources["Quest"] = true
-						else
-							ww_vars.options.gems.sources["Quest"] = false
-						end
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.gems.sources["Quest"] end
-						self.ttText = ww_localization["USE_QR_GEMS_TT"]
-						self:SetText(ww_localization["USE_QR_GEMS"])
-					</OnLoad>
+					<OnClick function="ww_configGemsQuestClick"/>
+					<OnLoad function="ww_configGemsQuestLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentObeySocketColors" parentKey="obeySocketColors" inherits="ww_checkButton">
@@ -233,21 +134,8 @@
 					<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parentUseQuestGems"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.gems.breakSocketColors = false
-							self:GetParent().alwaysObeySocketColors:Enable()
-						else
-							ww_vars.options.gems.breakSocketColors = true
-							self:GetParent().alwaysObeySocketColors:Disable()
-						end
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return not ww_vars.options.gems.breakSocketColors end
-						self.ttText = ww_localization["MATCH_SOCKET_TT"]
-						self:SetText(ww_localization["MATCH_SOCKET"])
-					</OnLoad>
+					<OnClick function="ww_configGemsBreakSocketColorsClick"/>
+					<OnLoad function="ww_configGemsBreakSocketColorsLoad"/>
 				</Scripts>
 			</CheckButton>
 			<CheckButton name="$parentAlwaysObeySocketColors" parentKey="alwaysObeySocketColors" inherits="ww_checkButton">
@@ -259,69 +147,13 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if self:GetChecked() then
-							ww_vars.options.gems.neverBreakSocketColors = true
-						else
-							ww_vars.options.gems.neverBreakSocketColors = false
-						end
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					</OnClick>
-					<OnLoad>
-						self.shouldBeChecked = function() return ww_vars.options.gems.neverBreakSocketColors end
-						self.shouldBeEnabled = function() return not ww_vars.options.gems.breakSocketColors end
-						self.ttText = ww_localization["ALWAYS_MATCH_SOCKET_TT"]
-						self:SetText(ww_localization["ALWAYS_MATCH_SOCKET"])
-					</OnLoad>
+					<OnClick function="ww_configGemsNeverBreakSocketColorsClick"/>
+					<OnLoad function="ww_configGemsNeverBreakSocketColorsLoad"/>
 				</Scripts>
 			</CheckButton>
 		</Frames>
 		<Scripts>
-			<OnLoad>
-				self.header:SetText(ww_localization["IDEAL_GEM_OPTS"])
-				self.name = ww_localization["IDEAL_GEM_NAME"]
-				self.parent = "WeightsWatcher"
-				self.default = function()
-						ww_vars.options.gems = ww_defaultVars.options.gems
-						ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
-					end
-				local checkBoxes = {
-					"Unique-Equipped",
-					"Jewelcrafter-Only",
-					"Vendor",
-					"PVP-Vendor",
-					"Crafted",
-					"Procced",
-					"Drop",
-					"Quest",
-					"obeySocketColors",
-					"alwaysObeySocketColors",
-					["Unique-Equipped"] = self.useUEGems,
-					["Jewelcrafter-Only"] = self.useJCOnlyGems,
-					["Vendor"] = self.useVendorGems,
-					["PVP-Vendor"] = self.usePVPVendorGems,
-					["Crafted"] = self.useCraftedGems,
-					["Procced"] = self.useProcGems,
-					["Drop"] = self.useDropGems,
-					["Quest"] = self.useQuestGems,
-					["obeySocketColors"] = self.obeySocketColors,
-					["alwaysObeySocketColors"] = self.alwaysObeySocketColors,
-				}
-				self.refresh = function()
-						for _, option in ipairs(checkBoxes) do
-							local checkBox = checkBoxes[option]
-							checkBox:SetChecked(checkBox.shouldBeChecked())
-							if checkBox.shouldBeEnabled then
-								if checkBox.shouldBeEnabled() then
-									checkBox:Enable()
-								else
-									checkBox:Disable()
-								end
-							end
-						end
-					end
-				InterfaceOptions_AddCategory(self)
-			</OnLoad>
+			<OnLoad function=""/>
 		</Scripts>
 	</Frame>
 </Ui>
diff --git a/config.lua b/config.lua
index 3c7c4ae..2bf142f 100644
--- a/config.lua
+++ b/config.lua
@@ -19,6 +19,20 @@ local function showConfig(frame)
 	end
 end

+function ww_weightsCommand()
+	if InterfaceOptionsFrame:IsVisible() then
+		InterfaceOptionsFrameCancel:Click()
+	end
+	if InterfaceOptionsFrame:IsVisible() then
+		return
+	end
+	if ww_weights:IsVisible() then
+		ww_weights:Hide()
+	else
+		ww_weights:Show()
+	end
+end
+
 function ww_commandHandler(msg)
 	if msg:find("^" .. L["config"]) then
 		local frame = ww_config
@@ -40,17 +54,7 @@ function ww_commandHandler(msg)
 			showConfig(frame)
 		end
 	elseif msg == L["weights"] then
-		if InterfaceOptionsFrame:IsVisible() then
-			InterfaceOptionsFrameCancel:Click()
-		end
-		if InterfaceOptionsFrame:IsVisible() then
-			return
-		end
-		if ww_weights:IsVisible() then
-			ww_weights:Hide()
-		else
-			ww_weights:Show()
-		end
+		ww_weightsCommand()
 	elseif msg == L["version"] then
 		print(string.format(L["WW_VERSION"], GetAddOnMetadata("WeightsWatcher", "Version")))
 		print(string.format(L["ACCT_VERSION"], ww_vars.dataMajorVersion, ww_vars.dataMinorVersion))
@@ -177,3 +181,36 @@ function ww_ShowEnhancementsWhenDropDownInitialize(dropdown)
 		UIDropDownMenu_AddButton(info)
 	end
 end
+
+local function okay()
+	ww_config.originalOpts = nil
+end
+
+local function cancel()
+	ww_vars.options = ww_config.originalOpts
+	ww_config.originalOpts = nil
+	WeightsWatcher.ResetTables()
+end
+
+function ww_loadConfig(self)
+	local function refresh()
+		local function refresh()
+			ww_config.originalOpts = ww_config.originalOpts or ww_deepTableCopy(ww_vars.options)
+		end
+
+		self.version:SetText(string.format(ww_localization["CONF_WW_VER"], GetAddOnMetadata("WeightsWatcher", "Version")))
+		self.accountVersion:SetText(string.format(ww_localization["CONF_ACCT_VER"], ww_vars.dataMajorVersion, ww_vars.dataMinorVersion))
+		self.characterVersion:SetText(string.format(ww_localization["CONF_CHAR_VER"], ww_charVars.dataMajorVersion, ww_charVars.dataMinorVersion))
+		self.contact:SetText(string.format(ww_localization["CONF_CONTACT"], "WeightsWatcher@gmail.com"))
+		self.webpage:SetText(string.format(ww_localization["CONF_WEBPAGE"], "http://wowinterface.com/downloads/\n         info15289-WeightsWatcher.html"))
+		self.description:SetText(ww_localization["CONF_DESC"])
+		self.refresh = refresh
+		self.refresh()
+	end
+
+	self.name = "WeightsWatcher"
+	self.okay = okay
+	self.cancel = cancel
+	self.refresh = refresh
+	InterfaceOptions_AddCategory(self)
+end
diff --git a/config.xml b/config.xml
index adca973..1ded85c 100644
--- a/config.xml
+++ b/config.xml
@@ -95,37 +95,12 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						ww_commandHandler("weights")
-					</OnClick>
+					<OnClick function="ww_weightsCommand"/>
 				</Scripts>
 			</Button>
 		</Frames>
 		<Scripts>
-			<OnLoad>
-				self.name = "WeightsWatcher"
-				self.okay = function(...)
-						ww_config.originalOpts = nil
-					end
-				self.cancel = function(...)
-						ww_vars.options = ww_config.originalOpts
-						ww_config.originalOpts = nil
-						WeightsWatcher.ResetTables()
-					end
-				self.refresh = function(...)
-						self.version:SetText(string.format(ww_localization["CONF_WW_VER"], GetAddOnMetadata("WeightsWatcher", "Version")))
-						self.accountVersion:SetText(string.format(ww_localization["CONF_ACCT_VER"], ww_vars.dataMajorVersion, ww_vars.dataMinorVersion))
-						self.characterVersion:SetText(string.format(ww_localization["CONF_CHAR_VER"], ww_charVars.dataMajorVersion, ww_charVars.dataMinorVersion))
-						self.contact:SetText(string.format(ww_localization["CONF_CONTACT"], "WeightsWatcher@gmail.com"))
-						self.webpage:SetText(string.format(ww_localization["CONF_WEBPAGE"], "http://wowinterface.com/downloads/\n         info15289-WeightsWatcher.html"))
-						self.description:SetText(ww_localization["CONF_DESC"])
-						self.refresh = function(...)
-								ww_config.originalOpts = ww_config.originalOpts or ww_deepTableCopy(ww_vars.options)
-							end
-						self.refresh(...)
-					end
-				InterfaceOptions_AddCategory(self)
-			</OnLoad>
+			<OnLoad function="ww_loadConfig"/>
 		</Scripts>
 	</Frame>
 	<Include file="config-calculation.xml"/>
diff --git a/init.lua b/init.lua
new file mode 100644
index 0000000..cbcc5cb
--- /dev/null
+++ b/init.lua
@@ -0,0 +1,14 @@
+function ww_load(self)
+	self:RegisterEvent("ADDON_LOADED")
+end
+
+function ww_event(self, event, ...)
+	if event == "ADDON_LOADED" and ... == "WeightsWatcher" then
+		self:OnInitialize()
+		self:UnregisterEvent("ADDON_LOADED")
+	end
+end
+
+function ww_setHiddenTooltipOwner(self)
+	self:SetOwner(WorldFrame, "ANCHOR_NONE")
+end
diff --git a/weights.lua b/weights.lua
index 973a8d4..f607938 100644
--- a/weights.lua
+++ b/weights.lua
@@ -567,7 +567,8 @@ local function removeRecursive(shown, elements, start)
 	return offset
 end

-function ww_toggleCollapse(frame)
+function ww_toggleCollapse(self)
+	local frame = self:GetParent()
 	local scrolledFrame = frame
 	while scrolledFrame and not scrolledFrame.shown do
 		scrolledFrame = scrolledFrame:GetParent()
@@ -611,6 +612,269 @@ function ww_toggleCollapse(frame)
 		end
 	end
 	scrolledFrame.scrollFrame:GetScript("OnShow")(scrolledFrame.scrollFrame)
+	if frame.collapsed then
+		self:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-UP")
+		self:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-DOWN")
+	else
+		self:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP")
+		self:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN")
+	end
+end
+
+function ww_toggleTriggerActive(self)
+	-- The nots convert things to boolean (instead of 1/nil)
+	if not self:GetChecked() == not ww_weights.rightPanel.statList.triggers[self:GetText()] then
+		ww_weights.rightPanel.changedTriggers[self] = nil
+		local changed = false
+		for _ in pairs(ww_weights.rightPanel.changedStats) do
+			changed = true
+			break
+		end
+		if not changed then
+			for _ in pairs(ww_weights.rightPanel.changedTriggers) do
+				changed = true
+				break
+			end
+			if not changed then
+				ww_weights.rightPanel.saveButton:Disable()
+				ww_weights.rightPanel.resetButton:Disable()
+			end
+		end
+	else
+		ww_weights.rightPanel.changedTriggers[self] = self:GetText()
+		ww_weights.rightPanel.saveButton:Enable()
+		ww_weights.rightPanel.resetButton:Enable()
+	end
+end
+
+function ww_statValueTextChanged(self)
+	local text = self:GetText()
+	local number = tonumber(text)
+	if number then
+		self.number = number
+	elseif text:match("^[0.]*$") then
+		self.number = 0
+	end
+	if number == ww_weights.rightPanel.statList[self:GetParent().statName] or (number == 0 and ww_weights.rightPanel.statList[self:GetParent().statName] == nil) then
+		ww_weights.rightPanel.changedStats[self] = nil
+		local changed = false
+		for _ in pairs(ww_weights.rightPanel.changedStats) do
+			changed = true
+			break
+		end
+		for _ in pairs(ww_weights.rightPanel.changedTriggers) do
+			changed = true
+			break
+		end
+		if not changed then
+			ww_weights.rightPanel.saveButton:Disable()
+			ww_weights.rightPanel.resetButton:Disable()
+		end
+	else
+		ww_weights.rightPanel.changedStats[self] = self:GetParent().statName
+		ww_weights.rightPanel.saveButton:Enable()
+		ww_weights.rightPanel.resetButton:Enable()
+	end
+end
+
+function ww_statValueOnChar(self, text)
+	if ww_validateNumber(text, self:GetText()) then
+		self.number = tonumber(self:GetText()) or 0
+	else
+		local cursorPosition = self:GetCursorPosition() - 1
+		self:SetText(self.number)
+		self:SetCursorPosition(cursorPosition)
+	end
+end
+
+function ww_editFocusGained(self)
+	self:GetParent().highlightFrame:Show()
+	self:HighlightText()
+end
+
+function ww_editFocusLost(self)
+	self:GetParent().highlightFrame:Hide()
+	self:HighlightText(0,0)
+end
+
+function ww_statValueTabPressed(self)
+	ww_changeFocus(self:GetParent())
+end
+
+function ww_toggleWeightActive(self)
+	local parent = self:GetParent()
+	local class = parent.category.class
+
+	if not ww_charVars.activeWeights[class] then
+		ww_charVars.activeWeights[class] = {}
+		table.insert(ww_charVars.activeWeights, class)
+	end
+	if self:GetChecked() then
+		table.insert(ww_charVars.activeWeights[class], parent.name)
+	else
+		for i, weight in ipairs(ww_charVars.activeWeights[class]) do
+			if weight == parent.name then
+				table.remove(ww_charVars.activeWeights[class], i)
+				break
+			end
+		end
+	end
+end
+
+function ww_showWeightTooltip(self)
+	ww_showTooltip(self, ww_localization["WATCH_TT"])
+end
+
+function ww_confirmDiscardWeightChangesChangeWeight(self)
+	local function func()
+		ww_configSelectWeight(self:GetParent())
+	end
+
+	ww_configDiscardChanges(func)
+end
+
+function ww_classListScrollFrameOnShow(self)
+	ww_scrollBarUpdate(self, ww_weights.leftPanel.scrollContainer, 22, 0, 25)
+end
+
+function ww_scrollFrameOnVerticalScroll(self, offset)
+	FauxScrollFrame_OnVerticalScroll(self, offset, 22, self:GetScript("OnShow"))
+end
+
+function ww_copyWeight(self)
+	local parent = self:GetParent()
+	local weightFrame = parent.weightFrame
+	ww_configNewWeight(weightFrame.category.class, string.format(ww_localization["DEFAULT_COPY_NAME"], weightFrame.name), parent.statList)
+end
+
+function ww_copyButtonOnLoad(self)
+	ww_localizeText(self)
+	local relTo = self:GetParent().saveButton
+	local _, _, _, relToXOffset = relTo:GetPoint(1)
+	self:SetPoint("CENTER", relTo, (self:GetParent():GetWidth() - self:GetWidth() - 2 * relToXOffset) / 3, 0)
+end
+
+function ww_deleteButtonOnLoad(self)
+	ww_localizeText(self)
+	local relTo = self:GetParent().resetButton
+	local _, _, _, relToXOffset = relTo:GetPoint(1)
+	self:SetPoint("CENTER", relTo, (self:GetWidth() - 2 * relToXOffset - self:GetParent():GetWidth()) / 3, 0)
+end
+
+function ww_weightFrameScrollFrameOnShow(self)
+	ww_scrollBarUpdate(self, ww_weights.rightPanel.scrollContainer, 22, -30, 22)
+end
+
+function ww_weightFrameOnShow(self)
+	if not ww_weights.popup then
+		ww_changeFocus(self.scrollContainer.stats[#(self.scrollContainer.stats)])
+	end
+end
+
+function ww_restoreDefaultWeights()
+	local function func()
+		StaticPopup_Show("WW_CONFIRM_RESTORE_DEFAULT_WEIGHTS")
+	end
+
+	local weightFrame = ww_weights.rightPanel.weightFrame
+	if weightFrame and ww_defaultVars.weightsList[weightFrame.category.class][weightFrame.name] then
+		func()
+	else
+		ww_configDiscardChanges(func)
+	end
+end
+
+function ww_weightsOnShow(self)
+	function self:SmartHide(func)
+		self.afterHide = func
+		self:Hide()
+	end
+
+	ww_localizeText(self.title)
+	ww_localizeText(self.weightsAttribution)
+	table.insert(UISpecialFrames, self:GetName())
+end
+
+function ww_weightsOnHide(self)
+	if self.reallyClose then
+		self.reallyClose = nil
+		if self.afterHide then
+			self.afterHide()
+		end
+		self.afterHide = nil
+	else
+		local function func()
+			self.reallyClose = true
+			-- Safe because ww_configDiscardChanges will save the weight first
+			if self.rightPanel:IsShown() then
+				ww_configResetWeight()
+			end
+			self:Hide()
+			if self.afterHide then
+				self.afterHide()
+			end
+			self.afterHide = nil
+		end
+
+		self.popup = true
+		self:Show()
+		ww_configDiscardChanges(func)
+		self.popup = nil
+	end
+end
+
+function ww_initializeClassDropDown(self)
+	UIDropDownMenu_Initialize(self, ww_ClassDropDownInitialize)
+	UIDropDownMenu_SetSelectedValue(self, WeightsWatcher.player.class)
+end
+
+function ww_weightNameTextChanged(self)
+	if self:GetText() == "" then
+		self:GetParent().createButton:Disable()
+	else
+		self:GetParent().createButton:Enable()
+	end
+end
+
+local function handleWeightExistsPopup(button)
+	if StaticPopup_Visible("WW_WEIGHT_EXISTS") then
+		StaticPopup_Hide("WW_WEIGHT_EXISTS")
+	else
+		button:Click()
+	end
+end
+
+function ww_weightNameEnterPressed(self)
+	handleWeightExistsPopup(self:GetParent().createButton)
+end
+
+function ww_weightNameEscapePressed(self)
+	handleWeightExistsPopup(self:GetParent().cancelButton)
+end
+
+function ww_createNewWeight(self)
+	local parent = self:GetParent()
+	local class = UIDropDownMenu_GetSelectedValue(parent.dropdown)
+	local name = parent.editBox:GetText()
+	if ww_vars.weightsList[class][name] then
+		local error = StaticPopup_Show("WW_WEIGHT_EXISTS", ww_classDisplayNames[class], name)
+	else
+		ww_setWeight(class, name, parent.statList)
+		ww_selectWeight(class, name)
+		parent:Hide()
+	end
+end
+
+function ww_hidePopup(self)
+	self:GetParent():Hide()
+end
+
+function ww_newWeightLocalizeText(self)
+	ww_localizeText(self.text)
+end
+
+function ww_setFocusOnEditBox(self)
+	self.editBox:SetFocus()
 end

 local function loadStatButtons()
diff --git a/weights.xml b/weights.xml
index 49d0fc3..8027339 100644
--- a/weights.xml
+++ b/weights.xml
@@ -47,21 +47,8 @@
 					</Anchors>
 				</HighlightTexture>
 				<Scripts>
-					<OnLoad>
-						local fontString = self:CreateFontString(nil, "OVERLAY", "GameFontNormal")
-						fontString:SetPoint("LEFT", 20, 0)
-						self:SetFontString(fontString)
-					</OnLoad>
-					<OnClick>
-						ww_toggleCollapse(self:GetParent(), self:GetParent():GetParent():GetParent().scrollFrame)
-						if self:GetParent().collapsed then
-							self:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-UP")
-							self:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-DOWN")
-						else
-							self:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP")
-							self:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN")
-						end
-					</OnClick>
+					<OnLoad function="ww_normalFontString"/>
+					<OnClick function="ww_toggleCollapse"/>
 				</Scripts>
 			</Button>
 		</Frames>
@@ -112,21 +99,8 @@
 					</Anchors>
 				</HighlightTexture>
 				<Scripts>
-					<OnLoad>
-						local fontString = self:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
-						fontString:SetPoint("LEFT", 20, 0)
-						self:SetFontString(fontString)
-					</OnLoad>
-					<OnClick>
-						ww_toggleCollapse(self:GetParent())
-						if self:GetParent().collapsed then
-							self:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-UP")
-							self:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-DOWN")
-						else
-							self:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP")
-							self:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN")
-						end
-					</OnClick>
+					<OnLoad function="ww_highlightFontString"/>
+					<OnClick function="ww_toggleCollapse"/>
 				</Scripts>
 			</Button>
 		</Frames>
@@ -194,61 +168,13 @@
 					</Anchors>
 				</FontString>
 				<Scripts>
-					<OnLoad>
-						self:SetTextInsets(5, 5, 0, 0)
-					</OnLoad>
-					<OnTextChanged>
-						local text = self:GetText()
-						local number = tonumber(text)
-						if number then
-							self.number = number
-						elseif text:match("^[0.]*$") then
-							self.number = 0
-						end
-						if number == ww_weights.rightPanel.statList[self:GetParent().statName] or (number == 0 and ww_weights.rightPanel.statList[self:GetParent().statName] == nil) then
-							ww_weights.rightPanel.changedStats[self] = nil
-							local changed = false
-							for _ in pairs(ww_weights.rightPanel.changedStats) do
-								changed = true
-								break
-							end
-							for _ in pairs(ww_weights.rightPanel.changedTriggers) do
-								changed = true
-								break
-							end
-							if not changed then
-								ww_weights.rightPanel.saveButton:Disable()
-								ww_weights.rightPanel.resetButton:Disable()
-							end
-						else
-							ww_weights.rightPanel.changedStats[self] = self:GetParent().statName
-							ww_weights.rightPanel.saveButton:Enable()
-							ww_weights.rightPanel.resetButton:Enable()
-						end
-					</OnTextChanged>
-					<OnChar>
-						if ww_validateNumber(text, self:GetText()) then
-							self.number = tonumber(self:GetText()) or 0
-						else
-							local cursorPosition = self:GetCursorPosition() - 1
-							self:SetText(self.number)
-							self:SetCursorPosition(cursorPosition)
-						end
-					</OnChar>
-					<OnEditFocusGained>
-						self:GetParent().highlightFrame:Show()
-						self:HighlightText()
-					</OnEditFocusGained>
-					<OnEditFocusLost>
-						self:GetParent().highlightFrame:Hide()
-						self:HighlightText(0,0)
-					</OnEditFocusLost>
-					<OnTabPressed>
-						ww_changeFocus(self:GetParent())
-					</OnTabPressed>
-					<OnEscapePressed>
-						self:ClearFocus()
-					</OnEscapePressed>
+					<OnLoad function="ww_editBoxTextInsets"/>
+					<OnTextChanged function="ww_statValueTextChanged"/>
+					<OnChar function="ww_statValueOnChar"/>
+					<OnEditFocusGained function="ww_editFocusGained"/>
+					<OnEditFocusLost function="ww_editFocusLost"/>
+					<OnTabPressed function="ww_statValueTabPressed"/>
+					<OnEscapePressed function="ww_clearFocus"/>
 				</Scripts>
 			</EditBox>
 		</Frames>
@@ -290,29 +216,7 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						-- The nots convert things to boolean (instead of 1/nil)
-						if not self:GetChecked() == not ww_weights.rightPanel.statList.triggers[self:GetText()] then
-							ww_weights.rightPanel.changedTriggers[self] = nil
-							local changed = false
-							for _ in pairs(ww_weights.rightPanel.changedStats) do
-								changed = true
-								break
-							end
-							for _ in pairs(ww_weights.rightPanel.changedTriggers) do
-								changed = true
-								break
-							end
-							if not changed then
-								ww_weights.rightPanel.saveButton:Disable()
-								ww_weights.rightPanel.resetButton:Disable()
-							end
-						else
-							ww_weights.rightPanel.changedTriggers[self] = self:GetText()
-							ww_weights.rightPanel.saveButton:Enable()
-							ww_weights.rightPanel.resetButton:Enable()
-						end
-					</OnClick>
+					<OnClick function="ww_toggleTriggerActive"/>
 				</Scripts>
 			</CheckButton>
 		</Frames>
@@ -338,33 +242,9 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						local parent = self:GetParent()
-						local class = parent.category.class
-
-						if not ww_charVars.activeWeights[class] then
-							ww_charVars.activeWeights[class] = {}
-							table.insert(ww_charVars.activeWeights, class)
-						end
-						if self:GetChecked() then
-							table.insert(ww_charVars.activeWeights[class], parent.name)
-						else
-							for i, weight in ipairs(ww_charVars.activeWeights[class]) do
-								if weight == parent.name then
-									table.remove(ww_charVars.activeWeights[class], i)
-									break
-								end
-							end
-						end
-					</OnClick>
-					<OnEnter>
-						GameTooltip:SetOwner(self,"ANCHOR_RIGHT")
-						GameTooltip:AddLine(ww_localization["WATCH_TT"], 1, 1, 1)
-						GameTooltip:Show()
-					</OnEnter>
-					<OnLeave>
-						GameTooltip:Hide()
-					</OnLeave>
+					<OnClick function="ww_toggleWeightActive"/>
+					<OnEnter function="ww_showWeightTooltip"/>
+					<OnLeave function="ww_hideTooltip"/>
 				</Scripts>
 			</CheckButton>
 			<Button name="$parentText" parentKey="text">
@@ -410,28 +290,11 @@
 					</Frame>
 				</Frames>
 				<Scripts>
-					<OnClick>
-						ww_configDiscardChanges(function()
-								ww_configSelectWeight(self:GetParent())
-							end)
-					</OnClick>
-					<OnLoad>
-						self:SetFontString(self:CreateFontString(nil, "OVERLAY", "ww_defaultString"))
-					</OnLoad>
+					<OnClick function="ww_confirmDiscardWeightChangesChangeWeight"/>
+					<OnLoad function="ww_defaultFontString"/>
 				</Scripts>
 			</Button>
 		</Frames>
-<!--		<Scripts>
-			<OnHide>
-				self.checkButton:Hide()
-				self.text:Hide()
-			</OnHide>
-			<OnShow>
-				self.checkButton:Show()
-				self.text:Show()
-				error()
-			</OnShow>
-		</Scripts> -->
 	</Frame>
 	<!-- The frame containing all weight-related content -->
 	<Frame name="ww_weights" parent="UIParent" hidden="true" frameStrata="HIGH">
@@ -470,7 +333,7 @@
 				</Texture>
 			</Layer>
 		</Layers>
-		<!--list of objects within the configuartion window-->
+		<!--list of objects within the configuration window-->
 		<Frames>
 			<!--The Class Selection Frame-->
 			<Frame name="$parentLeftPanel" parentKey="leftPanel">
@@ -520,12 +383,8 @@
 							</Anchor>
 						</Anchors>
 						<Scripts>
-							<OnShow>
-								ww_scrollBarUpdate(self, ww_weights.leftPanel.scrollContainer, 22, 0, 25)
-							</OnShow>
-							<OnVerticalScroll>
-								FauxScrollFrame_OnVerticalScroll(self, offset, 22, self:GetScript("OnShow"))
-							</OnVerticalScroll>
+							<OnShow function="ww_classListScrollFrameOnShow"/>
+							<OnVerticalScroll function="ww_scrollFrameOnVerticalScroll"/>
 						</Scripts>
 					</ScrollFrame>
 				</Frames>
@@ -583,9 +442,7 @@
 							</Anchor>
 						</Anchors>
 						<Scripts>
-							<OnClick>
-								ww_configSaveWeight()
-							</OnClick>
+							<OnClick function="ww_configSaveWeight"/>
 						</Scripts>
 					</Button>
 					<!--Copy button-->
@@ -595,15 +452,8 @@
 							<AbsDimension x="80" y="22"/>
 						</Size>
 						<Scripts>
-							<OnClick>
-								ww_configNewWeight(self:GetParent().weightFrame.category.class, string.format(ww_localization["DEFAULT_COPY_NAME"], self:GetParent().weightFrame.name), self:GetParent().statList)
-							</OnClick>
-							<OnLoad>
-								self:SetText(ww_localization[self:GetText()])
-								local relTo = self:GetParent().saveButton
-								local _, _, _, relToXOffset = relTo:GetPoint(1)
-								self:SetPoint("CENTER", relTo, (self:GetParent():GetWidth() - self:GetWidth() - 2 * relToXOffset) / 3, 0)
-							</OnLoad>
+							<OnClick function="ww_copyWeight"/>
+							<OnLoad function="ww_copyButtonOnLoad"/>
 						</Scripts>
 					</Button>
 					<!--Reset button-->
@@ -619,9 +469,7 @@
 							</Anchor>
 						</Anchors>
 						<Scripts>
-							<OnClick>
-								ww_configResetWeight()
-							</OnClick>
+							<OnClick function="ww_configResetWeight"/>
 						</Scripts>
 					</Button>
 					<!--Delete button-->
@@ -631,15 +479,8 @@
 							<AbsDimension x="80" y="22"/>
 						</Size>
 						<Scripts>
-							<OnClick>
-								ww_configDeleteWeight()
-							</OnClick>
-							<OnLoad>
-								self:SetText(ww_localization[self:GetText()])
-								local relTo = self:GetParent().resetButton
-								local _, _, _, relToXOffset = relTo:GetPoint(1)
-								self:SetPoint("CENTER", relTo, (self:GetWidth() - 2 * relToXOffset - self:GetParent():GetWidth()) / 3, 0)
-							</OnLoad>
+							<OnClick function="ww_configDeleteWeight"/>
+							<OnLoad function="ww_deleteButtonOnLoad"/>
 						</Scripts>
 					</Button>
 					<!--used to hold a series of stat frames to maintain absolute position when scrolling-->
@@ -660,21 +501,13 @@
 							</Anchor>
 						</Anchors>
 						<Scripts>
-							<OnShow>
-								ww_scrollBarUpdate(self, ww_weights.rightPanel.scrollContainer, 22, -30, 22)
-							</OnShow>
-							<OnVerticalScroll>
-								FauxScrollFrame_OnVerticalScroll(self, offset, 22, self:GetScript("OnShow"))
-							</OnVerticalScroll>
+							<OnShow function="ww_weightFrameScrollFrameOnShow"/>
+							<OnVerticalScroll function="ww_scrollFrameOnVerticalScroll"/>
 						</Scripts>
 					</ScrollFrame>
 				</Frames>
 				<Scripts>
-					<OnShow>
-						if not ww_weights.popup then
-							ww_changeFocus(self.scrollContainer.stats[#(self.scrollContainer.stats)])
-						end
-					</OnShow>
+					<OnShow function="ww_weightFrameOnShow"/>
 				</Scripts>
 			</Frame>
 			<!--Close Button for the configuration window-->
@@ -692,15 +525,7 @@
 					<Anchor point="BOTTOMLEFT"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						if ww_weights.rightPanel.weightFrame and ww_defaultVars.weightsList[ww_weights.rightPanel.weightFrame.category.class][ww_weights.rightPanel.weightFrame.name] then
-							StaticPopup_Show("WW_CONFIRM_RESTORE_DEFAULT_WEIGHTS")
-						else
-							ww_configDiscardChanges(function()
-									StaticPopup_Show("WW_CONFIRM_RESTORE_DEFAULT_WEIGHTS")
-								end)
-						end
-					</OnClick>
+					<OnClick function="ww_restoreDefaultWeights"/>
 				</Scripts>
 			</Button>
 			<!--Create new weight button-->
@@ -712,47 +537,13 @@
 					<Anchor point="BOTTOMRIGHT"/>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						ww_configNewWeight()
-					</OnClick>
+					<OnClick function="ww_configNewWeight"/>
 				</Scripts>
 			</Button>
 		</Frames>
 		<Scripts>
-			<OnLoad>
-				self.title:SetText(ww_localization[self.title:GetText()])
-				self.weightsAttribution:SetText(ww_localization[self.weightsAttribution:GetText()])
-				table.insert(UISpecialFrames, self:GetName())
-				function self:SmartHide(func)
-						self.afterHide = func
-						self:Hide()
-					end
-			</OnLoad>
-			<OnHide>
-				if self.reallyClose then
-					self.reallyClose = nil
-					if self.afterHide then
-						self.afterHide()
-					end
-					self.afterHide = nil
-				else
-					self.popup = true
-					self:Show()
-					ww_configDiscardChanges(function()
-							self.reallyClose = true
-							<!-- Safe because ww_configDiscardChanges will save the weight first -->
-							if self.rightPanel:IsShown() then
-								ww_configResetWeight()
-							end
-							self:Hide()
-							if self.afterHide then
-								self.afterHide()
-							end
-							self.afterHide = nil
-						end)
-					self.popup = nil
-				end
-			</OnHide>
+			<OnLoad function="ww_weightsOnShow"/>
+			<OnHide function="ww_weightsOnHide"/>
 		</Scripts>
 	</Frame>
 	<Frame name="ww_newWeight" parent="UIParent" hidden="true" frameStrata="DIALOG">
@@ -801,10 +592,7 @@
 					<Anchor point="LEFT"/>
 				</Anchors>
 				<Scripts>
-					<OnShow>
-						UIDropDownMenu_Initialize(self, ww_ClassDropDownInitialize)
-						UIDropDownMenu_SetSelectedValue(self, WeightsWatcher.player.class)
-					</OnShow>
+					<OnShow function="ww_initializeClassDropDown"/>
 				</Scripts>
 			</Button>
 			<EditBox letters="50" name="$parentEditBox" parentKey="editBox">
@@ -860,30 +648,10 @@
 					</Layer>
 				</Layers>
 				<Scripts>
-					<OnLoad>
-						self:SetTextInsets(5, 5, 0, 0)
-					</OnLoad>
-					<OnTextChanged>
-						if self:GetText() == "" then
-							self:GetParent().createButton:Disable()
-						else
-							self:GetParent().createButton:Enable()
-						end
-					</OnTextChanged>
-					<OnEnterPressed>
-						if StaticPopup_Visible("WW_WEIGHT_EXISTS") then
-							StaticPopup_Hide("WW_WEIGHT_EXISTS")
-						else
-							self:GetParent().createButton:Click()
-						end
-					</OnEnterPressed>
-					<OnEscapePressed>
-						if StaticPopup_Visible("WW_WEIGHT_EXISTS") then
-							StaticPopup_Hide("WW_WEIGHT_EXISTS")
-						else
-							self:GetParent().cancelButton:Click()
-						end
-					</OnEscapePressed>
+					<OnLoad function="ww_editBoxTextInsets"/>
+					<OnTextChanged function="ww_weightNameTextChanged"/>
+					<OnEnterPressed function="ww_weightNameEnterPressed"/>
+					<OnEscapePressed function="ww_weightNameEscapePressed"/>
 				</Scripts>
 			</EditBox>
 			<Button name="$parentCreateButton" parentKey="createButton" inherits="ww_localizedButton" text="Create">
@@ -898,17 +666,7 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						local class = UIDropDownMenu_GetSelectedValue(self:GetParent().dropdown)
-						local name = self:GetParent().editBox:GetText()
-						if ww_vars.weightsList[class][name] then
-							local error = StaticPopup_Show("WW_WEIGHT_EXISTS", ww_classDisplayNames[class], name)
-						else
-							ww_setWeight(class, name, self:GetParent().statList)
-							ww_selectWeight(class, name)
-							self:GetParent():Hide()
-						end
-					</OnClick>
+					<OnClick function="ww_createNewWeight"/>
 				</Scripts>
 			</Button>
 			<Button name="$parentCancelButton" parentKey="cancelButton" inherits="ww_localizedButton" text="Cancel">
@@ -923,19 +681,13 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnClick>
-						self:GetParent():Hide()
-					</OnClick>
+					<OnClick function="ww_hidePopup"/>
 				</Scripts>
 			</Button>
 		</Frames>
 		<Scripts>
-			<OnLoad>
-				self.text:SetText(ww_localization[self.text:GetText()])
-			</OnLoad>
-			<OnShow>
-				self.editBox:SetFocus()
-			</OnShow>
+			<OnLoad function="ww_newWeightLocalizeText"/>
+			<OnShow function="ww_setFocusOnEditBox"/>
 		</Scripts>
 	</Frame>
 </Ui>
diff --git a/widgets.lua b/widgets.lua
new file mode 100644
index 0000000..5b04629
--- /dev/null
+++ b/widgets.lua
@@ -0,0 +1,98 @@
+function ww_leftJustifyDropDownText(self)
+	UIDropDownMenu_JustifyText(self, "LEFT")
+end
+
+function ww_initializeModifierKeyDropDown(self)
+	UIDropDownMenu_Initialize(self, ww_ModifierKeyDropDownInitialize)
+	UIDropDownMenu_SetSelectedValue(self, ww_vars.options.tooltip[self:GetText()])
+end
+
+local function setTextItem(self)
+	if not self.text then
+		self.text = _G[self:GetName() .. "Text"]
+	end
+end
+
+function ww_showTooltip(self, text)
+	GameTooltip:SetOwner(self,"ANCHOR_RIGHT")
+	GameTooltip:AddLine(text, 1, 1, 1)
+	GameTooltip:Show()
+end
+
+function ww_hideTooltip()
+	GameTooltip:Hide()
+end
+
+function ww_localizeText(self)
+	self:SetText(ww_localization[self:GetText()])
+end
+
+function ww_checkButtonDisable(self)
+	setTextItem(self)
+	self.text:SetTextColor(0.5, 0.5, 0.5)
+end
+
+function ww_checkButtonEnable(self)
+	setTextItem(self)
+	self.text:SetTextColor(1, 0.82, 0)
+end
+
+function ww_checkButtonTooltipShow(self)
+	if self.ttText then
+		ww_showTooltip(self, self.ttText)
+	end
+end
+
+function ww_checkButtonTooltipHide(self)
+	if self.ttText then
+		ww_hideTooltip()
+	end
+end
+
+function ww_checkButtonShow(self)
+	setTextItem(self)
+	self.text:SetText(self:GetText())
+end
+
+local function setFontString(self, font)
+	self:SetFontString(self:CreateFontString(nil, "OVERLAY", font))
+end
+
+local function setFontStringIndented(self, font)
+	local fontString = self:CreateFontString(nil, "OVERLAY", font)
+	fontString:SetPoint("LEFT", 20, 0)
+	self:SetFontString(fontString)
+end
+
+function ww_normalFontString(self)
+	setFontStringIndented(self, "GameFontNormal")
+end
+
+function ww_highlightFontString(self)
+	setFontStringIndented(self, "GameFontHighlight")
+end
+
+function ww_defaultFontString(self)
+	setFontString(self, "ww_defaultString")
+end
+
+function ww_editBoxTextInsets(self)
+	self:SetTextInsets(5, 5, 0, 0)
+end
+
+function ww_clearFocus(self)
+	self:ClearFocus()
+end
+
+function ww_refreshCheckBoxes(checkBoxes)
+	for _, checkBox in pairs(checkBoxes) do
+		checkBox:SetChecked(checkBox.shouldBeChecked())
+		if checkBox.shouldBeEnabled then
+			if checkBox.shouldBeEnabled() then
+				checkBox:Enable()
+			else
+				checkBox:Disable()
+			end
+		end
+	end
+end
diff --git a/widgets.xml b/widgets.xml
index 9a6dd2f..7aa415f 100644
--- a/widgets.xml
+++ b/widgets.xml
@@ -1,5 +1,6 @@
 <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 		xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
+	<Script file="widgets.lua"/>
 	<Frame name="ww_borderedFrame" virtual="true">
 		<Backdrop edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true">
 			<EdgeSize>
@@ -42,13 +43,8 @@
 					</Anchor>
 				</Anchors>
 				<Scripts>
-					<OnLoad>
-						UIDropDownMenu_JustifyText(self, "LEFT")
-					</OnLoad>
-					<OnShow>
-						UIDropDownMenu_Initialize(self, ww_ModifierKeyDropDownInitialize)
-						UIDropDownMenu_SetSelectedValue(self, ww_vars.options.tooltip[self:GetText()])
-					</OnShow>
+					<OnLoad function="ww_leftJustifyDropDownText"/>
+					<OnShow function="ww_initializeModifierKeyDropDown"/>
 				</Scripts>
 			</Button>
 		</Frames>
@@ -70,36 +66,11 @@
 			</Anchor>
 		</Anchors>
 		<Scripts>
-			<OnDisable>
-				if not self.text then
-					self.text = _G[self:GetName() .. "Text"]
-				end
-				self.text:SetTextColor(0.5, 0.5, 0.5)
-			</OnDisable>
-			<OnEnable>
-				if not self.text then
-					self.text = _G[self:GetName() .. "Text"]
-				end
-				self.text:SetTextColor(1, 0.82, 0)
-			</OnEnable>
-			<OnEnter>
-				if self.ttText then
-					GameTooltip:SetOwner(self,"ANCHOR_RIGHT")
-					GameTooltip:AddLine(self.ttText, 1, 1, 1)
-					GameTooltip:Show()
-				end
-			</OnEnter>
-			<OnLeave>
-				if self.ttText then
-					GameTooltip:Hide()
-				end
-			</OnLeave>
-			<OnShow>
-				if not self.text then
-					self.text = _G[self:GetName() .. "Text"]
-				end
-				self.text:SetText(self:GetText())
-			</OnShow>
+			<OnDisable function="ww_checkButtonDisable"/>
+			<OnEnable function="ww_checkButtonEnable"/>
+			<OnEnter function="ww_checkButtonTooltipShow"/>
+			<OnLeave function="ww_checkButtonTooltipHide"/>
+			<OnShow function="ww_checkButtonShow"/>
 		</Scripts>
 	</CheckButton>
 	<FontString name="ww_headerFont" inherits="GameFontNormalLarge" virtual="true">
@@ -120,9 +91,7 @@
 	<!-- Localizes the button text automatically -->
 	<Button name="ww_localizedButton" inherits="UIPanelButtonTemplate" virtual="true">
 		<Scripts>
-			<OnLoad>
-				self:SetText(ww_localization[self:GetText()])
-			</OnLoad>
+			<OnLoad function="ww_localizeText"/>
 		</Scripts>
 	</Button>
 	<!-- Adds a border that can be hidden/shown as a unit -->