From 6be86022955cf37d09014648e800ce37c7faabda Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 22 Jun 2012 13:02:35 +1200 Subject: [PATCH] BUG: Update MenuTitle whenever Title is changed and the value of Title used to be. Bubble the change to update LHS tree. (Trac #7507) We had to use .data() to track OrigVal manually, but this means that the MenuTitle can be updated much more reliably. In addition, we trigger the change-handler for MenuTitle that updates the LHS tree. Unfortunately, we couldn't simply use .trigger('change') because it broken in IE8 due to an entwine bug. --- javascript/CMSMain.EditForm.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/javascript/CMSMain.EditForm.js b/javascript/CMSMain.EditForm.js index e0d10c5a..85218d8e 100644 --- a/javascript/CMSMain.EditForm.js +++ b/javascript/CMSMain.EditForm.js @@ -24,6 +24,8 @@ // Constructor: onmatch onmatch : function() { var self = this; + + self.data('OrigVal', self.val()); var form = self.parents('form'); var url_segment = $('.field.urlsegment', form).find(':text'); @@ -33,14 +35,18 @@ if(url_segment.length > 0) { this.bind('change', function(e) { + var origTitle = self.data('OrigVal'); var title = self.val(); + self.data('OrigVal', title); + // Criteria for defining a "new" page if ((url_segment.val().indexOf('new') == 0) && live_url_segment.val() == '') { - self.updateRelatedFields(title); self.updateURLSegment(title); } else { $('.update', self.parent()).show(); } + + self.updateRelatedFields(title, origTitle); self.updateBreadcrumbLabel(title); }); } @@ -54,12 +60,20 @@ /** * Function: updateRelatedFields * - * Update the related fields - * (String) title + * Update the related fields if appropriate + * (String) title The new title + * (Stirng) origTitle The original title */ - updateRelatedFields: function(title) { - var form = this.parents('form'); - form.find('input[name=MetaTitle], input[name=MenuTitle]').val(title); + updateRelatedFields: function(title, origTitle) { + // Update these fields only if their value was originally the same as the title + this.parents('form').find('input[name=MetaTitle], input[name=MenuTitle]').each(function() { + var $this = $(this); + if($this.val() == origTitle) { + $this.val(title); + // Onchange bubbling didn't work in IE8, so .trigger('change') couldn't be used + if($this.updatedRelatedFields) $this.updatedRelatedFields(); + } + }); }, /** @@ -122,6 +136,13 @@ */ $('.cms-edit-form input[name=MenuTitle]').entwine({ onchange: function() { + this.updatedRelatedFields(); + }, + + /** + * Same as the onchange handler but callable as a method + */ + updatedRelatedFields: function() { var menuTitle = this.val(); this.updateTreeLabel(menuTitle); },