1(function (namespace) { // RSS Behavior Common Code. Used for the process of showing or not showing items in RSS feeds. 2 'use strict'; 3 4 var config = { 5 selector: { 6 rssBehavior: '[name=RssBehavior]', 7 showInRssFeed: "[name='ShowInRssFeed']", 8 rssConfigurationEnabled: '[name=RssConfigurationEnabled]', 9 $rssBehaviorMultipleCategory: function (categoryId) { return $("[name='RssBehavior." + categoryId + "']"); } 10 }, 11 localization: { 12 includeInRssFeedQuestion: 'Would you like to include this in the RSS feed? Click OK to include it. Click Cancel to exclude it.' 13 }, 14 attributes: { 15 addItemBehavior: 'data-add-item-behavior', 16 modifyItemBehavior: 'data-modify-item-behavior' 17 } 18 }; 19 20 /* Description: Asks the user about RSS behavior and sets a standard field for it if needed ([name='ShowInRssFeed']). Also supports multi category contexts. 21 Requirements for use: 22 For any use case you must define a hidden input field [name='ShowInRssFeed']". 23 For item modifies within the context of a single category you must define a hidden input indicating the rss behavior for the category [Name=RssBehavior}] 24 For multicategory selection you must define a hidden input indicating the RSS behavior for a given category [Name=RssBehavior.{categoryId}] 25 26 Example Markup: 27 <input type="hidden" name="RssBehavior" data-modify-item-behavior="0" data-add-item-behavior="0"> <!-- For contexts where multiple categories do not exist. 28 <input type="hidden" name="RssBehavior.81" data-modify-item-behavior="0" data-add-item-behavior="0"> <!-- 81 should be swapped with the category id --> 29 30 Example Usage (all of these will set [name='ShowInRssFeed'] as appropriate; should be called before sending server data; server should save data in field name "ShowInRssFeed" to the item): 31 SetFieldForRssBehavior({ categoryId: 5, add:true }); 32 SetFieldForRssBehavior({ modify: true }); 33 SetFieldForRssBehavior({ add: true }); 34 SetFieldForRssBehavior({ add: true, showInRssFeedSelector: 'Agenda.ShowInRssField' }); // Overrides the default selector for ShowInRssField 35 */ 36 namespace.SetFieldForRssBehavior = function (options) { 37 options = options || {}; 38 validateOptions(options); // prevent the developer using this function from doing something silly. 39 cloneInElementsFromParentWindowIfNeeded(); 40 if (!verifyRssConfiguration()) { 41 return; 42 } 43 var $rssBehavior = $(config.selector.rssBehavior); 44 45 config.selector.showInRssFeed = options.showInRssFeedSelector || config.selector.showInRssFeed; // override selector for show in rss field if needed. 46 47 if (options.categoryId) { 48 $rssBehavior = config.selector.$rssBehaviorMultipleCategory(options.categoryId); 49 if (!$rssBehavior.length) { 50 console.warn("A category was passed, but the required fields were not setup. (Expected " + config.selector.$rssBehaviorMultipleCategory(options.categoryId).selector + "); Falling back to general setting ("+config.selector.rssBehavior+")"); 51 $rssBehavior = $(config.selector.rssBehavior); 52 if (!$rssBehavior.length) { 53 throw "Required fields were not setup. Rss beahavior is unabled to be determined. Expected " + $rssBehavior.selector; 54 } 55 } 56 } 57 58 UpdateShowInRssFeed($rssBehavior, options.add, options.modify); 59 }; 60 61 function verifyRssConfiguration() { 62 var $showInRssFeed = $(config.selector.showInRssFeed); 63 var $rssConfigurationEnabled = $(config.selector.rssConfigurationEnabled); 64 if (!$rssConfigurationEnabled.length) { 65 66 throw "Rss configuration (the module parameter setting) was not enabled or disabled. Please define " + config.selector.rssConfigurationEnabled; 67 } 68 if ($rssConfigurationEnabled.val().toLowerCase() === 'false') { 69 $showInRssFeed.val('true'); 70 return false; 71 } 72 return true; 73 } 74
75 // This function is added "robustness". Basically some partials are reused inside LiveEdit IFrames on the front end; but also used on the backend. We also have common wrappers. 76 // I ran into a problem where I had to have these fields in the common wrapper because the wrapper itself needed it; but cannot have it in the child partials without a bunch of filtering as then 77 // sometimes multiple elements of the same name occur breaking equality comparisions (e.g. duplicate fields go to server as "true,true" as opposed to "true" for a single one). 78 // This function will clone in needed elements from the parent for the duration of an iframe session if needed. 79 function cloneInElementsFromParentWindowIfNeeded() { 80 if (window !== top) { // if this is an iframe 81 var $jQueryParent = window.parent.$; 82 var $showInRssFeed = $(config.selector.showInRssFeed); 83 var $showInRssFeedParent = $jQueryParent(config.selector.showInRssFeed); 84 var $rssConfigurationEnabled = $(config.selector.rssConfigurationEnabled); 85 var $rssConfigurationEnabledParent = $jQueryParent(config.selector.rssConfigurationEnabled); 86 var $rssBehaviors = $('[' + config.attributes.addItemBehavior + ']'); 87 var $rssBehaviorsParent = $jQueryParent('[' + config.attributes.addItemBehavior + ']'); 88 89 if (!$showInRssFeed.length && $showInRssFeedParent.length) { // if show in rss feed exists in parent window but not in our window; let's clone it. 90 $(document.forms).prepend($showInRssFeedParent.clone()); 91 } 92 93 if (!$rssConfigurationEnabled.length && $rssConfigurationEnabledParent.length) { // if rss configuration in rss feed exists in parent window but not in our window; let's clone it. 94 $(document.forms).prepend($rssConfigurationEnabledParent.clone()); 95 } 96 97 if (!$rssBehaviors.length && $rssBehaviorsParent.length) { // if rss behaviors exist in parent window but not in our window; let's clone them. 98 $(document.forms).prepend($rssBehaviorsParent.clone()); 99 } 100 } 101 } 102 103 function askUserAboutRss() { 104 var $showInRssFeed = $(config.selector.showInRssFeed); 105 if (!$showInRssFeed.length) { 106 throw "ShowInRssFeed field is not defined. Expected " + $showInRssFeed.selector; 107 } 108 109 if (confirm(config.localization.includeInRssFeedQuestion)) { 110 $showInRssFeed.val('true'); 111 } else { 112 $showInRssFeed.val('false'); 113 } 114 } 115 116 // Primarily a helper for multiple category situations. 117 namespace.UpdateShowInRssFeed = function ($rssBehavior, add, modify) { 118 var $showInRssFeed = $(config.selector.showInRssFeed); 119 120 121 if (add) { 122 if (!$rssBehavior.is("[" + config.attributes.modifyItemBehavior + "]")) { 123 throw "Modify behavior was not set. Please set [or check spelling of] attribute " + config.attributes.addItemBehavior + ' on ' + $rssBehavior.selector; 124 } 125 126 if ($rssBehavior.attr(config.attributes.addItemBehavior) === "0" || $rssBehavior.attr(config.attributes.addItemBehavior) === 'AlwaysAsk') { 127 askUserAboutRss(); 128 } else { 129 $showInRssFeed.val($rssBehavior.attr(config.attributes.addItemBehavior) === '1' || $rssBehavior.attr(config.attributes.addItemBehavior) === 'IncludeInRssFeed'); 130 } 131 } else if (modify) { 132 if (!$rssBehavior.is("[" + config.attributes.modifyItemBehavior + "]")) { 133 throw "Modify behavior was not set. Please set [or check spelling of] attribute " + config.attributes.modifyItemBehavior + ' on ' + $rssBehavior.selector; 134 } 135 136 if ($rssBehavior.attr(config.attributes.modifyItemBehavior) === '0' || $rssBehavior.attr(config.attributes.modifyItemBehavior) === 'AlwaysAsk') { 137 askUserAboutRss(); 138 } else { 139 $showInRssFeed.val($rssBehavior.attr(config.attributes.modifyItemBehavior) === '1' || $rssBehavior.attr(config.attributes.modifyItemBehavior) === 'IncludeInRssFeed'); 140 } 141 } else { 142 throw "Add or Modify was not specified. The caller of this function should specify one."; 143 } 144 }; 145 146 function validateOptions(options) { 147 if (!options.modify && !options.add) { 148 throw "The caller of this function must declare if this operation is adding or modifying."; 149 } 150 if (options.modify && options.add) { 151 throw "The caller of this function cannot simulataneously be adding and modifying an item for rss behavior."; 152 } 153 } 154 155 // 156 namespace.checkForRssPrompt = function (selector) { 157 var $rssBehavior = $(selector); 158 if (!$rssBehavior.length) { 159 throw "ShowInRssFeed field is not defined. Expected " + $rssBehavior.selector; 160 } 161 162 if ($rssBehavior.val() == '0') { 163 showInRssFeed = confirm(config.localization.includeInRssFeedQuestion); 164 } else { 165 showInRssFeed = $rssBehavior.val() == '1'; 166 } 167 return showInRssFeed; 168 }; 169 170 // 171 namespace.attachRssPromptHandlersForSave = function () { 172 $(document).ready(function () { 173 $('.bigButton.nextAction.modify').unbind('click').click(function (e) { 174 var rssBehaviorModifyItems = checkForRssPrompt("#RssBehaviorModifyItems") ? '1' : '2'; 175 $('#RssBehaviorModifyItems').val(rssBehaviorModifyItems); 176 }); 177 }); 178 }; 179 180 // 181 namespace.handleRssSaveAndSend = function (isPublish) { 182 showInRssFeed = checkForRssPrompt(isPublish ? '#RssBehaviorAddItems' : '#RssBehaviorModifyItems'); 183 $('#ShowInRssFeed').val(showInRssFeed ? "1" : "0"); 184 }; 185 186 namespace.showInRssFeed = true; 187}(window));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.