1function ContentCollectionClass() { 2 this.PageID = null; 3 this.ParentID = null; 4 this.IsLayoutPage = false; 5 this.VersionID = null; 6 this.StructureID = null; 7 this.ThemeID = null; 8 this.ModuleID = null; 9 this.IsWorkingCopy = $('#hdnIsWorkingCopy').val() === 'True'; //Only the first load this property would be initialized in this way 10 this.ContentCollectionID = null; 11 this.CurrentContentContainerIDs = []; 12 this.PostRefreshClickTargets = []; 13 this.resources = null; 14 this.newTabData = null; 15 this.RelatedDocumentWidgetIDToEdit = null; 16 this.RelatedDocumentSectionID = null; 17 this.PageStatus = null; 18} 19 20ContentCollectionClass.prototype.init = function () { 21 if ($('#hdnPageID').length == 1) 22 this.PageID = $('#hdnPageID').val(); 23 if ($('#hdnVersionID').length == 1) 24 this.VersionID = $('#hdnVersionID').val(); 25 if ($('#hdnParentID').length == 1) 26 this.ParentID = $('#hdnParentID').val(); 27 this.IsLayoutPage = ($('#hdnIsLayoutPage').length == 1) && ($('#hdnIsLayoutPage').val() === "True"); 28 this.StructureID = $('#hdnStructureID').val(); 29 this.ThemeID = $('#hdnThemeID').val(); 30 if ($('#hdnModuleID').length == 1 && $('#hdnModuleID').val() != "0" && $('#hdnModuleID').val() != "") 31 this.ModuleID = $('#hdnModuleID').val(); 32 if ($('#hdnContentCollectionID').length == 1) 33 this.ContentCollectionID = $('#hdnContentCollectionID').val(); 34 if ($('#hdnPageStatus').length == 1) 35 this.PageStatus = $('#hdnPageStatus').val(); 36 this.CurrentContentContainerIDs = []; 37 if (this.resources == null) { 38 this.resources = GetJson("/ContentLocalization/Index"); 39 } 40 window.imageRepository = new ImageRepositoryClass(); 41 this.initializeExternalAPI(); 42}; 43 44ContentCollectionClass.prototype.reloadContent = function (refreshNavContainers, contentRefreshedCallback, ignore) { 45 if ((ContentCollectionInstance.IsWorkingCopy 46 || $('#cc' + ContentCollectionInstance.CurrentContentContainerIDs[0]).parents('.megaMenuContainer').length == ContentCollectionInstance.CurrentContentContainerIDs.length 47 ) 48 && ContentCollectionInstance.CurrentContentContainerIDs != null 49 && ContentCollectionInstance.CurrentContentContainerIDs.length > 0) { 50 refreshContentContainers(contentRefreshedCallback, ignore); 51 } 52 else { 53 //force to refresh all content Containers. 54 ContentCollectionInstance.CurrentContentContainerIDs = []; 55 $('.pageContent').each(function () { 56 var $this = $(this); 57 if ($this.parents('.megaMenu').length == 0) { 58 ContentCollectionInstance.CurrentContentContainerIDs.push($this.data('containerid')); 59 } 60 }); 61 refreshContentContainers(contentRefreshedCallback, ignore); 62 if (refreshNavContainers) { 63 ContentCollectionInstance.refreshNavContainers(); 64 } 65 } 66 $('a[href*="#"]:not([href="#"]):not(.tabButton)').click(function () { 67 if ($(this)[0].target == '_blank') { 68 window.location = $(this)[0].href; 69 } else { 70 if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { 71 smoothScroll(this.hash); 72 } 73 } 74 }); 75 flipHandlesIfNecessary(); 76}; 77 78function displayGroupAndHideOthers(group, $carouselWidget, doEffect) { 79 doEffect = doEffect || false; 80 var transition = $carouselWidget.data('transition'); 81 var $groupToShow = $('[data-group="' + group + '"].widgetCarousel-group', $carouselWidget); 82 var $otherGroups = $('.widgetCarousel-group:not([data-group="' + group + '"])', $carouselWidget); 83 84 $otherGroups.removeClass('currentGroup'); 85 $groupToShow.addClass('currentGroup'); 86 87 if (!doEffect) { 88 if (transition === 'fade') { 89 $otherGroups.css('opacity', 0).css('z-index', 1); 90 $groupToShow.css('opacity', 1).css('z-index', 2); 91 } else { 92 $carouselWidget.find('.widgetCarousel-slider').css('left', ((group - 1) * -100) + '%'); 93 } 94 } else { 95 var transitionTiming = $carouselWidget.data('transitiontiming'); 96 if (transition === 'fade') { 97 $otherGroups.animate({ opacity: 0 }, transitionTiming * 1000, function () { 98 $(this).css('z-index', 1); 99 }); 100 $groupToShow.animate({ opacity: 1 }, transitionTiming * 1000, function () { 101 $(this).css('z-index', 2); 102 }); 103 } else { 104 $carouselWidget.find('.widgetCarousel-slider').animate({ left: ((group - 1) * -100) + '%' }, transitionTiming * 1000); 105 } 106 } 107 108 var $nextArrow = $('.widgetCarousel-next', $carouselWidget); 109 var $previousArrow = $('.widgetCarousel-previous', $carouselWidget); 110 $nextArrow[(group === parseInt($nextArrow.data('disabledatgroup'), 10)) ? 'addClass' : 'removeClass']("disabled"); 111 $previousArrow[(group === parseInt($previousArrow.data('disabledatgroup'), 10)) ? 'addClass' : 'removeClass']("disabled"); 112 113 carouselWidgetAdjustArrows($carouselWidget); 114 115 var $pager = $carouselWidget.find('.semanticList.pager'); 116 $pager.find('.active').removeClass('active'); 117 $pager.find('[data-group="' + group + '"].widgetCarouselPaging').parent().addClass('active'); 118 119 if (!window.isRemoveSetHeights) 120 SetHeights();
121 if (typeof window.dynamicStretchContainers === 'function') window.dynamicStretchContainers(); 122} 123 124function carouselWidgetAdjustArrows($carouselWidget) { 125 var $group = $('.widgetCarousel-group.currentGroup', $carouselWidget); 126 var $nextArrow = $('.widgetCarousel-next', $carouselWidget); 127 var $previousArrow = $('.widgetCarousel-previous', $carouselWidget); 128 129 var centerCss = 'translateY(' + (($group.height() / 2) + 15) + 'px)'; 130 $previousArrow.children('svg') 131 .add($nextArrow.children('svg')) 132 .css({ 133 '-webkit-transform': centerCss, 134 '-ms-transform': centerCss, 135 '-o-transform': centerCss, 136 'transform': centerCss 137 }); 138} 139 140function refreshContentContainers(callback, ignore) { 141 var url = '/Content/ContentCollectionID?moduleID={0}&versionID={1}' 142 .replace('{0}', ContentCollectionInstance.ModuleID) 143 .replace('{1}', ContentCollectionInstance.VersionID); 144 var reloadLinkedVersion = false; 145 $.ajax({ 146 url: url, 147 type: 'POST', 148 async: false, 149 success: function (response) { 150 if (response.ErrorMessage) 151 alert(response.ErrorMessage); 152 else if (response.ContentCollectionID == '00000000-0000-0000-0000-000000000000' && ContentCollectionInstance.VersionID > 0 && ContentCollectionInstance.PageID) { 153 reloadLinkedVersion = true; 154 } else { 155 $('#hdnContentCollectionID').val(response.ContentCollectionID); 156 ContentCollectionInstance.ContentCollectionID = response.ContentCollectionID; 157 } 158 }, 159 error: function (xhr, textStatus, exception) { 160 alert('Error: ' + xhr.statusText + '\nStatus: ' + xhr.status); 161 } 162 }); 163 164 if (reloadLinkedVersion) { 165 //Reloading linked versions by ajax might need to refactor /Content/Load to retrieve content depending on VersionID too. 166 document.location.href = "/{0}/{1}" 167 .replace("{0}", ContentCollectionInstance.PageID) 168 .replace("{1}", ContentCollectionInstance.VersionID); 169 return; 170 } 171 172 if (ContentCollectionInstance.CurrentContentContainerIDs.length > 0 && ContentCollectionInstance.ContentCollectionID != "00000000-0000-0000-0000-000000000000") { 173 $.ajax({ 174 url: '/Content/Load?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + "&StructureID=" + ContentCollectionInstance.StructureID + "&themeID=" + ContentCollectionInstance.ThemeID, 175 type: 'POST', 176 data: JSON.stringify({ "contentContainerIDs": ContentCollectionInstance.CurrentContentContainerIDs }), 177 contentType: 'application/json', 178 cache: false, 179 async: false, //Seems we need to have this as synchronus call since it is called from several places and data needs to be already initialized 180 error: function (xhr, textStatus, exception) { 181 alert("Error: " + xhr.statusText + "\nStatus: " + xhr.status); 182 }, 183 success: function (response) { 184 if (response.ErrorMessage) 185 alert(response.ErrorMessage); 186 else { 187 $('.actionable').removeClass('displayed'); 188 $('#divVersion' + ContentCollectionInstance.VersionID).addClass('displayed'); 189 $('#hdnVersionID').val(ContentCollectionInstance.VersionID); 190 ContentCollectionInstance.disposeExternalAPI(); 191 192 //Replace content containers HTML 193 var root = document.createElement("div"); 194 root.innerHTML = response; 195 ContentCollectionInstance.IsWorkingCopy = $(root).find('div.isWorkingCopy').html() == 'True'; 196 $(root).find('#fb-root').remove(); 197 var allChilds = root.childNodes; 198 for (var i = 0; i < ContentCollectionInstance.CurrentContentContainerIDs.length; i++) { 199 var contentContainerID = ContentCollectionInstance.CurrentContentContainerIDs[i]; 200 //Grab Content Container HTML from response 201 var contentContainerHtml = null; 202 for (var j = 0; j < allChilds.length; j++) { 203 if (allChilds[j].id && allChilds[j].id == 'cc' + contentContainerID) { 204 contentContainerHtml = allChilds[j].outerHTML; 205 break; 206 } 207 } 208 if (contentContainerHtml != null) { 209 var $contentContainer = $('#cc' + contentContainerID); 210 var isPinned = $contentContainer.hasClass('pinned'); 211 $contentContainer.empty().replaceWith(contentContainerHtml); 212 if (isPinned) { 213 $contentContainer = $('#cc' + contentContainerID);
214 menuManager.pinMegaMenuOpen($contentContainer.children(':first')); 215 } 216 } else { 217 //ContentContainer Html was not found. This might happen when we have a html version and switch (Refresh containers) to a linked version on the same page. 218 } 219 } 220 221 //TODO: unbind/destroy events/drag/drop on elements before initialize containers 222 if (getCookieValue("enableLiveEdit") === "true") { 223 InitializeContainers(); 224 } 225 226 if (!ignore) { 227 contentUpdated(); 228 } 229 ContentCollectionInstance.initializeExternalAPI(); 230 } 231 }, 232 complete: function () { 233 ContentCollectionInstance.refreshVersionTitle(); 234 $(window.Pages).trigger('ContentReload'); 235 if (callback) { 236 callback(); 237 } 238 } 239 }); 240 } 241} 242 243ContentCollectionClass.prototype.refreshVersionTitle = function () { 244 var title = $('.item.displayed h2 a', "#liveEditTab_versionsList").text(); 245 if (!title) 246 title = $('#versionHeadLine').find('span').attr('data-versiontitle'); 247 if ($('#versionHeadLine span').length > 0) {
248 $('#versionHeadLine span').text(title); 249 $('#versionHeadLine span').data('versiontitle', title); 250 } else { 251 $('#versionHeadLine').text(title); 252 } 253}; 254 255ContentCollectionClass.prototype.initializeExternalAPI = function () { 256 if (window.FB != undefined) { 257 //This is to handle FB initialization when page refreshes by ajax on Live Edit. For live edit off, FB code on custom widget should handle the initialization using window.fbAsyncInit. Ref: https://developers.facebook.com/docs/javascript/quickstart/v2.3 258 window.FB.init({ xfbml: true, version: 'v2.3' }); 259 window.FB.XFBML.parse($('.fb-like-box').parent().get(0)); 260 } 261}; 262 263ContentCollectionClass.prototype.disposeExternalAPI = function () { 264 $('#twitter-wjs, #facebook-jssdk').each(function () { 265 $(this).remove(); 266 }); 267}; 268 269ContentCollectionClass.prototype.buildWidgetOption = function (widgetID, name, value, moduleWidgetOptionSetOptionID) { 270 return { "WidgetID": widgetID.toUpperCase(), "Name": name, "Value": value, "ModuleWidgetOptionSetOptionID": moduleWidgetOptionSetOptionID }; 271}; 272 273ContentCollectionClass.prototype.refreshNavContainers = function () { 274 menuManager.resetSubMenus(); 275 //Always load first main nav 276 ContentCollectionInstance.refreshNavContainer($(".siteNav.mainNav")); 277 $(".siteNav:not('#divListSubMenus, .mainNav')").each(function () { 278 ContentCollectionInstance.refreshNavContainer($(this)); 279 }); 280}; 281 282ContentCollectionClass.prototype.refreshNavContainer = function ($nav) { 283 var menuContainerID = $nav.attr('id'); 284 var megaMenu = $('#megaMenu').detach(); 285 286 $.ajax({ 287 url: '/Content/LoadNavigation', 288 async: false, 289 type: 'POST', 290 data: { "themeID": ContentCollectionInstance.ThemeID, "pageID": ContentCollectionInstance.PageID, "moduleID": ContentCollectionInstance.ModuleID, "menuContainerID": menuContainerID }, 291 cache: false, 292 error: function (xhr, textStatus, exception) { 293 alert("Error: " + xhr.statusText + "\nStatus: " + xhr.status); 294 }, 295 success: function (response) { 296 if (response.ErrorMessage) 297 alert(response.ErrorMessage); 298 else { 299 $('#' + menuContainerID).html(response); 300 } 301 302 $('#mainNav').append(megaMenu); 303 } 304 }); 305}; 306 307function ResizeClass() { 308 this.ContentWidth = 0; 309 this.ColumnWidth = 0; 310 this.Prev = null; 311 this.Next = null; 312 this.TotalShift = 0; 313 this.MinContainerWidthToEnableRightAndLeftTargets = 0; 314} 315 316ResizeClass.prototype.init = function ($pageContent) { 317 ResizeData.ContentWidth = $pageContent.width(); 318 ResizeData.ColumnWidth = ResizeData.ContentWidth / 24 | 0; 319 ResizeData.MinContainerWidthToEnableRightAndLeftTargets = 200; 320}; 321 322$(document).ready(function () { 323 if (!window.ContentCollectionInstance) { 324 window.ContentCollectionInstance = new ContentCollectionClass(); 325 window.ContentCollectionInstance.init(); 326 } 327 328 if (!window.ResizeData) { 329 window.ResizeData = new ResizeClass(); 330 } 331 InitializeContainers(); 332}); 333 334function GetColumnWidth($column) { 335 if ($column.hasClass('col1')) { 336 return 1; 337 } if ($column.hasClass('col2')) { 338 return 2; 339 } if ($column.hasClass('col3')) { 340 return 3; 341 } if ($column.hasClass('col4')) { 342 return 4; 343 } if ($column.hasClass('col5')) { 344 return 5; 345 } if ($column.hasClass('col6')) { 346 return 6; 347 } if ($column.hasClass('col7')) { 348 return 7; 349 } if ($column.hasClass('col8')) { 350 return 8; 351 } if ($column.hasClass('col9')) { 352 return 9; 353 } if ($column.hasClass('col10')) { 354 return 10; 355 } if ($column.hasClass('col11')) { 356 return 11; 357 } if ($column.hasClass('col12')) { 358 return 12; 359 } if ($column.hasClass('col13')) { 360 return 13; 361 } if ($column.hasClass('col14')) { 362 return 14; 363 } if ($column.hasClass('col15')) { 364 return 15; 365 } if ($column.hasClass('col16')) { 366 return 16; 367 } if ($column.hasClass('col17')) { 368 return 17; 369 } if ($column.hasClass('col18')) { 370 return 18; 371 } if ($column.hasClass('col19')) { 372 return 19; 373 } if ($column.hasClass('col20')) { 374 return 20; 375 } if ($column.hasClass('col21')) { 376 return 21; 377 } if ($column.hasClass('col22')) { 378 return 22; 379 } if ($column.hasClass('col23')) { 380 return 23; 381 } if ($column.hasClass('col24')) { 382 return 24; 383 } 384} 385 386function GetSibling($current, getPrevious, moveLeft) { 387 var found = false; 388 var width = 0; 389 var widgetContainerID = 0; 390 var $sibling = getPrevious ? $current.prev() : $current.next().next(); 391 392 if ((getPrevious && !moveLeft) || (!getPrevious && moveLeft)) { 393 found = true; 394 } 395 396 while (!found && $sibling.length > 0) { 397 if ($sibling.hasClass('col') && GetColumnWidth($sibling) > MinimumWidth($sibling)) { 398 found = true; 399 } else { 400 $sibling = getPrevious ? $sibling.prev() : $sibling.next(); 401 } 402 } 403 404 if (!found) { 405 $sibling = getPrevious ? $current.prev() : $current.next().next(); 406 } 407 408 var minimumWidth = MinimumWidth($sibling); 409 width = GetColumnWidth($sibling); 410 widgetContainerID = $sibling.data('widgetcontainerid'); 411 412 return { "Column": $sibling, "Width": width, "WidgetContainerID": widgetContainerID, "MinimumWidth": minimumWidth } 413} 414 415function MinimumWidth($column) { 416 if ($column.hasClass('inner')) { 417 return 1; 418 } 419 420 var minimumWidth = 1; 421 $column.children('.row').each(function () { 422 var innerColumnCount = $(this).children('.col').length; 423 if (innerColumnCount > minimumWidth) { 424 minimumWidth = innerColumnCount; 425 } 426 }); 427 428 return minimumWidth; 429} 430 431function ResetWidth($column, oldWidth, newWidth) { 432 $column.removeClass('col' + oldWidth).addClass('col' + newWidth); 433 CalculateInnerColumnWidths($column.children('.row'), newWidth); 434} 435 436function CalculateInnerColumnWidths($rows, parentWidth) { 437 $rows.each(function () { 438 var $columns = $(this).children('.inner.col'); 439 var siblingWidth = (parentWidth / $columns.length) | 0; 440 $columns.each(function () { 441 var currentWidth = GetColumnWidth($(this)); 442 $(this).removeClass('col' + currentWidth).addClass('col' + siblingWidth);
443 }); 444 445 if (parentWidth % $columns.length > 0) { 446 for (var i = 0; i < parentWidth % $columns.length; i++) { 447 $($columns.get(i)).removeClass('col' + siblingWidth).addClass('col' + (siblingWidth + 1)); 448 } 449 } 450 }); 451} 452 453function getCSSClassForWidgetType(widgetType, moduleWidgetType) { 454 var cssClass; 455 switch (widgetType) { 456 case "Editor": 457 cssClass = "editor"; 458 break; 459 case "Froala": 460 cssClass = "froalaEditor"; 461 break; 462 case "Image": 463 cssClass = "picture"; 464 break; 465 case "SlideShow": 466 cssClass = "slideshow"; 467 break; 468 case "RelatedDocuments": 469 cssClass = "relatedDocuments"; 470 break; 471 case "CustomWidget": 472 cssClass = "custom"; 473 break; 474 case "Tabbed": 475 cssClass = "tabbed"; 476 break; 477 case "Carousel": 478 cssClass = "carousel"; 479 break; 480 case "Pages": 481 cssClass = "dynamicPageListing"; 482 break; 483 case "CustomHtml": 484 cssClass = "customHTML"; 485 break; 486 case "Spacer": 487 cssClass = "spacer"; 488 break; 489 case "List": 490 cssClass = "list"; 491 break; 492 case "Text": 493 cssClass = "text"; 494 break; 495 case "Table": 496 cssClass = "tableWidget"; 497 break; 498 case "ModuleWidget": 499 cssClass = "widget " + moduleWidgetType; 500 break; 501 default: 502 cssClass = widgetType; 503 } 504 return cssClass; 505} 506 507function buildWidgetDragHelper(widgetID, widgetType, moduleWidgetType, moduleID, contentContainerID, isInMegaMenu, isChildWidget, group) {
508 var $widget = $('<div/>', { 509 'class': 'widget ' + getCSSClassForWidgetType(widgetType, moduleWidgetType) 510 }).css('min-width', 0) 511 .append($('<input/>', { type: 'hidden', 'class': 'widgetType' }).val(widgetType)) 512 .append($('<input/>', { type: 'hidden', 'class': 'widgetID' }).val(widgetID)) 513 .append($('<input/>', { type: 'hidden', 'class': 'moduleID' }).val(moduleID)) 514 .append($('<div/>', { 'class': 'hidden contentContainerID' }).text(contentContainerID)); 515 var $helper = $('<div/>', { 'class': 'widgets' }) 516 .append($widget) 517 .append($('<div/>', { 'class': 'hidden isInMegaMenu' }).text(isInMegaMenu)); 518 519 if (isChildWidget) 520 $helper.attr('data-ischildwidget', 'true'); 521 if (group != null) 522 $helper.attr('data-group', group); 523 524 return $helper; 525} 526 527function ProcessTabbedWidgetDrop($target, $helper) { 528 var contentContainerID = $target.parents('.pageContent').filter(":first").data('containerid'); 529 var srcContentContainerID = $helper.find('.contentContainerID').html(); 530 var $tabbedWidget = $target.parents('.widget.widgetTabbed'); 531 var parentID = $tabbedWidget.data('widgetid'); 532 var sequence = $target.data('sequence'); 533 var widgetID = $helper.find('.widgetID').val(); 534 var widgetType = $helper.find('.widgetType').val(); 535 var customWidgetID = $helper.find('.customWidgetID').html(); 536 var moduleID = $helper.find('.moduleID').val(); 537 var moduleWidgetID = $helper.find('.moduleWidgetID').html(); 538 var AllowTabWidgetWithInAnotherTabWidget = $tabbedWidget.find('.AllowTabWidgetWithInAnotherTabWidget').val(); 539 var isAdd = false; 540 541 if (widgetType == 'Carousel') { 542 alert(liveEditTabs.liveEditResources.NoCarouselWithinTabbed); 543 return; 544 } 545 else if (widgetType == 'Tabbed' && AllowTabWidgetWithInAnotherTabWidget == "False") { 546 alert(liveEditTabs.liveEditResources.NoTabbedWithinTabbed); 547 return; 548 } 549 550 var url; 551 if (srcContentContainerID != null) { 552 url = '/Layout/TabbedWidget/MoveIn?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&sequence=' + sequence + '&parentID=' + parentID + '&widgetID=' + widgetID + '&contentContainerID=' + srcContentContainerID; 553 if (contentContainerID != srcContentContainerID || (contentContainerID == 'pageContent' && srcContentContainerID != null)) 554 ContentCollectionInstance.CurrentContentContainerIDs.push(srcContentContainerID); 555 } else { 556 url = '/Layout/TabbedWidget/AddChildWidget?contentContainerID=' + contentContainerID + '&contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&sequence=' + sequence + '&widgetType=' + widgetType + '&customWidgetID=' + customWidgetID + '&moduleWidgetID=' + moduleWidgetID + '&contentContainerID=' + contentContainerID + '&widgetID=' + parentID; 557 isAdd = true; 558 } 559 560 postAction(url, widgetType, contentContainerID, isAdd); 561 ContentCollectionInstance.PostRefreshClickTargets.push('li > a[href$="' + parentID + '_' + sequence + '"]'); 562} 563 564function ProcessCarouselWidgetDrop($target, $helper) { 565 var contentContainerID = $target.parents('.pageContent').filter(":first").data('containerid'); 566 var srcContentContainerID = $helper.find('.contentContainerID').html(); 567 var $carouselWidget = $target.parents('.widget.widgetCarousel'); 568 var parentID = $carouselWidget.data('widgetid'); 569 var sequence = $target.data('sequence'); 570 var group = $target.data('group'); 571 var widgetID = $helper.find('.widgetID').val(); 572 var widgetType = $helper.find('.widgetType').val(); 573 var customWidgetID = $helper.find('.customWidgetID').html(); 574 var moduleID = $helper.find('.moduleID').val(); 575 var moduleWidgetID = $helper.find('.moduleWidgetID').html(); 576 var isAdd = false; 577 578 switch (widgetType) { 579 case 'Carousel': 580 alert(liveEditTabs.liveEditResources.NoCarouselWithinCarousel); 581 return; 582 case 'SlideShow': 583 alert(liveEditTabs.liveEditResources.NoSlideshowlWithinCarousel); 584 return; 585 case 'Tabbed': 586 alert(liveEditTabs.liveEditResources.NoTabbedlWithinCarousel); 587 return; 588 } 589 590 var url; 591 if (srcContentContainerID != null) { 592 url = '/Layout/CarouselWidget/MoveIn?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&group=' + group + '&sequence=' + sequence + '&parentID=' + parentID + '&widgetID=' + widgetID + '&contentContainerID=' + srcContentContainerID; 593 if (contentContainerID != srcContentContainerID || (contentContainerID == 'pageContent' && srcContentContainerID != null)) 594 ContentCollectionInstance.CurrentContentContainerIDs.push(srcContentContainerID); 595 } else { 596 url = '/Layout/CarouselWidget/AddChildWidget?contentContainerID=' + contentContainerID + '&contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&group=' + group + '&sequence=' + sequence + '&widgetType=' + widgetType + '&customWidgetID=' + customWidgetID + '&moduleWidgetID=' + moduleWidgetID + '&contentContainerID=' + contentContainerID + '&widgetID=' + parentID; 597 isAdd = true; 598 } 599 600 postAction(url, widgetType, contentContainerID, isAdd, function () { 601 var $reloadedCarouselWidget = $('[data-widgetid="' + parentID + '"].widget.widgetCarousel'); 602 603 if ($reloadedCarouselWidget.length == 0) { 604 var $optionHandle = $('[data-originalwidgetid="' + parentID + '"].handle.options'); 605 var currentWidgetId = $optionHandle.data('widgetid'); 606 607 $reloadedCarouselWidget = $('[data-widgetid="' + currentWidgetId + '"].widget.widgetCarousel'); 608 } 609 610 displayGroupAndHideOthers(group, $reloadedCarouselWidget); 611 }); 612} 613 614function putFocusOnNewTab() { 615 $('input.newTabName', $('#tab' + ContentCollectionInstance.newTabData.widgetID + '_' + ContentCollectionInstance.newTabData.sequence)).focus(); 616} 617 618function ProcessWidgetDrop($target, $helper, isInnerWidget) { 619 var contentContainerID = $target.data('contentcontainerid'); 620 var oldContentContainerID = $helper.find('.contentContainerID').html(); 621 var widgetContainerID = $target.data('widgetcontainerid'); 622 var sequence = $target.data('sequence'); 623 var group = $helper.data('group'); 624 var widgetID = $helper.find('.widgetID').val(); 625 var widgetType = $helper.find('.widgetType').val(); 626 var customWidgetID = $helper.find('.customWidgetID').html(); 627 var moduleID = $helper.find('.moduleID').val(); 628 var moduleWidgetID = $helper.find('.moduleWidgetID').html(); 629 var customHtmlID = $helper.data('customhtmlid'); 630 var isAdd = false; 631 var isChildWidget = $helper.data('ischildwidget'); 632 633 if (widgetContainerID != null) { 634 if (contentContainerID == 'pageContent') 635 contentContainerID = null; 636 var url; 637 if (oldContentContainerID != null) { 638 if (isChildWidget == true) { 639 if (group) { 640 url = '/Layout/CarouselWidget/MoveOut?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&widgetContainerID=' + widgetContainerID + '&sequence=' + sequence + '&widgetID=' + widgetID + '&contentContainerID=' + oldContentContainerID; 641 } else { 642 url = '/Layout/TabbedWidget/MoveOut?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&widgetContainerID=' + widgetContainerID + '&sequence=' + sequence + '&widgetID=' + widgetID + '&contentContainerID=' + oldContentContainerID; 643 } 644 } else { 645 url = '/Layout/WidgetMove/Move?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&widgetContainerID=' + widgetContainerID + '&sequence=' + sequence + '&widgetID=' + widgetID + '&contentContainerID=' + contentContainerID + "&oldContentContainerID=" + oldContentContainerID; 646 if (contentContainerID != oldContentContainerID) 647 ContentCollectionInstance.CurrentContentContainerIDs.push(oldContentContainerID); 648 } 649 if (contentContainerID != oldContentContainerID) 650 ContentCollectionInstance.CurrentContentContainerIDs.push(oldContentContainerID); 651 } 652 else { 653 url = '/Layout/WidgetAdd/Add?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&widgetContainerID=' + widgetContainerID + '&sequence=' + sequence + '&widgetType=' + widgetType + '&customWidgetID=' + customWidgetID + '&moduleWidgetID=' + moduleWidgetID + '&contentContainerID=' + contentContainerID + '&parentID=null' + '&customHtmlID=' + customHtmlID;
654 isAdd = true; 655 } 656 657 postAction(url, widgetType, contentContainerID, isAdd, adjustDraggableStateForWidgets); 658 } 659} 660 661function adjustDraggableStateForWidgets() 662{ 663 var formCenterWidgetPresent = $(".widget.widgetFormCenter").length > 0; 664 var $formCenterWidgetIcon = $(".widget.formCenter"); 665 666 if(formCenterWidgetPresent === true) 667 { 668 $formCenterWidgetIcon.draggable('disable'); 669 $formCenterWidgetIcon.addClass('disabled'); 670 $formCenterWidgetIcon.attr("title", "FormCenter widget icon is disabled as you already have 1 FormCenter widget on the page."); 671 if($(".liveEditTab p.tip").length === 0) 672 { 673 $("#subTabModules").append('<p class="tip">FormCenter widget icon is disabled as you already have 1 FormCenter widget on the page.</p>'); 674 } 675 } 676 else 677 { 678 $formCenterWidgetIcon.draggable('enable'); 679 $formCenterWidgetIcon.removeClass('disabled'); 680 $formCenterWidgetIcon.removeAttr("title"); 681 $("p.tip").remove(); 682 } 683} 684 685var enablePushOptionsFn = function () { $('#cpCommonPopover .pushingOptions .button').removeClass('inactive'); }; 686var disablePushOptionsFn = function () { $('#cpCommonPopover .pushingOptions .button').addClass('inactive'); }; 687 688function postAction(url, widgetType, contentContainerID, isAdd, callBack) { 689 AJAX(url, 'POST', '', function (response) { 690 ContentCollectionInstance.CurrentContentContainerIDs.push(contentContainerID); 691 ContentCollectionInstance.reloadContent(true, callBack == null ? function () { $(window.Pages).trigger('ContentReload', widgetType) } : callBack); 692 if (isAdd == true && response.WidgetID) { 693 switch (widgetType) { 694 case 'Image': 695 $('#divImage' + response.WidgetID, '[data-containerid=' + contentContainerID + ']').trigger('click'); 696 break; 697 case 'SlideShow': 698 $('#slideshow' + response.WidgetID, '[data-containerid=' + contentContainerID + ']').children('.slideshowOptions').trigger('click'); 699 break; 700 case 'CustomWidget': 701 $('#divCustomWidget_' + response.WidgetID, '[data-containerid=' + contentContainerID + ']').trigger('click'); 702 break; 703 case 'Editor': 704 $('#divEditor' + response.WidgetID, '[data-containerid=' + contentContainerID + ']').trigger('click'); 705 break; 706 case 'Froala': 707 $('#divEditor' + response.WidgetID, '[data-containerid=' + contentContainerID + ']').trigger('click'); 708 break; 709 case 'CustomHtml': 710 $('#widgetBody' + response.WidgetID, '[data-containerid="' + contentContainerID + '"]').trigger('click'); 711 break; 712 case 'Pages': 713 case 'RelatedDocuments': 714 case 'MyAccount': 715 case 'List': 716 case 'Carousel': 717 $('a.handle.options[data-widgetid="' + response.WidgetID + '"]', '[data-containerid=' + contentContainerID + ']').trigger("click"); 718 disablePushOptionsFn(); 719 break; 720 case 'ModuleWidget': 721 $('div[data-widget-id="' + response.WidgetID + '"]', '[data-containerid=' + contentContainerID + ']').siblings("a.handle.options").trigger('click'); 722 disablePushOptionsFn(); 723 break; 724 } 725 726 $('a.handle.options').unbind("click", enablePushOptionsFn).click(enablePushOptionsFn); 727 $(window.Pages).trigger('WidgetAdded', widgetType); 728 729 } 730 }); 731} 732 733function InitializeContainers(opt) { 734 var defaults = { 735 hidePopover: true //Whether or not close popups when reloading containers. 736 }; 737 738 var options = $.extend(defaults, opt); 739 if ($('#ReadOnly').val() == 'True') { 740 $('.pageContent.preDragging').removeClass('preDragging'); 741 } 742 else { 743 frontEnd_removeAttributesFromGraphicLinks(); 744 745 $('.removeWidgetTargets').parents('.inner.col').children('.target.inner').remove(); 746 747 $('.widgetCarousel').parents('.row.outer').find('.indicator:not(.tabbed,.carousel),.target:not(.above.outer,.below.outer,.tabbed,.carousel)').remove(); 748 749 $('.pageContent').removeClass('preDragging').addClass('preDragging'); 750 ResizeData.TotalShift = 0; 751 ResizeData.Prev = null; 752 ResizeData.Next = null; 753 754 ContentCollectionInstance.init(); 755 menuManager.initializeMegaMenus(); 756 var $allTargets = $('.pageContent').find('.target'); 757 var $allIndicators = $('.indicator'); 758 759 //Make resize handles draggable 760 $('.pageContent').find('.resize').draggable({ 761 stop: function (event, ui) { 762 var contentContainerID = $(this).parents('.pageContent').filter(":first").data('containerid'); 763 if (ResizeData.TotalShift != 0) { 764 url = '/Layout/WidgetResize/ResizeColumns?contentContainerID=' + contentContainerID + '&contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&leftID=' + ResizeData.Prev.WidgetContainerID + '&leftWidth=' + ResizeData.Prev.Width + '&rightID=' + ResizeData.Next.WidgetContainerID + '&rightWidth=' + ResizeData.Next.Width; 765 AJAX(url, 'POST', '', function (response) { 766 ContentCollectionInstance.CurrentContentContainerIDs.push(contentContainerID); 767 ContentCollectionInstance.reloadContent(); 768 if (window.Page) { 769 $(window.Page).trigger('ColumnResize'); 770 } 771 }, false); 772 } 773 }, 774 start: function (event, ui) { 775 $allTargets.removeClass("targetOver"); 776 $allIndicators.removeClass('active'); 777 ResizeData.init($(this).parents('.pageContent').filter(":first")); 778 }, 779 drag: function (event, ui) { 780 var moveDistance = $(this).position().left - $(this).next().next().position().left; 781 var totalShift = (moveDistance / ResizeData.ColumnWidth) | 0; 782 var columnShift = Math.abs(totalShift - ResizeData.TotalShift); 783 var moveLeft = totalShift - ResizeData.TotalShift < 0; 784 var prev = GetSibling($(this), true, moveLeft); 785 var next = GetSibling($(this), false, moveLeft); 786 var newPrevWidth; 787 var newNextWidth;
788 var validResize = false; 789 if (moveLeft && prev.Width > columnShift && prev.Width - columnShift >= prev.MinimumWidth) { 790 newPrevWidth = prev.Width - columnShift; 791 newNextWidth = next.Width + columnShift; 792 validResize = true; 793 } 794 if (!moveLeft && next.Width > columnShift && next.Width - columnShift >= next.MinimumWidth) { 795 newPrevWidth = prev.Width + columnShift; 796 newNextWidth = next.Width - columnShift; 797 validResize = true; 798 } 799 800 if (validResize && columnShift != 0) { 801 ResetWidth(prev.Column, prev.Width, newPrevWidth); 802 ResetWidth(next.Column, next.Width, newNextWidth); 803 804 //prevent spacer height to stuck while resizing. 805 $("div.widgetSpacer").height(0); 806 if (!window.isRemoveSetHeights) 807 SetHeights(); 808 809 ResizeData.TotalShift = totalShift; 810 prev.Width = newPrevWidth; 811 next.Width = newNextWidth; 812 ResizeData.Prev = prev; 813 ResizeData.Next = next; 814 var dividerLeft = Number($(this).find('span').css('left').replace('px', '')); 815 var newOffset = columnShift * ResizeData.ColumnWidth; 816 if (moveLeft) { 817 dividerLeft = dividerLeft + newOffset; 818 } else { 819 dividerLeft = dividerLeft - newOffset; 820 } 821 $(this).find('span').css('left', dividerLeft.toString() + 'px'); 822 } 823 }, 824 axis: 'x', 825 containment: 'parent' 826 }); 827 828 //Make widgets on the page draggable 829 $('.pageContent').find('.col.inner').draggable({ 830 helper: function (event, ui) { 831 var widgetID = $(this).find('.widgetID').val(); 832 var widgetType = $(this).find('.widgetType').val(); 833 var moduleWidgetType = $(this).find('.widget').data('modulewidgettype'); 834 var moduleID = $(this).find('.moduleID').val(); 835 var isInMegaMenu = $(this).parents('[data-cprole=contentContainer].megaMenuContainer').length > 0; 836 var contentContainerID = $(this).parents('.pageContent').filter(":first").data('containerid'); 837 return buildWidgetDragHelper(widgetID, widgetType, moduleWidgetType, moduleID, contentContainerID, isInMegaMenu, false); 838 }, 839 start: function (event, ui) { 840 $allTargets.removeClass("targetOver"); 841 $allIndicators.removeClass('active'); 842 $('.pageContent.preDragging').removeClass('preDragging').addClass('dragging'); 843 }, 844 stop: function (event, ui) { 845 $('.pageContent.dragging').removeClass('dragging').addClass('preDragging'); 846 }, 847 appendTo: '.liveEditTab', 848 cursorAt: { top: 5, left: 5 }, 849 cursor: 'move', 850 handle: '.handle.move' 851 }); 852 853 //Make tabbed & carousel widgets on the page draggable 854 $('.pageContent').find('.col.inner .tabbedWidget.cpTabPanel,.col.inner .widgetCarousel .widgetCarousel-item').draggable({ 855 delay: 500, 856 helper: function (event, ui) { 857 var widgetID = $(this).find('.widgetID').val(); 858 var widgetType = $(this).find('.widgetType').val(); 859 var moduleWidgetType = $(this).find('.widget').data('modulewidgettype'); 860 var moduleID = $(this).find('.moduleID').val(); 861 var $group = $(this).find('.groupSequence'); 862 var group = $group.length ? $group.text() : null; 863 var isInMegaMenu = $(this).parents('[data-cprole=contentContainer].megaMenuContainer').length > 0; 864 var contentContainerID = $(this).parents('.pageContent').filter(":first").data('containerid'); 865 return buildWidgetDragHelper(widgetID, widgetType, moduleWidgetType, moduleID, contentContainerID, isInMegaMenu, true, group); 866 }, 867 start: function (event, ui) { 868 $allTargets.removeClass("targetOver"); 869 $allIndicators.removeClass('active'); 870 $('.pageContent.preDragging').removeClass('preDragging').addClass('dragging'); 871 }, 872 stop: function (event, ui) { 873 $('.pageContent.dragging').removeClass('dragging').addClass('preDragging'); 874 }, 875 appendTo: '.liveEditTab', 876 cursorAt: { top: 5, left: 5 }, 877 cursor: 'move', 878 handle: '.handle.moveChildWidget', 879 cancel: '.textContent,input[type=text],textarea,p.placeholder.dragWidgetHere,div[contenteditable=true],.fr-box' 880 }); 881 882 //Make top level menu items hoverable 883 $('li.topMenuItemxxx').droppable({ 884 over: function (event, ui) { 885 var $li = $(this); 886 var $parent = $li.parent(); 887 var menuData = $parent.data('menu'); 888 var displayMegaMenu = $li.data('displaymegamenu'); 889 if (displayMegaMenu == 'True') { 890 var pageID = $li.data('pageid'); 891 if (menuData.type === MAIN_MENU) { 892 $('.mainNavMegaMenu.megaMenuContainer.pageID_' + pageID).show(); 893 } else { 894 $('.secondaryNavMegaMenu.megaMenuContainer.pageID_' + pageID).show(); 895 } 896 if (!window.isRemoveSetHeights) 897 SetHeights();
898 } 899 //menuManager.menuMouseOver($(this)); 900 }, 901 out: function (event, ui) { 902 //menuManager.menuMouseOut($(this)); 903 }, 904 tolerance: 'pointer' 905 }); 906 907 //Make above & below targets droppable 908 $('.pageContent').find('.target.above,.target.below').droppable({ 909 over: function (event, ui) { 910 var $this = $(this); 911 var isOverMegaMenu = $this.parents('[data-cprole=contentContainer].megaMenuContainer').length > 0; 912 if (isOverMegaMenu != ($(ui.helper).find('.isInMegaMenu').html() == "true") && $(ui.helper).find('.isInMegaMenu').length > 0) { 913 return; 914 } 915 916 $allTargets.removeClass("targetOver"); 917 $allIndicators.removeClass('active'); 918 var indicatorID = "indicator_{0}_{1}_{2}" 919 .replace("{0}", $this.data('contentcontainerid')) 920 .replace("{1}", $this.data('widgetcontainerid')) 921 .replace("{2}", $this.data('sequence')); 922 923 var $indicator = $('#' + indicatorID); 924 if (ui.helper.find('.widgetType').val() === 'Carousel' && (!$indicator.hasClass('outer'))) return; 925 926 $this.addClass("targetOver"); 927 $indicator.addClass('active'); 928 }, 929 out: function (event, ui) { 930 var indicatorID = "indicator_{0}_{1}_{2}" 931 .replace("{0}", $(this).data('contentcontainerid')) 932 .replace("{1}", $(this).data('widgetcontainerid')) 933 .replace("{2}", $(this).data('sequence')); 934 $('#' + indicatorID).removeClass('active'); 935 }, 936 drop: function (event, ui) { 937 if ($(this)[0] === $(".targetOver")[0]) 938 ProcessWidgetDrop($(this), ui.helper, false); 939 }, 940 tolerance: 'pointer' 941 }); 942 943 //Make left & right targets droppable only for the content containers who have a width > min width defined for targets to be droppable on the left and right. Vishal 944 $('.pageContent').find('.target.right,.target.left').droppable({ 945 over: function (event, ui) { 946 var $this = $(this); 947 var isOverMegaMenu = $this.parents('[data-cprole=contentContainer].megaMenuContainer').length > 0; 948 if (isOverMegaMenu != ($(ui.helper).find('.isInMegaMenu').html() == "true") && $(ui.helper).find('.isInMegaMenu').length > 0) { 949 return; 950 } 951 if ($this.parents('.pageContent').width() >= ResizeData.MinContainerWidthToEnableRightAndLeftTargets) { 952 953 if (ui.helper.find('.widgetType').val() === 'Carousel') return; 954 955 $allTargets.removeClass("targetOver"); 956 $allIndicators.removeClass('active'); 957 var indicatorID = "indicator_{0}_{1}_{2}" 958 .replace("{0}", $this.data('contentcontainerid')) 959 .replace("{1}", $this.data('widgetcontainerid')) 960 .replace("{2}", $this.data('sequence')); 961 $this.addClass("targetOver"); 962 $('#' + indicatorID).addClass('active'); 963 } 964 }, 965 out: function (event, ui) { 966 var indicatorID = "indicator_{0}_{1}_{2}" 967 .replace("{0}", $(this).data('contentcontainerid')) 968 .replace("{1}", $(this).data('widgetcontainerid')) 969 .replace("{2}", $(this).data('sequence')); 970 $('#' + indicatorID).removeClass('active'); 971 }, 972 drop: function (event, ui) { 973 if ($(this).parents('.pageContent').width() >= ResizeData.MinContainerWidthToEnableRightAndLeftTargets) { 974 if ($(this)[0] === $(".targetOver")[0]) 975 ProcessWidgetDrop($(this), $(ui.helper), false); 976 } 977 }, 978 tolerance: 'pointer' 979 }); 980 981 //Make tabbed widget targets droppable 982 $('.pageContent .widget.widgetTabbed').find('.target.tabbed').droppable({ 983 over: function (event, ui) { 984 var $this = $(this); 985 var isOverMegaMenu = $this.parents('[data-cprole=contentContainer].megaMenuContainer').length > 0; 986 if (isOverMegaMenu != ($(ui.helper).find('.isInMegaMenu').html() == "true") && $(ui.helper).find('.isInMegaMenu').length > 0) { 987 return; 988 } 989 990 $allTargets.removeClass("targetOver"); 991 $allIndicators.removeClass('active'); 992 var indicatorID = "indicator_tabbed_{0}_{1}" 993 .replace("{0}", $this.data('widgetid')) 994 .replace("{1}", $this.data('sequence')); 995 $this.addClass("targetOver"); 996 $('#' + indicatorID).addClass('active'); 997 }, 998 out: function (event, ui) { 999 var indicatorID = "indicator_tabbed_{0}_{1}" 1000 .replace("{0}", $(this).data('widgetid')) 1001 .replace("{1}", $(this).data('sequence')); 1002 $('#' + indicatorID).removeClass('active'); 1003 }, 1004 drop: function (event, ui) { 1005 if ($(this)[0] === $(".targetOver")[0]) 1006 ProcessTabbedWidgetDrop($(this), $(ui.helper));
1007 }, 1008 tolerance: 'pointer' 1009 }); 1010 1011 //Make carousel widget targets droppable 1012 $('.pageContent .widget.widgetCarousel').find('.target.carousel').droppable({ 1013 over: function (event, ui) { 1014 var $this = $(this); 1015 var isOverMegaMenu = $this.parents('[data-cprole=contentContainer].megaMenuContainer').length > 0; 1016 if (isOverMegaMenu != ($(ui.helper).find('.isInMegaMenu').html() == "true") && $(ui.helper).find('.isInMegaMenu').length > 0) { 1017 return; 1018 } 1019 1020 if (!$this.parents('.widgetCarousel-group').hasClass('currentGroup')) return; 1021 1022 $allTargets.removeClass("targetOver"); 1023 $allIndicators.removeClass('active'); 1024 var indicatorID = "indicator_carousel_{0}_{1}_{2}" 1025 .replace("{0}", $this.data('widgetid')) 1026 .replace("{1}", $this.data('group')) 1027 .replace("{2}", $this.data('sequence')); 1028 $this.addClass("targetOver"); 1029 $('#' + indicatorID).addClass('active'); 1030 }, 1031 out: function (event, ui) { 1032 var $this = $(this); 1033 var indicatorID = "indicator_carousel_{0}_{1}_{2}" 1034 .replace("{0}", $this.data('widgetid')) 1035 .replace("{1}", $this.data('group')) 1036 .replace("{2}", $this.data('sequence')); 1037 $('#' + indicatorID).removeClass('active'); 1038 }, 1039 drop: function (event, ui) { 1040 if ($(this)[0] === $(".targetOver")[0]) 1041 ProcessCarouselWidgetDrop($(this), $(ui.helper)); 1042 }, 1043 tolerance: 'pointer' 1044 }); 1045 1046 //Container delete handler 1047 $('.pageContent').find('.handle.remove:not(.childWidget,.emptyTab,.emptyGroup)').unbind('click').click(function (e) { 1048 if (!confirm(window.ContentCollectionInstance.resources.ConfirmWidgetDelete)) { 1049 e.stopPropagation(); 1050 return false; 1051 } 1052 if (e.stopPropagation) 1053 e.stopPropagation(); 1054 var widgetID = $(this).parent().find('.widgetID').val(); 1055 var widgetType = $(this).parent().find('.widgetType').val(); 1056 var contentContainerID = $(this).parents('.pageContent').filter(':first').data('containerid'); 1057 widgetID = widgetID ? widgetID : '00000000-0000-0000-0000-000000000000'; 1058 var url = '/Layout/WidgetDelete/Delete?contentContainerID=' + contentContainerID + '&contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&widgetID=' + widgetID; 1059 AJAX(url, 'POST', '', function (response) { 1060 ContentCollectionInstance.CurrentContentContainerIDs.push(contentContainerID); 1061 ContentCollectionInstance.reloadContent(); 1062 //Bind the grid targets to be file droppable. 1063 if (widgetType == 'Image' || widgetType == 'RelatedDocuments' || widgetType == 'SlideShow') 1064 makeGridTargetsFileDroppable(); 1065 1066 adjustDraggableStateForWidgets(); 1067 }); 1068 }); 1069 1070 //Child widget delete handler 1071 $('.pageContent').find('.handle.remove.childWidget').unbind('click').click(function (e) { 1072 if (!confirm(window.ContentCollectionInstance.resources.ConfirmWidgetDelete)) { 1073 e.stopPropagation(); 1074 return false; 1075 } 1076 var sequence = $(this).data('sequence'); 1077 var widgetID = $(this).data('widgetid'); 1078 var parentID = $(this).data('parentid'); 1079 var group = $(this).data('group'); 1080 if (widgetID) { 1081 var url; 1082 var contentContainerID = $(this).parents('.pageContent').filter(":first").data('containerid'); 1083 if (group != null) { 1084 //Widget from Carousel Widget 1085 url = '/Layout/CarouselWidget/DeleteChildWidget?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&widgetID=' + widgetID; 1086 } else { 1087 url = '/Layout/TabbedWidget/DeleteTab?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&widgetID=' + widgetID; 1088 ContentCollectionInstance.PostRefreshClickTargets.push('li > a[href$="' + parentID + '_' + sequence + '"]'); 1089 } 1090 AJAX(url, 'POST', '', function (response) { 1091 ContentCollectionInstance.CurrentContentContainerIDs.push(contentContainerID); 1092 ContentCollectionInstance.reloadContent(); 1093 1094 if (group != null) { 1095 var $reloadedCarouselWidget = $('[data-widgetid="' + parentID + '"].widget.widgetCarousel'); 1096 1097 if ($reloadedCarouselWidget.length == 0) { 1098 var $optionHandle = $('[data-originalwidgetid="' + parentID + '"].handle.options'); 1099 var currentWidgetId = $optionHandle.data('widgetid'); 1100 1101 $reloadedCarouselWidget = $('[data-widgetid="' + currentWidgetId + '"].widget.widgetCarousel'); 1102 } 1103 1104 displayGroupAndHideOthers(group, $reloadedCarouselWidget); 1105 } 1106 }); 1107 } 1108 }); 1109 1110 $('.tabbedWidget.cpTabPanel .button.cancel, .tabbedWidget.cpTabPanel .handle.remove.emptyTab').unbind('click').click(function (e) { 1111 e.preventDefault(); 1112 var $tabbedWidget = $(this).parents('.widget.widgetTabbed'); 1113 var parentID = $tabbedWidget.data('widgetid'); 1114 var sequence = $(this).parents('.cpTabPanel').children('.tabSequence').html(); 1115 if (parentID && sequence) { 1116 var url = '/Layout/TabbedWidget/DeleteEmptyTab?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&parentID=' + parentID + '&sequence=' + sequence; 1117 var contentContainerID = $(this).parents('.pageContent').filter(":first").data('containerid'); 1118 AJAX(url, 'POST', '', function (response) { 1119 ContentCollectionInstance.CurrentContentContainerIDs.push(contentContainerID); 1120 ContentCollectionInstance.reloadContent(); 1121 if (window.Pages && window.Pages.Widgets && window.Pages.Widgets.Tabs) { 1122 $(window.Pages.Widgets.Tabs).trigger('TabDeleted'); 1123 } 1124 }); 1125 } 1126 }); 1127 1128 //Widget options popup 1129 $('.col .options').click(function (e) { 1130 $('.col .configPopup:visible').fadeOut(300);
1131 menuManager.pinMegaMenuOpen($(this)); 1132 $(this).siblings(".configPopup:not('.moduleAddItem')").fadeIn(300); 1133 return false; 1134 }); 1135 1136 // Handle Event Bubbling 1137 $('html').unbind("click.hidePopOvers").bind("click.hidePopOvers", function () { 1138 //Hide the menus if visible 1139 $('.col .configPopup:visible').fadeOut(300); 1140 }); 1141 1142 $('.col.inner').find('.options,.configPopup').click(function (event) { 1143 event.stopPropagation(); 1144 }); 1145 1146 //Add an extra class to pages widget handle for pages widgets inside megamenu. VB 1147 $('.widgetPages').each(function () { 1148 var $this = $(this); 1149 if ($this.parents('.megaMenuContainer ').length > 0) { 1150 $this.siblings('.handle.options').addClass('insideMegaMenu'); 1151 } 1152 }); 1153 1154 //Pages widget options 1155 $('.widget.widgetPages').siblings('a.handle.options').each(function () { 1156 var $handler = $(this); 1157 var insideMegaMenu = $handler.hasClass('insideMegaMenu'); 1158 if ($handler.data('cpPopover')) { 1159 $handler.data('cpPopover').destroy(); 1160 } 1161 1162 var contentContainerExternalID = $handler.parents('[data-cprole$="ontentContainer"]').attr('id'); 1163 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1164 menuManager.pinMegaMenuOpen($handler); 1165 var url = '/Pages/PagesWidget/Options?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerExternalID=' + contentContainerExternalID + '&contentContainerID=' + currentContentContainerID + '&insideMegaMenu=' + insideMegaMenu; 1166 $handler.cpPopover({ 1167 url: url, 1168 className: 'options adminWrap', 1169 onClose: function (e, popoverWrap) { 1170 e.preventDefault(); 1171 window.CommonPopoverInstance.hide(popoverWrap); 1172 $(document.activeElement).change(); 1173 } 1174 }); 1175 }); 1176 1177 //Text widget options 1178 $('.widget.widgetText').siblings('a.handle.options').each(function () { 1179 var $handler = $(this); 1180 var insideMegaMenu = $handler.hasClass('insideMegaMenu'); 1181 if ($handler.data('cpPopover')) { 1182 $handler.data('cpPopover').destroy(); 1183 } 1184 1185 var contentContainerExternalID = attrOrProps($handler.parents('[data-cprole$="ontentContainer"]'), 'id'); 1186 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1187 menuManager.pinMegaMenuOpen($handler); 1188 var url = '/ContentWidgets/TextOptions?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&contentContainerExternalID=' + contentContainerExternalID + '&contentContainerID=' + currentContentContainerID + '&insideMegaMenu=' + insideMegaMenu; 1189 $handler.cpPopover({ 1190 url: url, 1191 className: 'options adminWrap', 1192 onClose: function (e, popoverWrap) { 1193 e.preventDefault(); 1194 window.CommonPopoverInstance.hide(popoverWrap); 1195 $(document.activeElement).change(); 1196 } 1197 }); 1198 }); 1199 1200 //MyAccount widget options 1201 $('.widget.widgetMyAccount').siblings('a.handle.options').each(function () { 1202 var $handler = $(this); 1203 1204 if ($handler.data('cpPopover')) { 1205 $handler.data('cpPopover').destroy(); 1206 } 1207 1208 var contentContainerExternalID = $handler.parents('[data-cprole$="ontentContainer"]').attr('id'); 1209 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1210 var url = '/MyAccount/Widget/Options?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&contentContainerExternalID=' + contentContainerExternalID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerID=' + currentContentContainerID; 1211 $handler.cpPopover({ 1212 url: url, 1213 className: 'options adminWrap', 1214 onClose: function (e, popoverWrap) { 1215 e.preventDefault(); 1216 window.CommonPopoverInstance.hide(popoverWrap); 1217 $(document.activeElement).change(); 1218 } 1219 }); 1220 }); 1221 1222 //Image widget options 1223 $('.widget.image').siblings('a.handle.options').each(function () { 1224 var $handler = $(this); 1225 1226 if ($handler.data('cpPopover')) { 1227 $handler.data('cpPopover').destroy(); 1228 } 1229 1230 var contentContainerExternalID = attrOrProps($handler.parents('[data-cprole$="ontentContainer"]'), 'id'); 1231 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1232 var url = '/ContentWidgets/ImageOptions?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&contentContainerExternalID=' + contentContainerExternalID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerID=' + currentContentContainerID; 1233 $handler.cpPopover({ 1234 url: url, 1235 className: 'options adminWrap', 1236 onClose: function (e, popoverWrap) { 1237 e.preventDefault();
1238 window.CommonPopoverInstance.hide(popoverWrap); 1239 $(document.activeElement).change(); 1240 } 1241 }); 1242 }); 1243 1244 //Editor widget options 1245 $('.widget.editor').siblings('a.handle.options').each(function () { 1246 var $handler = $(this); 1247 1248 if ($handler.data('cpPopover')) { 1249 $handler.data('cpPopover').destroy(); 1250 } 1251 1252 var contentContainerExternalID = $handler.parents('[data-cprole$="ontentContainer"]').attr('id'); 1253 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1254 var url = '/ContentWidgets/EditorOptions?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&contentContainerExternalID=' + contentContainerExternalID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerID=' + currentContentContainerID; 1255 $handler.cpPopover({ 1256 url: url, 1257 className: 'options adminWrap', 1258 onClose: function (e, popoverWrap) { 1259 e.preventDefault(); 1260 window.CommonPopoverInstance.hide(popoverWrap); 1261 $(document.activeElement).change(); 1262 } 1263 }); 1264 }); 1265 1266 //Froala widget options 1267 $('.widget.froala').siblings('a.handle.options').each(function () { 1268 var $handler = $(this); 1269 1270 if ($handler.data('cpPopover')) { 1271 $handler.data('cpPopover').destroy(); 1272 } 1273 1274 var contentContainerExternalID = $handler.parents('[data-cprole$="ontentContainer"]').attr('id'); 1275 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1276 var url = '/ContentWidgets/EditorOptions?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&contentContainerExternalID=' + contentContainerExternalID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerID=' + currentContentContainerID; 1277 $handler.cpPopover({ 1278 url: url, 1279 className: 'options adminWrap', 1280 onClose: function (e, popoverWrap) { 1281 e.preventDefault(); 1282 window.CommonPopoverInstance.hide(popoverWrap); 1283 $(document.activeElement).change(); 1284 } 1285 }); 1286 }); 1287 1288 //Spacer widget options 1289 $('.widget.widgetSpacer').siblings('a.handle.options').each(function () { 1290 var $handler = $(this); 1291 1292 if ($handler.data('cpPopover')) { 1293 $handler.data('cpPopover').destroy(); 1294 } 1295 1296 var contentContainerExternalID = $handler.parents('[data-cprole$="ontentContainer"]').attr('id'); 1297 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1298 var url = '/ContentWidgets/SpacerOptions?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&contentContainerExternalID=' + contentContainerExternalID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerID=' + currentContentContainerID; 1299 $handler.cpPopover({ 1300 url: url, 1301 className: 'options adminWrap', 1302 onClose: function (e, popoverWrap) { 1303 e.preventDefault(); 1304 window.CommonPopoverInstance.hide(popoverWrap); 1305 $(document.activeElement).change(); 1306 } 1307 }); 1308 }); 1309 1310 //Custom widget options 1311 $('.widget.custom').siblings('a.handle.options').each(function () { 1312 var $handler = $(this); 1313 1314 if ($handler.data('cpPopover')) { 1315 $handler.data('cpPopover').destroy(); 1316 } 1317 1318 var contentContainerExternalID = attrOrProps($handler.parents('[data-cprole$="ontentContainer"]'), 'id'); 1319 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1320 var url = '/Pages/CustomWidgetOptions?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&contentContainerExternalID=' + contentContainerExternalID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerID=' + currentContentContainerID; 1321 $handler.cpPopover({ 1322 url: url, 1323 className: 'options adminWrap', 1324 onClose: function (e, popoverWrap) { 1325 e.preventDefault(); 1326 window.CommonPopoverInstance.hide(popoverWrap); 1327 $(document.activeElement).change(); 1328 } 1329 }); 1330 }); 1331 1332 //List widget options 1333 $('.widget.widgetList').siblings('a.handle.options').each(function () { 1334 var $handler = $(this); 1335 1336 if ($handler.data('cpPopover')) { 1337 $handler.data('cpPopover').destroy(); 1338 } 1339 1340 var contentContainerExternalID = attrOrProps($handler.parents('[data-cprole$="ontentContainer"]'), 'id'); 1341 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1342 var url = '/ContentWidgets/ListOptions?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&contentContainerExternalID=' + contentContainerExternalID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerID=' + currentContentContainerID; 1343 $handler.cpPopover({ 1344 url: url, 1345 className: 'options adminWrap', 1346 onClose: function (e, popoverWrap) { 1347 e.preventDefault();
1348 window.CommonPopoverInstance.hide(popoverWrap); 1349 $(document.activeElement).change(); 1350 } 1351 }); 1352 }); 1353 1354 //Slideshow widget options 1355 $('.widget.slideShow').siblings('a.handle.options').each(function () { 1356 var $handler = $(this); 1357 1358 if ($handler.data('cpPopover')) { 1359 $handler.data('cpPopover').destroy(); 1360 } 1361 1362 var contentContainerExternalID = attrOrProps($handler.parents('[data-cprole$="ontentContainer"]'), 'id'); 1363 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1364 var url = '/ContentWidgets/SlideshowOptions?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&contentContainerExternalID=' + contentContainerExternalID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerID=' + currentContentContainerID; 1365 $handler.cpPopover({ 1366 url: url, 1367 className: 'options adminWrap', 1368 onClose: function (e, popoverWrap) { 1369 e.preventDefault(); 1370 window.CommonPopoverInstance.hide(popoverWrap); 1371 $(document.activeElement).change(); 1372 } 1373 }); 1374 }); 1375 1376 //Related Documents widget options 1377 $('.widget.widgetRelatedDocuments').siblings('a.handle.options').each(function () { 1378 var $handler = $(this); 1379 1380 if ($handler.data('cpPopover')) { 1381 $handler.data('cpPopover').destroy(); 1382 } 1383 1384 var contentContainerExternalID = $handler.parents('[data-cprole$="ontentContainer"]').attr('id'); 1385 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1386 var url = '/ContentWidgets/RelatedDocumentsSave/Options?widgetID=' + $handler.data('widgetid') 1387 + '&pageID=' + ContentCollectionInstance.PageID 1388 + '&contentContainerExternalID=' + contentContainerExternalID 1389 + '&moduleID=' + ContentCollectionInstance.ModuleID 1390 + "&contentContainerID=" + currentContentContainerID; 1391 $handler.cpPopover({ 1392 url: url, 1393 type: 'post', 1394 className: 'options adminWrap' 1395 }); 1396 }); 1397 1398 attachRelatedDocumentsHandlers(); 1399 1400 //Tabbed widget options 1401 $('.widget.widgetTabbed ').siblings('a.handle.options').each(function () { 1402 var $handler = $(this); 1403 openTabbedWidgetOptionsModal($handler); 1404 }); 1405 1406 //Carousel widget options 1407 $('.widget.widgetCarousel').siblings('a.handle.options').each(function () { 1408 var $handler = $(this); 1409 1410 if ($handler.data('cpPopover')) { 1411 $handler.data('cpPopover').destroy(); 1412 } 1413 1414 var contentContainerExternalID = $handler.parents('[data-cprole$="ontentContainer"]').attr('id'); 1415 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1416 var url = '/Layout/CarouselWidget/Options?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&contentContainerExternalID=' + contentContainerExternalID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerID=' + currentContentContainerID; 1417 $handler.cpPopover({ 1418 url: url, 1419 type: 'post', 1420 className: 'options adminWrap', 1421 onClose: function (e, popoverWrap) { 1422 e.preventDefault(); 1423 window.Pages.carouselOptionsClosed = true; 1424 window.CommonPopoverInstance.hide(popoverWrap); 1425 $(document.activeElement).change(); 1426 }, 1427 onOpen: function () { 1428 window.Pages.carouselOptionsClosed = null; 1429 } 1430 }); 1431 }); 1432 1433 if (!window.isRemoveSetHeights) 1434 SetHeights(); 1435 1436 // Preventing unwanted clicks 1437 $('a[href="#"]').click(function (e) { 1438 e.preventDefault(); 1439 }); 1440 1441 //Carousel widget 1442 $('.carouselChooseTemplates .widgetCarousel-layoutChoice').unbind('click').bind('click', function (e) { 1443 e.preventDefault(); 1444 var $carouselWidget = $(this).parents('.widget.widgetCarousel'); 1445 var widgetID = $carouselWidget.data('widgetid'); 1446 var contentContainerID = $(this).parents('.pageContent').filter(":first").data('containerid'); 1447 var group = $(this).parents('.widgetCarousel-group').filter(":first").data('group'); 1448 var template = $(this).data('template'); 1449 var url = '/Layout/CarouselWidget/ChooseTemplate?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&template=' + template + '&group=' + group + '&widgetID=' + widgetID; 1450 postAction(url, null, contentContainerID, false, function () { 1451 var $reloadedCarouselWidget = $('[data-widgetid="' + widgetID + '"].widget.widgetCarousel'); 1452 1453 if ($reloadedCarouselWidget.length == 0) { 1454 var $optionHandle = $('[data-originalwidgetid="' + widgetID + '"].handle.options'); 1455 var currentWidgetId = $optionHandle.data('widgetid'); 1456 1457 $reloadedCarouselWidget = $('[data-widgetid="' + currentWidgetId + '"].widget.widgetCarousel'); 1458 } 1459 1460 displayGroupAndHideOthers(group, $reloadedCarouselWidget); 1461 }); 1462 }); 1463 1464 $('.widgetCarousel .handle.remove.emptyGroup').unbind('click').click(function (e) { 1465 e.preventDefault(); 1466 if (confirm(window.ContentCollectionInstance.resources.ConfirmCarouselGroupDelete)) { 1467 var $carouselWidget = $(this).parents('.widget.widgetCarousel'); 1468 var parentID = $carouselWidget.data('widgetid'); 1469 var contentContainerID = $carouselWidget.parents('.pageContent').filter(":first").data('containerid'); 1470 var group = $(this).data('group'); 1471 if (parentID) { 1472 var url = '/Layout/CarouselWidget/DeleteEmptyGroup?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&group=' + group + '&parentID=' + parentID; 1473 postAction(url, null, contentContainerID, false, function () { 1474 var $reloadedCarouselWidget = $('[data-widgetid="' + parentID + '"].widget.widgetCarousel'); 1475 1476 if ($reloadedCarouselWidget.length == 0) { 1477 var $optionHandle = $('[data-originalwidgetid="' + parentID + '"].handle.options'); 1478 var currentWidgetId = $optionHandle.data('widgetid'); 1479 1480 $reloadedCarouselWidget = $('[data-widgetid="' + currentWidgetId + '"].widget.widgetCarousel'); 1481 } 1482 1483 displayGroupAndHideOthers((group > 1) ? group - 1 : 1, $reloadedCarouselWidget); 1484 });
1485 } 1486 } else { 1487 e.stopPropagation(); 1488 } 1489 }); 1490 1491 1492 1493 $('.widgetCarousel .widgetCarousel-addBtn--after, .widgetCarousel .widgetCarousel-addBtn--before').unbind('click').click(function (e) { 1494 e.preventDefault(); 1495 e.stopPropagation(); 1496 1497 var $this = $(this); 1498 1499 if (!$this.hasClass('disabled')) { 1500 var $carouselWidget = $this.parents('.widget.widgetCarousel'); 1501 var parentID = $carouselWidget.data('widgetid'); 1502 var contentContainerID = $carouselWidget.parents('.pageContent').filter(":first").data('containerid'); 1503 var group = $('.widgetCarousel-group.currentGroup', $carouselWidget).data('group'); 1504 var insertBefore = $this.hasClass('widgetCarousel-addBtn--before'); 1505 1506 if (parentID) { 1507 var url = '/Layout/CarouselWidget/AddEmptyGroup?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&group=' + group + '&insertBefore=' + insertBefore + '&parentID=' + parentID; 1508 postAction(url, null, contentContainerID, false, function () { 1509 var $reloadedCarouselWidget = $('[data-widgetid="' + parentID + '"].widget.widgetCarousel'); 1510 1511 if ($reloadedCarouselWidget.length == 0) { 1512 var $optionHandle = $('[data-originalwidgetid="' + parentID + '"].handle.options'); 1513 var currentWidgetId = $optionHandle.data('widgetid'); 1514 1515 $reloadedCarouselWidget = $('[data-widgetid="' + currentWidgetId + '"].widget.widgetCarousel'); 1516 } 1517 1518 displayGroupAndHideOthers(insertBefore ? group : group + 1, $reloadedCarouselWidget); 1519 }); 1520 } 1521 } 1522 }); 1523 1524 $('.widgetCarousel .widgetCarousel-next, .widgetCarousel .widgetCarousel-previous').unbind('click').click(function (e) { 1525 e.preventDefault(); 1526 e.stopPropagation(); 1527 1528 var $this = $(this); 1529 var $carouselWidget = $this.parents('.widget.widgetCarousel'); 1530 if (!$this.hasClass('disabled')) { 1531 var visibleGroup = parseInt($('.widgetCarousel-group.currentGroup', $carouselWidget).data('group'), 10); 1532 1533 if ($this.hasClass('widgetCarousel-next')) { 1534 visibleGroup += 1; 1535 } else if ($this.hasClass('widgetCarousel-previous')) { 1536 visibleGroup -= 1; 1537 } 1538 displayGroupAndHideOthers(visibleGroup, $carouselWidget, true); 1539 if (document.activeElement !== document.body) document.activeElement.blur(); 1540 } 1541 }); 1542 1543 $('.widgetCarousel .widgetCarouselPaging').unbind('click').click(function (e) { 1544 e.preventDefault(); 1545 e.stopPropagation(); 1546 1547 var $this = $(this); 1548 if (!$this.parent().hasClass('active')) { 1549 var $carouselWidget = $this.parents('.widget.widgetCarousel'); 1550 var group = parseInt($this.data('group'), 10); 1551 displayGroupAndHideOthers(group, $carouselWidget, true); 1552 } 1553 }); 1554 1555 //Tabbed widgets 1556 $('.cpTabs > li.newTab').unbind().click(function () { 1557 var isAccordion = $(this).parent(".accordion").length > 0; 1558 var widgetID = $(this).parents('.widget.widgetTabbed').data('widgetid'); 1559 var url = '/Layout/TabbedWidget/AddTab?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&widgetID=' + widgetID; 1560 var contentContainerID = $(this).parents('.pageContent').filter(":first").data('containerid'); 1561 var sequence = isAccordion === true ? $(this).parent(".accordion").siblings('.accordion').length : $(this).siblings('li').length; 1562 ContentCollectionInstance.newTabData = { widgetID: widgetID, sequence: sequence }; 1563 postAction(url, null, contentContainerID, false, putFocusOnNewTab); 1564 ContentCollectionInstance.PostRefreshClickTargets.push('li > a[href$="' + widgetID + '_' + sequence + '"]'); 1565 if (window.Pages && window.Pages.Widgets && window.Pages.Widgets.Tabs) { 1566 $(window.Pages.Widgets.Tabs).trigger('TabAdded'); 1567 } 1568 }); 1569 1570 $('input.newTabName').unbind('keypress').keypress(function (event) { 1571 if (event.keyCode == 13) { 1572 $(this).siblings('.newTabName.button').click(); 1573 } 1574 }); 1575 1576 $('.newTabName.button').unbind('click').click(function (e) { 1577 e.preventDefault(); 1578 var $tabbedWidget = $(this).parents('.widget.widgetTabbed'); 1579 var widgetID = $tabbedWidget.data('widgetid'); 1580 var sequence = $(this).parents('.cpTabPanel').children('.tabSequence').html(); 1581 var tabName = $(this).siblings('input.newTabName').val(); 1582 if (tabName == '') { 1583 alert(liveEditTabs.liveEditResources.TabNameRequired); 1584 return false; 1585 } 1586 var url = '/Layout/TabbedWidget/UpdateTabName?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&widgetID=' + widgetID + '&sequence=' + sequence + '&tabName=' + encodeURIComponent(tabName); 1587 var contentContainerID = $(this).parents('.pageContent').filter(":first").data('containerid'); 1588 postAction(url, null, contentContainerID, false); 1589 ContentCollectionInstance.PostRefreshClickTargets.push('li > a[href$="' + widgetID + '_' + sequence + '"]'); 1590 }); 1591 1592 $('.cpTabs .tabName.editable').unbind('blur').bind('blur', function (e) { 1593 e.preventDefault(); 1594 var $tabbedWidget = $(this).parents('.widget.widgetTabbed'); 1595 var widgetID = $tabbedWidget.data('widgetid'); 1596 var originalTabName = $(this).data('tabname'); 1597 var sequence = $(this).data('sequence'); 1598 var tabName = $(this).html(); 1599 if (tabName === '') { 1600 alert(liveEditTabs.liveEditResources.TabNameRequired); 1601 $(this).html(originalTabName); 1602 return false; 1603 } 1604 1605 if (tabName !== originalTabName) { 1606 var url = '/Layout/TabbedWidget/UpdateTabName?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&widgetID=' + widgetID + '&sequence=' + sequence + '&tabName=' + encodeURIComponent(tabName); 1607 var contentContainerID = $(this).parents('.pageContent').filter(":first").data('containerid'); 1608 postAction(url, null, contentContainerID, false); 1609 ContentCollectionInstance.PostRefreshClickTargets.push('li > a[href$="' + widgetID + '_' + sequence + '"]'); 1610 } 1611 }); 1612 1613 $('.cpTabs .tabName.editable').unbind('click').bind('click', function (e) { 1614 e.preventDefault(); 1615 e.stopPropagation(); 1616 }); 1617 1618 $('.cpTabs .tabName.editable').unbind('keypress').bind('keypress', function (e) { 1619 return event.keyCode != 13; 1620 }); 1621 1622 Core.Layout.attachTabbedWidgetTabHandlers(); 1623 1624 for (var index = 0; index < ContentCollectionInstance.PostRefreshClickTargets.length; index++) { 1625 var $tab = $(ContentCollectionInstance.PostRefreshClickTargets[index]); 1626 $tab.click(); 1627 } 1628 1629 ContentCollectionInstance.PostRefreshClickTargets = []; 1630 1631 if (options.hidePopover) { 1632 //After loading or reloading contentainers hide popovers.
1633 if (window.CommonPopoverInstance) 1634 window.CommonPopoverInstance.hideAll(false); 1635 } 1636 1637 1638 // Content Container Options 1639 $('[data-cprole="contentContainer"], [data-cprole="mainContentContainer"], [data-cprole="stickyStructuralContainer"]').find('a.handle.containerOptions').each(function () { 1640 var $handler = $(this); 1641 1642 if ($handler.data('cpPopover')) { 1643 $handler.data('cpPopover').destroy(); 1644 } 1645 1646 var $megaMenu = $(this).parents('.megaMenuContainer'); 1647 1648 var $contentContainer = $(this).parent('.pageContent').filter(':first'); 1649 var $divViewModel = $contentContainer.children(".containerOptionsViewModel"); 1650 var viewModel = JSON.parse($divViewModel.html()); 1651 1652 var tempIsLayoutPage = $('#hdnIsLayoutPage').length > 0 && Boolean.parse($('#hdnIsLayoutPage').val()); 1653 1654 if (tempIsLayoutPage != null) { 1655 viewModel.IsLayoutPage = viewModel.IsLayoutPage || tempIsLayoutPage; 1656 } 1657 1658 var data = JSON.stringify({ contentContainerOptionsViewModel: viewModel }); 1659 1660 1661 $handler.cpPopover({ 1662 url: '/Layout/ContentContainerOptions/Popup', 1663 type: 'POST', 1664 contentType: 'application/json', 1665 data: data, 1666 className: 'options adminWrap admin', 1667 onOpen: function (popoverWrap) { 1668 $megaMenu.addClass('optionOpen'); 1669 1670 if (ContentCollectionInstance.IsWorkingCopy && ContentCollectionInstance.IsLayoutPage) { 1671 $('#mustSaveTip').removeClass('hidden'); 1672 $('#contentContainerCheckboxDiv').find('[type="checkbox"]').prop('disabled', true); 1673 $('#contentContainerCheckboxDiv').find('.button.copyContainerToSelected').addClass('inactive'); 1674 } 1675 }, 1676 onInit: function (popoverWrap) { 1677 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1678 var $popOver = $("#" + popoverWrap.ID); 1679 initializeContentContainerOptionsPopup($handler, $popOver, currentContentContainerID); 1680 }, 1681 onClose: function (e) { 1682 e.preventDefault(); 1683 closeContentContainerOptionsPopup($handler, false); 1684 } 1685 }); 1686 }); 1687 1688 function initializeContentContainerOptionsPopup($handler, $popOver, currentContentContainerID) { 1689 $popOver.find('.button.nextAction').unbind("click").bind("click", function (e) { 1690 e.preventDefault(); 1691 var isSmoothScrolling = false; 1692 if ($('#cpCommonPopover').find('[name=IsSmoothScrolling]').length > 0) { 1693 isSmoothScrolling = $('#cpCommonPopover').find('[name=IsSmoothScrolling]')[0].checked; 1694 } 1695 var json = { contentContainerID: currentContentContainerID, ColumnAlignment: $('#cpCommonPopover').find('[name=columnAlignment]').val(), Breakpoint: $('#cpCommonPopover').find('[name=contentContainerbreakpoint]').val(), IsSmoothScrolling: isSmoothScrolling }; 1696 AJAX("/Layout/ContentContainerOptions/Save", 'POST', json, function (response) { 1697 closeContentContainerOptionsPopup($handler); 1698 ContentCollectionInstance.reloadContent(); 1699 }, true); 1700 }); 1701 $popOver.find('.button.cancel').unbind("click").bind("click", function (e) { 1702 e.preventDefault(); 1703 closeContentContainerOptionsPopup($handler); 1704 }); 1705 1706 $popOver.find('.button.copyContainerToSelected').unbind("click").bind("click", function (e) { 1707 e.preventDefault(); 1708 1709 if (!$(this).hasClass('inactive')) { 1710 var data = {}; 1711 var $containerDiv = $('#contentContainerCheckboxDiv'); 1712 1713 var checkBoxes = $containerDiv.find('[type="checkbox"]:checked'); 1714 var containers = new Array(); 1715 1716 for (var i = 0; i < checkBoxes.length; i++) { 1717 var $cb = $(checkBoxes[i]); 1718 1719 containers.push({ 1720 ContentContainerID: $cb.attr('data-copycontainerid'), 1721 LayoutPageID: $cb.attr('data-copycontainerpageid') 1722 }); 1723 } 1724 1725 data.containers = containers; 1726 data.sourceContentContainerId = $containerDiv.attr('data-sourceContentContainerId'); 1727 data.sourceContentCollectionId = $('#hdnContentCollectionID').val(); 1728 1729 AJAX('/Layout/ContentContainerOptions/CopyContainerContents', 'POST', JSON.stringify(data), 1730 function (response) { 1731 alert(response.Message); 1732 closeContentContainerOptionsPopup($handler); 1733 }, 1734 true, "application/json; charset=utf-8"); 1735 } 1736 }); 1737 1738 $popOver.find('.copyContainerLayoutPage').unbind("change").bind("change", function () { 1739 if ($('#contentContainerCheckboxDiv').find('[type="checkbox"]:checked').length == 0) { 1740 $('#contentContainerCheckboxDiv').find('.button.copyContainerToSelected').addClass('inactive'); 1741 } 1742 else { 1743 $('#contentContainerCheckboxDiv').find('.button.copyContainerToSelected').removeClass('inactive'); 1744 } 1745 }); 1746 } 1747 1748 //Inheritance Content Containers 1749 $('[data-cprole="contentContainer"]').find('a.handle.inheritance').each(function () { 1750 var $handler = $(this); 1751 1752 if ($handler.data('cpPopover')) { 1753 $handler.data('cpPopover').destroy(); 1754 } 1755 1756 var $megaMenu = $(this).parents('.megaMenuContainer'); 1757 1758 var $contentContainer = $(this).parent('.pageContent').filter(':first'); 1759 var $divViewModel = $contentContainer.children(".contentInheritanceViewModel"); 1760 var viewModel = JSON.parse($divViewModel.html());
1761 var data = JSON.stringify({ viewModel: viewModel }); 1762 $handler.cpPopover({ 1763 url: '/Layout/ContentInheritance/InheritancePopup', 1764 type: 'POST', 1765 contentType: 'application/json', 1766 data: data, 1767 className: 'options adminWrap admin inheritance', 1768 onOpen: function (popoverWrap) { 1769 $megaMenu.addClass('optionOpen'); 1770 }, 1771 onInit: function (popoverWrap) { 1772 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 1773 var $popOver = $("#" + popoverWrap.ID); 1774 initializeInheritancePopup($handler, $popOver, currentContentContainerID); 1775 }, 1776 onClose: function (e) { 1777 e.preventDefault(); 1778 closeInheritancePopup($handler, false); 1779 } 1780 }); 1781 }); 1782 1783 //Popovers for feature widgets. 1784 $("a.handle.openPopOver.featureWidget.options").each(function () { 1785 var $handler = $(this); 1786 attachFeatureWidgetOptionsHandler($handler); 1787 }); 1788 1789 attachHeaderClickHandlers(); 1790 } 1791 if (window.Pages) { 1792 $(window.Pages).trigger('ContainersInitialized'); 1793 } 1794} 1795 1796function attachHeaderClickHandlers() { 1797 $('.widgetHeader h2, .widgetHeader h3').unbind('mousedown').mousedown(function (e) { 1798 e.stopPropagation(); 1799 }); 1800 1801 $('.widgetHeader h2, .widgetHeader h3').unbind('blur').blur(function (e) { 1802 var $this = $(this), 1803 widgetID = $this.closest('.tabbedWidget, .inner.col').children('.widgetID').val(), 1804 contentContainerID = $this.closest('.pageContent').data('containerid'), 1805 headerText = $this.html(), 1806 url = '/Layout/WidgetUpdateHeader/Update'; 1807 1808 if ($this.data('headertext') != headerText) { 1809 var json = { contentCollectionID: ContentCollectionInstance.ContentCollectionID, contentContainerID: contentContainerID, widgetID: widgetID, headerText: headerText }; 1810 1811 AJAX(url, 'POST', json, function (response) { 1812 if (ContentCollectionInstance.IsWorkingCopy) { 1813 $this.data('headertext', headerText); 1814 contentUpdated(); 1815 } else { 1816 ContentCollectionInstance.reloadContent(); 1817 } 1818 }); 1819 } 1820 }); 1821} 1822 1823function attachFeatureWidgetOptionsHandler($handler) { 1824 if ($handler.data('cpPopover')) { 1825 $handler.data('cpPopover').destroy(); 1826 } 1827 1828 var $divViewModel = $handler.nextAll(".optionsViewModel"); 1829 var viewModel = JSON.parse($divViewModel.html()); 1830 var url = "/" + viewModel.area + "/" + viewModel.controller.replace('Get', '') + "/Options"; 1831 var data = JSON.stringify({ pageID: viewModel.pageID, widgetID: viewModel.widgetID, moduleID: viewModel.moduleID, contentContainerID: viewModel.contentContainerID }); 1832 $handler.cpPopover({ 1833 url: url, 1834 type: 'POST', 1835 contentType: 'application/json', 1836 data: data, 1837 className: 'options adminWrap', 1838 onOpen: function (popoverWrap) { 1839 var $widgetOptionSet = popoverWrap.$popoverContent.find("#widgetOptionSet"); 1840 if ($widgetOptionSet.length > 0) 1841 $widgetOptionSet.data("originalSelected", $widgetOptionSet.val()); 1842 }, 1843 onClose: function (e, popoverWrap) { 1844 e.preventDefault(); 1845 window.CommonPopoverInstance.hide(popoverWrap); 1846 $(document.activeElement).change(); 1847 }, 1848 makeAjaxCallEverytime: true 1849 }); 1850} 1851 1852function attachRelatedDocumentsHandlers() { 1853 //Related Documents widget drag & drop sorting 1854 $('.widget.widgetRelatedDocuments').each(function () { 1855 var $widget = $(this); 1856 var columnCount = $widget.data('columncount'); 1857 var axis = columnCount == 1 ? "y" : null; 1858 $widget.find('.semanticList.bullets').sortable({ 1859 axis: axis, 1860 connectWith: '.semanticList.bullets', 1861 cursor: "move", 1862 stop: dragAndDropStopped 1863 }); 1864 1865 $widget.find('.sortableWidgetTitle').sortable({ 1866 axis: "y", 1867 handle: '.grippy', 1868 connectWith: '.sortableWidgetTitle', 1869 cancel: 'input,textarea,button,select,option,.disableSortable,.add,.addFile', 1870 cursor: "move", 1871 helper: function (e, item) { //create custom helper 1872 if (item.hasClass('widgetTitle')) { 1873 var dom = []; 1874 1875 item.each(function (key, value) { 1876 dom.push(value.outerHTML); 1877 }); 1878 1879 var sectionId = item.attr('data-section-id'); 1880 1881 $('[data-col-section-id="' + sectionId + '"]').each(function (key, value) { 1882 var $value = $(value); 1883 1884 dom.push(value.outerHTML); 1885 1886 $value.addClass('hidden'); 1887 });
1888 1889 return $('<div>' + dom.join('') + '</div>'); 1890 } 1891 else { 1892 return item; 1893 } 1894 }, 1895 stop: dragAndDropStopped 1896 }); 1897 1898 $widget.find('.remove.section').unbind("click").bind("click", function (e) { 1899 var $this = $(this); 1900 var $section = $this.closest('.relatedDocumentsSection'); 1901 var $widget = $this.closest('.widgetRelatedDocuments'); 1902 if ($section.find('li.widgetItem').length > 0 && !confirm(window.ContentCollectionInstance.resources.ConfirmRelatedDocumentsSectionDelete)) { 1903 e.stopPropagation(); 1904 return false; 1905 } 1906 1907 $section.remove(); 1908 ContentCollectionInstance.RelatedDocumentWidgetIDToEdit = $widget.data('widgetid'); 1909 saveRelatedDocumentWidgetContent('false'); 1910 return false; 1911 }); 1912 1913 attachDocumentSections($widget); 1914 1915 $widget.undelegate('focus').delegate('h3.widgetTitle', 'focus', sectionHeadingFocus); 1916 $widget.undelegate('blur').delegate('h3.widgetTitle', 'blur', sectionHeadingBlur); 1917 $widget.undelegate('click').delegate('h3.widgetTitle', 'click', sectionHeadingClick); 1918 $widget.undelegate('keydown').delegate('h3.widgetTitle', 'keydown', sectionHeadingKeyDown); 1919 }); 1920} 1921 1922function dragAndDropStopped(event, ui) { 1923 var $item = $(ui.item); 1924 var $widget = $item.closest('.widgetRelatedDocuments'); 1925 1926 ContentCollectionInstance.RelatedDocumentWidgetIDToEdit = $widget.data('widgetid'); 1927 1928 $widget.find('.relatedDocumentsSection').each(function () { 1929 var documentIDs = ''; 1930 var $section = $(this); 1931 1932 $section.find('li.widgetItem').each(function () { 1933 documentIDs += $(this).data('documentid') + ','; 1934 }); 1935 $section.data('sorteddocumentids', documentIDs); 1936 }); 1937 1938 //This is switching the loaded options popup, if any, to reflect a manual sort order 1939 $('.widgetRelatedOptions[data-widgetid="' + ContentCollectionInstance.RelatedDocumentWidgetIDToEdit + '"] #sequence').val('4'); 1940 //Passing 'true' for the setManualSortOrder parameters sets the sort order on the server 1941 saveRelatedDocumentWidgetContent('true'); 1942} 1943 1944function attachDocumentSections($widget) { 1945 $('.widgetTitle', $widget).each(function () { 1946 $(this).attr('data-section-id', generateUUID()); 1947 }); 1948 1949 $widget.find('.col').each(function () { 1950 var $this = $(this); 1951 1952 var sectionHeaderId = $this.prevAll('.widgetTitle:first').attr('data-section-id'); 1953 1954 $this.attr('data-col-section-id', sectionHeaderId); 1955 }); 1956} 1957 1958function closeContentContainerOptionsPopup($handler) { 1959 $handler.data("cpPopover").hide(); 1960} 1961 1962function closeInheritancePopup($handler) { 1963 $handler.data("cpPopover").hide(); 1964} 1965 1966function initializeInheritancePopup($handler, $popOver, currentContentContainerID) { 1967 //Inheritance popups initialization. 1968 1969 $popOver.find('.cancelStopInheritanceOptions').unbind("click").bind("click", function (e) { 1970 e.preventDefault(); 1971 closeInheritancePopup($handler); 1972 }); 1973 1974 $popOver.find('.stopInheritanceOptions').unbind("click").bind("click", function (e) { 1975 e.preventDefault(); 1976 $(this).parent().parent().next().fadeToggle(300); 1977 }); 1978 1979 $popOver.find('.startEmptyContainer, .startCopyCurrentContainer').unbind("click").bind("click", function (e) { 1980 e.preventDefault(); 1981 var contentCollectionIDToCopyFrom = ($(this).hasClass('startCopyCurrentContainer')) ? $(this).data("contentCollectionID") : null; 1982 var ancestorStructureId = $('#ancestorStructureId').val() == undefined ? null : $('#ancestorStructureId').val(); 1983 var json = { contentCollectionID: ContentCollectionInstance.ContentCollectionID, contentContainerID: currentContentContainerID, contentCollectionIDToCopyFrom: contentCollectionIDToCopyFrom, ancestorStructureId: parseInt(ancestorStructureId, 10) }; 1984 AJAX("/Layout/ContentInheritance/StopInheritanceFromAncestor", 'POST', json, function (response) { 1985 closeInheritancePopup($handler); 1986 ContentCollectionInstance.reloadContent(); 1987 }, true); 1988 }); 1989 1990 $popOver.find('.stopInheritanceToSubpages').unbind("click").bind("click", function (e) { 1991 e.preventDefault(); 1992 if (ContentCollectionInstance.IsWorkingCopy) { 1993 alert("It is not possible to stop inheriting to Subpages from a working copy. Save your changes before doing so."); 1994 } 1995 else { 1996 var json = { pageID: ContentCollectionInstance.PageID, contentCollectionID: ContentCollectionInstance.ContentCollectionID, contentContainerID: currentContentContainerID }; 1997 AJAX("/Layout/ContentInheritance/StopInheritanceToSubpages", 'POST', json, function (response) { 1998 closeInheritancePopup($handler); 1999 ContentCollectionInstance.CurrentContentContainerIDs.push(currentContentContainerID); 2000 ContentCollectionInstance.reloadContent(); 2001 }, true); 2002 } 2003 }); 2004 2005 $popOver.find("input[type=radio].containerInheritRadio").unbind("change").bind("change", function () { 2006 if ($(this).is(':checked')) { 2007 var json; 2008 if ($(this).val() == "containerInheritToSubpages") { 2009 if (ContentCollectionInstance.IsWorkingCopy) { 2010 closeInheritancePopup($handler); 2011 openCpModal({ 2012 title: 'Save and Set Inheritance?', 2013 className: 'notContent newCP adminWrap actOnWhich', 2014 isFrontEnd: false, 2015 url: '/Layout/ContentInheritance/InheritToSubaPagesPopupConfirm?contentContainerID=' + currentContentContainerID 2016 });
2017 } 2018 else { 2019 json = { pageID: ContentCollectionInstance.PageID, contentCollectionID: ContentCollectionInstance.ContentCollectionID, contentContainerID: currentContentContainerID }; 2020 AJAX("/Layout/ContentInheritance/StartInheritanceToSubpages", 'POST', json, function (response) { 2021 closeInheritancePopup($handler); 2022 ContentCollectionInstance.CurrentContentContainerIDs.push(currentContentContainerID); 2023 ContentCollectionInstance.reloadContent(); 2024 }, true); 2025 } 2026 } else if ($(this).val() == "containerInheritFromAncestor") { 2027 json = { pageID: ContentCollectionInstance.PageID, moduleID: ContentCollectionInstance.ModuleID, contentCollectionID: ContentCollectionInstance.ContentCollectionID, contentContainerID: currentContentContainerID }; 2028 AJAX("/Layout/ContentInheritance/StartInheritanceFromAncestor", 'POST', json, function (response) { 2029 closeInheritancePopup($handler); 2030 ContentCollectionInstance.reloadContent(); 2031 }, true); 2032 } else { 2033 alert("This should not be possible to do."); 2034 } 2035 } 2036 }); 2037 2038 $popOver.find('.startInheritanceToSubpagesPublishVersion').unbind("click").bind("click", function (e) { 2039 e.preventDefault(); 2040 var hidePage = $(this).hasClass("hidePage"); 2041 var json = { pageID: ContentCollectionInstance.PageID, versionID: ContentCollectionInstance.VersionID, hidePage: hidePage, contentContainerID: currentContentContainerID }; 2042 AJAX("/Layout/ContentInheritance/PublishVersionAndStartInheritanceToSubpages", 'POST', json, function (response) { 2043 closeInheritancePopup($handler); 2044 $('#divVersion' + ContentCollectionInstance.VersionID).data("status", "Published"); 2045 ContentCollectionInstance.reloadContent(); 2046 updateVersionList(ContentCollectionInstance.VersionID); 2047 }, true); 2048 }); 2049} 2050 2051//************************************Widget Content save related functions*************************************// 2052function openRelatedDocumentsWidgetModal(link, widgetID) { 2053 var promise = null; 2054 var $activeElement = $(document.activeElement); 2055 //Defined globally for related documents 2056 documentsToInsert = []; 2057 foldersToInsert = []; 2058 2059 if ($activeElement != null && $activeElement.hasClass('widgetTitle') 2060 && $activeElement.prop('tagName').toLowerCase() === "h3" 2061 && $activeElement.parent() != null 2062 && $activeElement.parent().hasClass("relatedDocumentsSection")) { 2063 promise = sectionHeadingBlurAction($activeElement); 2064 } 2065 2066 var open = function ($element, widgetId) { 2067 ContentCollectionInstance.RelatedDocumentWidgetIDToEdit = widgetId; 2068 callbackfnDocumentCenter = addRelatedDocuments; 2069 ContentCollectionInstance.RelatedDocumentSectionID = $element.attr('data-section-id'); 2070 var className = 'relatedDocuments'; 2071 if (window.FeatureToggles.isActive("CMS.DocumentCenter.ReplaceTelerikTreeAndGridWithReact")) { 2072 className = 'relatedDocuments reactModal'; 2073 } 2074 openCpModal({ 2075 title: 'Related Documents Widget', 2076 className: className, 2077 isFrontEnd: false, 2078 useIframe: true, 2079 iframeHeight: '600px', 2080 draggable: true, 2081 url: '/Admin/DocumentCenter/FolderForModal/Index?loadSource=2&requestingModuleID=76' 2082 }); 2083 }; 2084 2085 if (promise == null) { 2086 open($(link).closest('.relatedDocumentsSection').find('h3.widgetTitle'), widgetID); 2087 } else { 2088 $.when(promise).done(function () { 2089 return; 2090 }); 2091 } 2092} 2093 2094function assembleRelatedDocumentsJson() { 2095 var widgetID = ContentCollectionInstance.RelatedDocumentWidgetIDToEdit; 2096 var widgetJson = []; 2097 2098 $('#widgetRelDoc' + widgetID + ' .relatedDocumentsSection').each(function () { 2099 var $section = $(this); 2100 var $sectionTitle = $section.find('h3.widgetTitle:first'); 2101 var sectionTitleHtml = $sectionTitle.html() || ''; 2102 var sectionTitleText = $.trim($sectionTitle.text()); 2103 var title = sectionTitleText === '' || sectionTitleText == window.ContentCollectionInstance.resources.ClickHereToType ? '' : encodeURIComponent(sectionTitleHtml); 2104 var documentIDs = $section.data('documentids'); 2105 var folderIds = $section.data('folderids'); 2106 var sortedDocumentIds = $section.data('sorteddocumentids'); 2107 2108 widgetJson.push({ Title: title, DocumentIDs: documentIDs, FolderIds: folderIds, SortedDocumentIds: sortedDocumentIds }); 2109 }); 2110 2111 return widgetJson; 2112} 2113 2114function removeRelatedDoc(link, documentID, widgetID, folderID) { 2115 ContentCollectionInstance.RelatedDocumentWidgetIDToEdit = widgetID; 2116 ContentCollectionInstance.RelatedDocumentSectionID = $(link).closest('.relatedDocumentsSection').find('h3.widgetTitle').data('section-id'); 2117 var $section = $('[data-section-id="' + ContentCollectionInstance.RelatedDocumentSectionID + '"]').parent(); 2118 if ($section.data("folderids").indexOf(folderID) != -1) { 2119 var result = 2120 window.confirm( 2121 'Removing this document will also remove all other related folder document(s) from this widget. The document(s) will remain in Document Center. Would you like to proceed?'); 2122 if (result) { 2123 $section.data('documentids', $section.data('documentids').replace(documentID + ',', '')); 2124 $section.data('folderids', $section.data('folderids').replace(folderID + ',', '')); 2125 $section.data('sorteddocumentids', $section.data('sorteddocumentids').replace(folderID + ',', '')); 2126 } 2127 } else { 2128 $section.data('documentids', $section.data('documentids').replace(documentID + ',', '')); 2129 $section.data('sorteddocumentids', $section.data('sorteddocumentids').replace(folderID + ',', '')); 2130 } 2131 saveRelatedDocumentWidgetContent('false'); 2132} 2133 2134function addRelatedDocuments(json) { 2135 var $section = $('[data-section-id="' + ContentCollectionInstance.RelatedDocumentSectionID + '"]').parent(); 2136 var documentids = $section.data('documentids').toString(); 2137 var folderids = $section.data('folderids').toString(); 2138 2139 $section.data('documentids', documentids + (documentids.substr(documentids.length - 1) == ',' ? '' : ',') + json.documentIDs); 2140 $section.data('folderids', folderids + (folderids.substr(folderids.length - 1) == ',' ? '' : ',') + json.folderIds); 2141 2142 saveRelatedDocumentWidgetContent('false'); 2143} 2144 2145function saveRelatedDocumentWidgetContent(setManualSortOrder) { 2146 var sectionsJson = JSON.stringify(assembleRelatedDocumentsJson()); 2147 var widgetID = ContentCollectionInstance.RelatedDocumentWidgetIDToEdit; 2148 var contentContainerID = $('#widgetRelDoc' + widgetID).parents('.pageContent').filter(":first").data('containerid'); 2149 var url = '/ContentWidgets/RelatedDocumentsSave/Save?contentCollectionID=' + ContentCollectionInstance.ContentCollectionID + '&widgetID=' + widgetID + '&pageID=' + ContentCollectionInstance.PageID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerID=' + contentContainerID + '&setManualSortOrder=' + setManualSortOrder; 2150 2151 closeCpModal(); 2152 2153 var deferred = $.Deferred(); 2154 2155 AJAX(url, 'POST', { 'sectionsJson': sectionsJson }, function (response) { 2156 if (ContentCollectionInstance.IsWorkingCopy || isWidgetUnderMegaMenu($('#widgetRelDoc' + widgetID))) { 2157 $('#divRelatedDocuments_' + widgetID).parent().replaceWith(response);
2158 contentUpdated(); 2159 2160 deferred.resolve(); 2161 } 2162 else { 2163 var $widget = $('#divRelatedDocuments_' + widgetID).parent(); 2164 if ($widget.parent().hasClass('tabbedWidget')) { 2165 var sequence = $widget.parent().find('tabSequence').html(); 2166 ContentCollectionInstance.PostRefreshClickTargets.push('li > a[href$="' + widgetID + '_' + sequence + '"]'); 2167 } 2168 ContentCollectionInstance.CurrentContentContainerIDs.push(contentContainerID); 2169 ContentCollectionInstance.reloadContent(null, function () { 2170 deferred.resolve(); 2171 }); 2172 } 2173 }); 2174 2175 return deferred; 2176} 2177 2178function generateUUID() { 2179 var d = new Date().getTime(); 2180 var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { 2181 var r = (d + Math.random() * 16) % 16 | 0; 2182 d = Math.floor(d / 16); 2183 return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16); 2184 }); 2185 return uuid; 2186} 2187 2188function addRelatedDocumentSection(widgetID) { 2189 ContentCollectionInstance.RelatedDocumentWidgetIDToEdit = widgetID; 2190 ContentCollectionInstance.RelatedDocumentSectionID = generateUUID(); 2191 2192 var $relatedDocuments = $('#divRelatedDocuments_' + widgetID); 2193 2194 $relatedDocuments.find('div.widgetBody div.row') 2195 .append('<div class="relatedDocumentsSection" data-documentids="" data-folderids=""><h3 class="widgetTitle" style="clear: left;" data-section-id="' + ContentCollectionInstance.RelatedDocumentSectionID + '"><em class="meta">' + window.ContentCollectionInstance.resources.ClickHereToType + '</em></h3>'); 2196 2197 saveRelatedDocumentWidgetContent('false'); 2198} 2199 2200function sectionHeadingFocus() { 2201 var $this = $(this); 2202 2203 $this.addClass('disableSortable'); 2204 2205 if ($this.text() === window.ContentCollectionInstance.resources.ClickHereToType) { 2206 $this.html(''); 2207 } 2208 2209 $this.unbind('mousedown').mousedown(function (e) { 2210 e.stopPropagation(); 2211 }); 2212} 2213 2214function sectionHeadingClick() { 2215 $(this).focus(); 2216} 2217 2218function sectionHeadingBlur() { 2219 var $this = $(this); 2220 2221 sectionHeadingBlurAction($this); 2222} 2223 2224function sectionHeadingBlurAction($this) { 2225 $this.removeClass('disableSortable'); 2226 $this.unbind('mousedown'); 2227 2228 if ($this.data('section-header-text') != $this.html()) { 2229 var $widget = $this.closest('.widgetRelatedDocuments'); 2230 2231 ContentCollectionInstance.RelatedDocumentWidgetIDToEdit = $widget.data('widgetid'); 2232 return saveRelatedDocumentWidgetContent('false'); 2233 } else if ($this.html() === '') { 2234 $this.html('<em class="meta">' + window.ContentCollectionInstance.resources.ClickHereToType + '</em>'); 2235 } 2236 2237 return null; 2238} 2239 2240function sectionHeadingMouseUp() { 2241 var rangeObject = window.getSelection().rangeCount ? window.getSelection().getRangeAt(0) : null; 2242 if (rangeObject && (rangeObject.startContainer === rangeObject.endContainer || $(rangeObject.startContainer).closest('h3.widgetTitle').get(0) === $(rangeObject.endContainer).closest('h3.widgetTitle').get(0))) { 2243 var $elementSelected = $(rangeObject.startContainer.parentNode); 2244 if ($elementSelected.is('h3.widgetTitle')) { 2245 $elementSelected.select(); 2246 } else { 2247 $elementSelected.closest('h3.widgetTitle').focus(); 2248 } 2249 } 2250} 2251 2252function sectionHeadingKeyDown(e) { 2253 var Enum = { 2254 keys: { 2255 backspace: 8, 2256 enter: 13, 2257 del: 46 2258 } 2259 }; 2260 2261 var $item = $(this); 2262 var $widget = $item.closest('.widgetRelatedDocuments'); 2263 2264 var returnValue = null; 2265 switch (e.keyCode) { // Enter - Create new section heading 2266 case Enum.keys.enter: 2267 e.preventDefault(); 2268 break; 2269 } 2270 return returnValue; 2271} 2272 2273//************************************Widget Content save related functions*************************************// 2274 2275function ajaxCallWidgetsResources(url, json, id) { 2276 $.ajax({ 2277 url: url, 2278 type: 'GET', 2279 cache: false, 2280 async: false, //Widgets resources have to be called synchronously 2281 data: json, 2282 success: function (response) { 2283 $('#' + id).html(response); 2284 }, 2285 error: function (xhr, textStatus, exception) { 2286 alert("Error: " + xhr.statusText + "\nStatus: " + xhr.status); 2287 } 2288 }); 2289} 2290 2291function handleWidgetOptionsPopOver(widgetID) { 2292 $(window.Pages).unbind('ContentReload.OptionsPopOver'); 2293 if (!ContentCollectionInstance.IsWorkingCopy) { 2294 $(window.Pages).bind('ContentReload.OptionsPopOver', function () { 2295 $(window.Pages).unbind('ContentReload.OptionsPopOver');
2296 var $handler = $('.handle.options[data-originalwidgetid=' + widgetID + ']'); 2297 var workingCopyWidgetID = $handler.data('widgetid'); 2298 if (workingCopyWidgetID) { 2299 var $widget = $('#' + ($handler.data('widgetsuffix') || "") + workingCopyWidgetID); 2300 if ($widget.length == 0) { 2301 $widget = $('[data-widget-id=' + workingCopyWidgetID + ']'); 2302 } 2303 if ($widget.length > 0 && $widget.parents('.widget.widgetTabbed').length > 0) { 2304 var sequence = $widget.parent().find('.tabSequence').html(); 2305 var tabWidgetID = $widget.parents('.widget.widgetTabbed').data('widgetid'); 2306 $("li > a[href$='" + tabWidgetID + "_" + sequence + "']").trigger("click"); 2307 } 2308 } 2309 $handler.trigger('click'); 2310 }); 2311 } 2312} 2313 2314function initAdvancedWidgetOptionsPopOver(collapseControlID) { 2315 collapseControlID = collapseControlID || 'advancedWidgetOptions'; 2316 var $expandCollapse = $('#' + collapseControlID); 2317 var $box = $expandCollapse.next(); 2318 var advancedOptions = $box.find('li'); 2319 2320 if (advancedOptions.length == 0) { 2321 $expandCollapse.hide(); 2322 $box.hide(); 2323 } else { 2324 $expandCollapse.show(); 2325 2326 $expandCollapse.each(function () { 2327 if ($(this).hasClass('collapsed')) { 2328 $box.hide(); 2329 } 2330 }); 2331 2332 $expandCollapse.unbind("click").bind("click", function (e) { 2333 e.preventDefault(); 2334 2335 if ($(this).hasClass('collapsed')) { 2336 $box.slideDown(200); 2337 $(this).removeClass('collapsed').addClass('expanded'); 2338 } else { 2339 $box.slideUp(200); 2340 $(this).removeClass('expanded').addClass('collapsed'); 2341 } 2342 }); 2343 2344 var $basicOptions = $expandCollapse.prev(); 2345 if ($basicOptions.find('li').length == 0) { 2346 $box.show(); 2347 $expandCollapse.removeClass('collapsed').addClass('expanded'); 2348 } 2349 } 2350} 2351 2352function contentUpdated() { 2353 //This function is being called from several other widgets. 2354 if (typeof (redrawContextualInnerToolbar) == "function") { 2355 redrawContextualInnerToolbar(ContentCollectionInstance.PageID, ContentCollectionInstance.VersionID); 2356 } 2357 if (!window.isRemoveSetHeights) 2358 SetHeights(); 2359 flipHandlesIfNecessary(); 2360 setTabbedWidgetsTabHeight(); 2361 attachHeaderClickHandlers(); 2362 attachRelatedDocumentsHandlers(); 2363 if (window.Pages) { 2364 $(window.Pages).trigger('ContentChanged'); 2365 } 2366} 2367 2368function openTabbedWidgetOptionsModal($handler) { 2369 if ($handler.data('cpPopover')) { 2370 $handler.data('cpPopover').destroy(); 2371 } 2372 2373 var contentContainerExternalID = attrOrProps($handler.parents('[data-cprole$="ontentContainer"]'), 'id'); 2374 var currentContentContainerID = $handler.parents('.pageContent').filter(':first').data('containerid'); 2375 var url = '/Layout/TabbedWidget/Options?widgetID=' + $handler.data('widgetid') + '&pageID=' + ContentCollectionInstance.PageID + '&moduleID=' + ContentCollectionInstance.ModuleID + '&contentContainerExternalID=' + contentContainerExternalID + "&contentContainerID=" + currentContentContainerID; 2376 $handler.cpPopover({ 2377 url: url, 2378 type: 'post', 2379 className: 'options adminWrap', 2380 onClose: function (e, popoverWrap) { 2381 e.preventDefault(); 2382 window.CommonPopoverInstance.hide(popoverWrap); 2383 $(document.activeElement).change(); 2384 } 2385 }); 2386} 2387 2388//Returns a bool based on whether the widget is under megamenu or not. 2389//Any change in a widget within the megamenu does not affect the working copy state of the contentcollection. This function is being called from various widgets, if this turns out to be true, there is no need to call the reloadContent function 2390//because that tries to refresh all the content containers in the current contentcollectioninstance, which is not required while making changes under megamenu. Vishal 2391function isWidgetUnderMegaMenu($widget) { 2392 return $widget.parents('.megaMenu').length > 0; 2393}
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.