﻿(function($) { $.fantasyleague.articles = { settings: { groupDropDownId: '', hfSubGroupId: '', hfGroupId: '', bodyId: '', articleImagesUrl: '', widgetHtml: '', localPath: '', groupIdParam: '', threadIdParam: '', tagParam: '', hasShowAllFilter: false }, articleGroups: null, init: function(groupDropDownId, articleGroups, hfSubGroupId, createImageUrl, browseImagesUrl, bodyId, articleImagesUrl, widgetHtml) { $.fantasyleague.articles.settings.groupDropDownId = groupDropDownId; $.fantasyleague.articles.settings.hfSubGroupId = hfSubGroupId; $.fantasyleague.articles.settings.bodyId = bodyId; $.fantasyleague.articles.settings.articleImagesUrl = articleImagesUrl; $.fantasyleague.articles.settings.widgetHtml = widgetHtml; $.fantasyleague.articles.articleGroups = articleGroups; $.fantasyleague.articles.onGroupChange(document.getElementById($.fantasyleague.articles.settings.groupDropDownId)); $("#" + $.fantasyleague.articles.settings.hfSubGroupId).attr("value", $("#selSubGroups").find(':selected').attr("value")); $("#" + $.fantasyleague.articles.settings.groupDropDownId).bind("change", function(e) { $.fantasyleague.articles.onGroupChange(this) }); $("#selSubGroups").bind("change", function(e) { $.fantasyleague.articles.onSubGroupChange(this) }); $("#hlCreateImage").bind("click", function(e) { $.fantasyleague.popups.open(createImageUrl, '0', '0', '0', '0', '0', '0', 'yes', '800px', '600px', '_wArticleImage') }); $("#hlBrowseImages").bind("click", function(e) { $.fantasyleague.popups.open(browseImagesUrl, '0', '0', '0', '0', '0', '0', 'yes', '800px', '600px', '_wArticleImage') }) }, initBrowse: function(groupDropDownId, articleGroups, hfGroupId, hfSubGroupId, hasShowAllFilter, selectedGroupId, selectedSubGroupId, localPath, groupIdParam, threadIdParam, tagParam) { $.fantasyleague.articles.settings.groupDropDownId = groupDropDownId; $.fantasyleague.articles.settings.hfSubGroupId = hfSubGroupId; $.fantasyleague.articles.settings.hfGroupId = hfGroupId; $.fantasyleague.articles.settings.hasShowAllFilter = hasShowAllFilter; $.fantasyleague.articles.settings.localPath = localPath; $.fantasyleague.articles.settings.groupIdParam = groupIdParam; $.fantasyleague.articles.settings.threadIdParam = threadIdParam; $.fantasyleague.articles.settings.tagParam = tagParam; $.fantasyleague.articles.articleGroups = articleGroups; var d; var i; if (selectedGroupId !== null && selectedGroupId.length > 0) { d = document.getElementById($.fantasyleague.articles.settings.groupDropDownId); for (i = 0; i < d.options.length; i++) { if (d.options[i].value == selectedGroupId) { d.selectedIndex = i } } } $.fantasyleague.articles.onGroupChange(document.getElementById($.fantasyleague.articles.settings.groupDropDownId)); if (selectedSubGroupId !== null && selectedSubGroupId.length > 0) { d = document.getElementById("selSubGroups"); for (i = 0; i < d.options.length; i++) { if (d.options[i].value == selectedSubGroupId) { d.selectedIndex = i } } } $.fantasyleague.articles.enableDisableSubGroups(); $("#" + $.fantasyleague.articles.settings.hfGroupId).attr("value", selectedGroupId); $("#" + $.fantasyleague.articles.settings.hfSubGroupId).attr("value", selectedSubGroupId); $("#" + $.fantasyleague.articles.settings.groupDropDownId).bind("change", function(e) { $.fantasyleague.articles.onGroupChange(this) }); $("#selSubGroups").bind("change", function(e) { $.fantasyleague.articles.onSubGroupChange(this) }) }, initEdit: function(createImageUrl, browseImagesUrl, bodyId, articleImagesUrl, widgetHtml) { $.fantasyleague.articles.settings.bodyId = bodyId; $.fantasyleague.articles.settings.articleImagesUrl = articleImagesUrl; $.fantasyleague.articles.settings.widgetHtml = widgetHtml; $("#hlCreateImage").bind("click", function(e) { $.fantasyleague.popups.open(createImageUrl, '0', '0', '0', '0', '0', '0', 'yes', '800px', '600px', '_wArticleImage') }); $("#hlBrowseImages").bind("click", function(e) { $.fantasyleague.popups.open(browseImagesUrl, '0', '0', '0', '0', '0', '0', 'yes', '800px', '600px', '_wArticleImage') }); $.fantasyleague.articles.showPreview() }, onGroupChange: function(sender) { $.fantasyleague.articles.enableDisableSubGroups(); var o = ''; for (var i = 0; i < $.fantasyleague.articles.articleGroups[sender.selectedIndex].length; i++) { o += '<option value="' + $.fantasyleague.articles.articleGroups[sender.selectedIndex][i].v + '">' + $.fantasyleague.articles.articleGroups[sender.selectedIndex][i].t + '</option>' } $("#selSubGroups").html(o); if ($.fantasyleague.articles.settings.hasShowAllFilter) { $("#" + $.fantasyleague.articles.settings.hfGroupId).attr("value", sender.options[sender.selectedIndex].value) } $("#" + $.fantasyleague.articles.settings.hfSubGroupId).attr("value", $("#selSubGroups").find(':selected').attr("value")) }, onSubGroupChange: function(sender) { $("#" + $.fantasyleague.articles.settings.hfSubGroupId).attr("value", sender.options[sender.selectedIndex].value) }, showHTML: function() { $("#htmlWrapper").show(); $("#previewWrapper").hide() }, showPreview: function() { var content = $("#" + $.fantasyleague.articles.settings.bodyId).attr("value"); content = content.replace(new RegExp('<image[^>]*>([0-9]*)</image>', "g"), '<img border="0" src="' + $.fantasyleague.articles.settings.articleImagesUrl + '" />'); content = content.replace(new RegExp('<articlewidget />', "g"), $.fantasyleague.articles.settings.widgetHtml); $("#previewWrapper").html(content); $("#previewWrapper").show(); $("#htmlWrapper").hide() }, enableDisableSubGroups: function() { if ($.fantasyleague.articles.settings.hasShowAllFilter && $("#" + $.fantasyleague.articles.settings.groupDropDownId)[0].selectedIndex === 0) { $("#selSubGroups").attr('disabled', true) } else { $("#selSubGroups").attr('disabled', false) } }, onSearchClick: function() { document.location = $.fantasyleague.articles.settings.localPath + "?" + $.fantasyleague.articles.settings.groupIdParam + "=" + $("#" + $.fantasyleague.articles.settings.hfGroupId).attr("value") + "&" + $.fantasyleague.articles.settings.threadIdParam + "=" + $("#" + $.fantasyleague.articles.settings.hfSubGroupId).attr("value") + "&" + $.fantasyleague.articles.settings.tagParam + "=" + encodeURIComponent($("#searchBox").attr("value")) }, onShowAllClick: function() { document.location = $.fantasyleague.articles.settings.localPath + "?" + $.fantasyleague.articles.settings.groupIdParam + "=" + $("#" + $.fantasyleague.articles.settings.hfGroupId).attr("value") + "&" + $.fantasyleague.articles.settings.threadIdParam + "=" + $("#" + $.fantasyleague.articles.settings.hfSubGroupId).attr("value") + "&" + $.fantasyleague.articles.settings.tagParam + "=" } } })(jQuery);
