OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /* | 5 /* |
6 * Base class that Ribbon uses to display photos. | 6 * Base class that Ribbon uses to display photos. |
7 */ | 7 */ |
8 | 8 |
9 function RibbonClient() {} | 9 function RibbonClient() {} |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 this.closeCallback_ = closeCallback; | 30 this.closeCallback_ = closeCallback; |
31 this.metadataProvider_ = metadataProvider; | 31 this.metadataProvider_ = metadataProvider; |
32 | 32 |
33 this.displayStringFunction_ = function(id) { | 33 this.displayStringFunction_ = function(id) { |
34 return displayStringFunction('GALLERY_' + id.toUpperCase()); | 34 return displayStringFunction('GALLERY_' + id.toUpperCase()); |
35 }; | 35 }; |
36 | 36 |
37 this.onFadeTimeoutBound_ = this.onFadeTimeout_.bind(this); | 37 this.onFadeTimeoutBound_ = this.onFadeTimeout_.bind(this); |
38 this.fadeTimeoutId_ = null; | 38 this.fadeTimeoutId_ = null; |
39 this.mouseOverTool_ = false; | 39 this.mouseOverTool_ = false; |
| 40 this.imageChanges_ = 0; |
40 | 41 |
41 this.initDom_(shareActions); | 42 this.initDom_(shareActions); |
42 } | 43 } |
43 | 44 |
44 Gallery.prototype = { __proto__: RibbonClient.prototype }; | 45 Gallery.prototype = { __proto__: RibbonClient.prototype }; |
45 | 46 |
46 Gallery.open = function(parentDirEntry, items, selectedItem, | 47 Gallery.open = function(parentDirEntry, items, selectedItem, |
47 closeCallback, metadataProvider, shareActions, displayStringFunction) { | 48 closeCallback, metadataProvider, shareActions, displayStringFunction) { |
48 var container = document.querySelector('.gallery'); | 49 var container = document.querySelector('.gallery'); |
49 container.innerHTML = ''; | 50 container.innerHTML = ''; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 this.container_.appendChild(this.closeButton_); | 90 this.container_.appendChild(this.closeButton_); |
90 | 91 |
91 this.imageContainer_ = doc.createElement('div'); | 92 this.imageContainer_ = doc.createElement('div'); |
92 this.imageContainer_.className = 'image-container'; | 93 this.imageContainer_.className = 'image-container'; |
93 this.container_.appendChild(this.imageContainer_); | 94 this.container_.appendChild(this.imageContainer_); |
94 | 95 |
95 this.toolbar_ = doc.createElement('div'); | 96 this.toolbar_ = doc.createElement('div'); |
96 this.toolbar_.className = 'toolbar tool dimmable'; | 97 this.toolbar_.className = 'toolbar tool dimmable'; |
97 this.container_.appendChild(this.toolbar_); | 98 this.container_.appendChild(this.toolbar_); |
98 | 99 |
| 100 var filenameSpacer = doc.createElement('div'); |
| 101 filenameSpacer.className = 'filename-spacer'; |
| 102 this.toolbar_.appendChild(filenameSpacer); |
| 103 |
| 104 this.filenameEdit_ = doc.createElement('input'); |
| 105 this.filenameEdit_.setAttribute('type', 'text'); |
| 106 this.filenameEdit_.addEventListener('blur', |
| 107 this.updateFilename_.bind(this)); |
| 108 this.filenameEdit_.addEventListener('keydown', |
| 109 this.onFilenameEditKeydown_.bind(this)); |
| 110 filenameSpacer.appendChild(this.filenameEdit_); |
| 111 |
99 this.ribbonSpacer_ = doc.createElement('div'); | 112 this.ribbonSpacer_ = doc.createElement('div'); |
100 this.ribbonSpacer_.className = 'ribbon-spacer'; | 113 this.ribbonSpacer_.className = 'ribbon-spacer'; |
101 this.toolbar_.appendChild(this.ribbonSpacer_); | 114 this.toolbar_.appendChild(this.ribbonSpacer_); |
102 | 115 |
103 this.arrowBox_ = this.document_.createElement('div'); | 116 this.arrowBox_ = this.document_.createElement('div'); |
104 this.arrowBox_.className = 'arrow-box'; | 117 this.arrowBox_.className = 'arrow-box'; |
105 this.container_.appendChild(this.arrowBox_); | 118 this.container_.appendChild(this.arrowBox_); |
106 | 119 |
107 this.arrowLeft_ = this.document_.createElement('div'); | 120 this.arrowLeft_ = this.document_.createElement('div'); |
108 this.arrowLeft_.className = 'arrow left tool dimmable'; | 121 this.arrowLeft_.className = 'arrow left tool dimmable'; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 159 |
147 this.editor_ = new ImageEditor( | 160 this.editor_ = new ImageEditor( |
148 this.container_, | 161 this.container_, |
149 this.imageContainer_, | 162 this.imageContainer_, |
150 this.editBarMain_, | 163 this.editBarMain_, |
151 this.editBarModeWrapper_, | 164 this.editBarModeWrapper_, |
152 Gallery.editorModes, | 165 Gallery.editorModes, |
153 this.displayStringFunction_); | 166 this.displayStringFunction_); |
154 | 167 |
155 this.imageView_ = this.editor_.getImageView(); | 168 this.imageView_ = this.editor_.getImageView(); |
| 169 this.imageView_.addContentCallback(this.onImageContentChanged_.bind(this)); |
156 | 170 |
157 this.editor_.trackWindow(doc.defaultView); | 171 this.editor_.trackWindow(doc.defaultView); |
158 | 172 |
159 if (shareActions.length > 0) { | 173 if (shareActions.length > 0) { |
160 this.shareMode_ = new ShareMode( | 174 this.shareMode_ = new ShareMode( |
161 this.container_, this.toolbar_, shareActions, | 175 this.container_, this.toolbar_, shareActions, |
162 this.onShare_.bind(this), this.onActionExecute_.bind(this), | 176 this.onShare_.bind(this), this.onActionExecute_.bind(this), |
163 this.displayStringFunction_); | 177 this.displayStringFunction_); |
164 | 178 |
165 } else { | 179 } else { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 function initRibbon() { | 219 function initRibbon() { |
206 self.ribbon_.load(urls, selectedIndex); | 220 self.ribbon_.load(urls, selectedIndex); |
207 // Flash the ribbon briefly to let the user know it is there. | 221 // Flash the ribbon briefly to let the user know it is there. |
208 self.cancelFading_(); | 222 self.cancelFading_(); |
209 self.initiateFading_(Gallery.FIRST_FADE_TIMEOUT); | 223 self.initiateFading_(Gallery.FIRST_FADE_TIMEOUT); |
210 } | 224 } |
211 | 225 |
212 var selectedURL = urls[selectedIndex]; | 226 var selectedURL = urls[selectedIndex]; |
213 // Initialize the ribbon only after the selected image is fully loaded. | 227 // Initialize the ribbon only after the selected image is fully loaded. |
214 this.metadataProvider_.fetch(selectedURL, function (metadata) { | 228 this.metadataProvider_.fetch(selectedURL, function (metadata) { |
| 229 // The first change is load, we should not count it. |
| 230 self.imageChanges_ = -1; |
| 231 self.filenameEdit_.value = ImageUtil.getFileNameFromUrl(selectedURL); |
215 self.editor_.openSession( | 232 self.editor_.openSession( |
216 selectedIndex, selectedURL, metadata, 0, initRibbon); | 233 selectedIndex, selectedURL, metadata, 0, initRibbon); |
217 }); | 234 }); |
218 }; | 235 }; |
219 | 236 |
| 237 Gallery.prototype.onImageContentChanged_ = function() { |
| 238 this.imageChanges_++; |
| 239 if (this.imageChanges_ == 1) |
| 240 this.ribbon_.getSelectedItem().setCopyName(); |
| 241 this.updateFilename_(); |
| 242 }; |
| 243 |
220 Gallery.prototype.saveItem_ = function(item, callback, canvas, modified) { | 244 Gallery.prototype.saveItem_ = function(item, callback, canvas, modified) { |
221 if (modified) { | 245 if (modified) { |
222 item.save( | 246 item.save( |
223 this.parentDirEntry_, this.metadataProvider_, canvas, callback); | 247 this.parentDirEntry_, this.metadataProvider_, canvas, callback); |
224 } else { | 248 } else { |
225 if (callback) callback(); | 249 if (callback) callback(); |
226 } | 250 } |
227 }; | 251 }; |
228 | 252 |
229 Gallery.prototype.saveChanges_ = function(opt_callback) { | 253 Gallery.prototype.saveChanges_ = function(opt_callback) { |
| 254 this.imageChanges_ = 0; |
230 this.editor_.requestImage( | 255 this.editor_.requestImage( |
231 this.saveItem_.bind(this, this.ribbon_.getSelectedItem(), opt_callback)); | 256 this.saveItem_.bind(this, this.ribbon_.getSelectedItem(), opt_callback)); |
232 }; | 257 }; |
233 | 258 |
234 Gallery.prototype.onActionExecute_ = function(action) { | 259 Gallery.prototype.onActionExecute_ = function(action) { |
235 var url = this.ribbon_.getSelectedItem().getUrl(); | 260 var url = this.ribbon_.getSelectedItem().getUrl(); |
236 // saveChanges_ makes the editor leave the mode and close the sharing menu. | 261 // saveChanges_ makes the editor leave the mode and close the sharing menu. |
237 this.saveChanges_(action.execute.bind(action, [url])); | 262 this.saveChanges_(action.execute.bind(action, [url])); |
238 }; | 263 }; |
239 | 264 |
| 265 Gallery.prototype.updateFilename_ = function() { |
| 266 var item = this.ribbon_.getSelectedItem(); |
| 267 if (!item) |
| 268 return; |
| 269 |
| 270 var fullName = item.getCopyName() || |
| 271 ImageUtil.getFullNameFromUrl(item.getUrl()); |
| 272 this.filenameEdit_.value = ImageUtil.getFileNameFromFullName(fullName); |
| 273 }; |
| 274 |
| 275 Gallery.prototype.onFilenameEditKeydown_ = function() { |
| 276 switch (event.keyCode) { |
| 277 case 27: // Escape |
| 278 this.filenameEdit_.blur(); |
| 279 break; |
| 280 |
| 281 case 13: // Enter |
| 282 if (this.filenameEdit_.value) { |
| 283 this.renameItem_(this.ribbon_.getSelectedItem(), |
| 284 this.filenameEdit_.value); |
| 285 this.filenameEdit_.blur(); |
| 286 } |
| 287 break; |
| 288 } |
| 289 event.stopPropagation(); |
| 290 }; |
| 291 |
| 292 Gallery.prototype.renameItem_ = function(item, name) { |
| 293 var dir = this.parentDirEntry_; |
| 294 var self = this; |
| 295 var newName; |
| 296 |
| 297 if (this.imageChanges_ > 0) { |
| 298 // We are editing the file. |
| 299 newName = ImageUtil.replaceFileNameInFullName( |
| 300 item.getCopyName(), name); |
| 301 } else { |
| 302 newName = ImageUtil.replaceFileNameInFullName( |
| 303 ImageUtil.getFullNameFromUrl(item.getUrl()), name); |
| 304 } |
| 305 |
| 306 function onError() { |
| 307 console.log('Rename error: "' + |
| 308 ImageUtil.getFullNameFromUrl(item.getUrl()) + '" to "' + name + '"'); |
| 309 } |
| 310 |
| 311 function onSuccess(entry) { |
| 312 item.setUrl(entry.toURL()); |
| 313 self.updateFilename_(); |
| 314 } |
| 315 |
| 316 function doRename() { |
| 317 if (self.imageChanges_ > 0) { |
| 318 // User this name in the next save operation. |
| 319 item.setCopyName(newName); |
| 320 self.updateFilename_(); |
| 321 } else { |
| 322 // Rename file in place. |
| 323 dir.getFile( |
| 324 ImageUtil.getFullNameFromUrl(item.getUrl()), |
| 325 {create: false}, |
| 326 function(entry) { entry.moveTo(dir, newName, onSuccess, onError); }, |
| 327 onError); |
| 328 } |
| 329 } |
| 330 |
| 331 function onVictimFound(victim) { |
| 332 self.editor_.getPrompt().show('file_exists', 3000); |
| 333 } |
| 334 |
| 335 dir.getFile(newName, {create: false, exclusive: false}, |
| 336 onVictimFound, doRename); |
| 337 }; |
| 338 |
240 Gallery.prototype.onClose_ = function() { | 339 Gallery.prototype.onClose_ = function() { |
241 // TODO: handle write errors gracefully (suggest retry or saving elsewhere). | 340 // TODO: handle write errors gracefully (suggest retry or saving elsewhere). |
242 this.saveChanges_(this.closeCallback_); | 341 this.saveChanges_(this.closeCallback_); |
243 }; | 342 }; |
244 | 343 |
245 Gallery.prototype.prefetchImage = function(id, content, metadata) { | 344 Gallery.prototype.prefetchImage = function(id, content, metadata) { |
246 this.editor_.prefetchImage(id, content, metadata); | 345 this.editor_.prefetchImage(id, content, metadata); |
247 }; | 346 }; |
248 | 347 |
249 Gallery.prototype.openImage = function(id, content, metadata, slide, callback) { | 348 Gallery.prototype.openImage = function(id, content, metadata, slide, callback) { |
| 349 // The first change is load, we should not count it. |
| 350 this.imageChanges_ = -1; |
| 351 this.updateFilename_(); |
250 this.editor_.openSession(id, content, metadata, slide, callback); | 352 this.editor_.openSession(id, content, metadata, slide, callback); |
251 }; | 353 }; |
252 | 354 |
253 Gallery.prototype.closeImage = function(item) { | 355 Gallery.prototype.closeImage = function(item) { |
254 this.editor_.closeSession(this.saveItem_.bind(this, item, null)); | 356 this.editor_.closeSession(this.saveItem_.bind(this, item, null)); |
255 }; | 357 }; |
256 | 358 |
257 Gallery.prototype.isEditing_ = function() { | 359 Gallery.prototype.isEditing_ = function() { |
258 return this.container_.hasAttribute('editing'); | 360 return this.container_.hasAttribute('editing'); |
259 }; | 361 }; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 * @param {MetadataProvider} metadataProvider | 479 * @param {MetadataProvider} metadataProvider |
378 * @param {HTMLElement} arrowLeft | 480 * @param {HTMLElement} arrowLeft |
379 * @param {HTMLElement} arrowRight | 481 * @param {HTMLElement} arrowRight |
380 */ | 482 */ |
381 function Ribbon(container, client, metadataProvider, arrowLeft, arrowRight) { | 483 function Ribbon(container, client, metadataProvider, arrowLeft, arrowRight) { |
382 this.container_ = container; | 484 this.container_ = container; |
383 this.document_ = container.ownerDocument; | 485 this.document_ = container.ownerDocument; |
384 this.client_ = client; | 486 this.client_ = client; |
385 this.metadataProvider_ = metadataProvider; | 487 this.metadataProvider_ = metadataProvider; |
386 | 488 |
| 489 this.items_ = []; |
| 490 this.selectedIndex_ = -1; |
| 491 |
387 this.arrowLeft_ = arrowLeft; | 492 this.arrowLeft_ = arrowLeft; |
388 this.arrowLeft_. | 493 this.arrowLeft_. |
389 addEventListener('click', this.selectNext.bind(this, -1, null)); | 494 addEventListener('click', this.selectNext.bind(this, -1, null)); |
390 | 495 |
391 this.arrowRight_ = arrowRight; | 496 this.arrowRight_ = arrowRight; |
392 this.arrowRight_. | 497 this.arrowRight_. |
393 addEventListener('click', this.selectNext.bind(this, 1, null)); | 498 addEventListener('click', this.selectNext.bind(this, 1, null)); |
394 | 499 |
395 this.fadeLeft_ = this.document_.createElement('div'); | 500 this.fadeLeft_ = this.document_.createElement('div'); |
396 this.fadeLeft_.className = 'fade left'; | 501 this.fadeLeft_.className = 'fade left'; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 | 776 |
672 var img = document.createElement('img'); | 777 var img = document.createElement('img'); |
673 wrapper.appendChild(img); | 778 wrapper.appendChild(img); |
674 | 779 |
675 this.boxes_.push(box); | 780 this.boxes_.push(box); |
676 this.wrappers_.push(wrapper); | 781 this.wrappers_.push(wrapper); |
677 this.imgs_.push(img); | 782 this.imgs_.push(img); |
678 } | 783 } |
679 | 784 |
680 this.original_ = true; | 785 this.original_ = true; |
| 786 this.copyName_ = null; |
681 }; | 787 }; |
682 | 788 |
683 Ribbon.Item.prototype.getIndex = function () { return this.index_ }; | 789 Ribbon.Item.prototype.getIndex = function () { return this.index_ }; |
684 | 790 |
685 Ribbon.Item.prototype.getBox = function (index) { return this.boxes_[index] }; | 791 Ribbon.Item.prototype.getBox = function (index) { return this.boxes_[index] }; |
686 | 792 |
687 Ribbon.Item.prototype.isOriginal = function () { return this.original_ }; | 793 Ribbon.Item.prototype.isOriginal = function () { return this.original_ }; |
688 | 794 |
689 Ribbon.Item.prototype.getUrl = function () { return this.url_ }; | 795 Ribbon.Item.prototype.getUrl = function () { return this.url_ }; |
| 796 Ribbon.Item.prototype.setUrl = function (url) { this.url_ = url }; |
| 797 |
| 798 Ribbon.Item.prototype.getCopyName = function () { return this.copyName_ }; |
690 | 799 |
691 Ribbon.Item.prototype.isSelected = function() { | 800 Ribbon.Item.prototype.isSelected = function() { |
692 return this.boxes_[0].hasAttribute('selected'); | 801 return this.boxes_[0].hasAttribute('selected'); |
693 }; | 802 }; |
694 | 803 |
695 Ribbon.Item.prototype.select = function(on) { | 804 Ribbon.Item.prototype.select = function(on) { |
696 for (var i = 0; i < 2; i++) { | 805 for (var i = 0; i < 2; i++) { |
697 ImageUtil.setAttribute(this.boxes_[i], 'selected', on); | 806 ImageUtil.setAttribute(this.boxes_[i], 'selected', on); |
698 } | 807 } |
699 }; | 808 }; |
(...skipping 18 matching lines...) Expand all Loading... |
718 | 827 |
719 if (!dirEntry) { // Happens only in gallery_demo.js | 828 if (!dirEntry) { // Happens only in gallery_demo.js |
720 self.onSaveSuccess( | 829 self.onSaveSuccess( |
721 window.webkitURL.createObjectURL( | 830 window.webkitURL.createObjectURL( |
722 ImageEncoder.getBlob(canvas, metadataEncoder))); | 831 ImageEncoder.getBlob(canvas, metadataEncoder))); |
723 if (opt_callback) opt_callback(); | 832 if (opt_callback) opt_callback(); |
724 return; | 833 return; |
725 } | 834 } |
726 | 835 |
727 var newFile = this.isOriginal(); | 836 var newFile = this.isOriginal(); |
728 var name = this.getCopyName(); | 837 var name = this.copyName_; |
| 838 this.original_ = false; |
| 839 this.copyName_ = ''; |
729 | 840 |
730 function onSuccess(url) { | 841 function onSuccess(url) { |
731 console.log('Saved from gallery', name); | 842 console.log('Saved from gallery', name); |
732 // Force the metadata provider to reread the metadata from the file. | 843 // Force the metadata provider to reread the metadata from the file. |
733 metadataProvider.reset(url); | 844 metadataProvider.reset(url); |
734 self.onSaveSuccess(url); | 845 self.onSaveSuccess(url); |
735 if (opt_callback) opt_callback(); | 846 if (opt_callback) opt_callback(); |
736 } | 847 } |
737 | 848 |
738 function onError(error) { | 849 function onError(error) { |
(...skipping 15 matching lines...) Expand all Loading... |
754 } else { | 865 } else { |
755 fileWriter.onwriteend = writeContent; | 866 fileWriter.onwriteend = writeContent; |
756 fileWriter.truncate(0); | 867 fileWriter.truncate(0); |
757 } | 868 } |
758 }, | 869 }, |
759 onError); | 870 onError); |
760 }, onError); | 871 }, onError); |
761 }; | 872 }; |
762 | 873 |
763 // TODO: Localize? | 874 // TODO: Localize? |
764 Ribbon.Item.COPY_SIGNATURE = '_Edited_'; | 875 Ribbon.Item.COPY_SIGNATURE = 'Copy of '; |
765 | 876 |
766 Ribbon.Item.prototype.getCopyName = function () { | 877 Ribbon.Item.prototype.createCopyName_ = function () { |
767 // When saving a modified image we never overwrite the original file (the one | 878 // When saving a modified image we never overwrite the original file (the one |
768 // that existed prior to opening the Gallery. Instead we save to a file named | 879 // that existed prior to opening the Gallery. Instead we save to a file named |
769 // <original-name>_Edited_<date-stamp>.<original extension>. | 880 // <original-name>_Edited_<date-stamp>.<original extension>. |
770 | 881 |
771 var name = this.url_.substr(this.url_.lastIndexOf('/') + 1); | 882 var name = this.url_.substr(this.url_.lastIndexOf('/') + 1); |
772 | 883 |
773 // If the item represents a file created during the current Gallery session | 884 // If the item represents a file created during the current Gallery session |
774 // we reuse it for subsequent saves instead of creating multiple copies. | 885 // we reuse it for subsequent saves instead of creating multiple copies. |
775 if (!this.original_) | 886 if (!this.original_) |
776 return name; | 887 return name; |
777 | 888 |
778 this.original_ = false; | |
779 | |
780 var ext = ''; | 889 var ext = ''; |
781 var index = name.lastIndexOf('.'); | 890 var index = name.lastIndexOf('.'); |
782 if (index != -1) { | 891 if (index != -1) { |
783 ext = name.substr(index); | 892 ext = name.substr(index); |
784 name = name.substr(0, index); | 893 name = name.substr(0, index); |
785 } | 894 } |
786 var signaturePos = name.indexOf(Ribbon.Item.COPY_SIGNATURE); | 895 |
787 if (signaturePos >= 0) { | 896 if (name.indexOf(Ribbon.Item.COPY_SIGNATURE) == 0) { |
788 // The file is likely to be a copy created during a previous session. | 897 // TODO(dgozman): add a number to form 'Copy (X) of File.jpg'. |
789 // Replace the signature instead of appending a new one. | 898 name = name.substr(Ribbon.Item.COPY_SIGNATURE.length); |
790 name = name.substr(0, signaturePos); | |
791 } | 899 } |
792 | 900 |
793 var mimeType = this.metadata_.mimeType.toLowerCase(); | 901 var mimeType = this.metadata_.mimeType.toLowerCase(); |
794 if (mimeType != 'image/jpeg') { | 902 if (mimeType != 'image/jpeg') { |
795 // Chrome can natively encode only two formats: JPEG and PNG. | 903 // Chrome can natively encode only two formats: JPEG and PNG. |
796 // All non-JPEG images are saved in PNG, hence forcing the file extension. | 904 // All non-JPEG images are saved in PNG, hence forcing the file extension. |
797 if (mimeType == 'image/png') { | 905 if (mimeType == 'image/png') { |
798 ext = '.png'; | 906 ext = '.png'; |
799 } else { | 907 } else { |
800 // All non-JPEG images get 'image/png' mimeType (see | 908 // All non-JPEG images get 'image/png' mimeType (see |
801 // ImageEncoder.MetadataEncoder constructor). | 909 // ImageEncoder.MetadataEncoder constructor). |
802 // This code can be reached only if someone has added a metadata parser | 910 // This code can be reached only if someone has added a metadata parser |
803 // for a format other than JPEG or PNG. The message below is to remind | 911 // for a format other than JPEG or PNG. The message below is to remind |
804 // that one must also come up with the way to encode the image data. | 912 // that one must also come up with the way to encode the image data. |
805 console.error('Image encoding for ' + mimeType + ' is not supported'); | 913 console.error('Image encoding for ' + mimeType + ' is not supported'); |
806 } | 914 } |
807 } | 915 } |
808 | 916 |
809 function twoDigits(n) { return (n < 10 ? '0' : '' ) + n } | 917 return Ribbon.Item.COPY_SIGNATURE + name + ext; |
| 918 }; |
810 | 919 |
811 var now = new Date(); | 920 Ribbon.Item.prototype.setCopyName = function(opt_name) { |
812 | 921 if (opt_name) { |
813 // Datestamp the copy with YYYYMMDD_HHMMSS (similar to what many cameras do) | 922 this.copyName_ = opt_name; |
814 return name + | 923 } else { |
815 Ribbon.Item.COPY_SIGNATURE + | 924 this.copyName_ = this.createCopyName_(); |
816 now.getFullYear() + | 925 } |
817 twoDigits(now.getMonth() + 1) + | |
818 twoDigits(now.getDate()) + | |
819 '_' + | |
820 twoDigits(now.getHours()) + | |
821 twoDigits(now.getMinutes()) + | |
822 twoDigits(now.getSeconds()) + | |
823 ext; | |
824 }; | 926 }; |
825 | 927 |
826 // The url and metadata stored in the item are not valid while the modified | 928 // The url and metadata stored in the item are not valid while the modified |
827 // image is being saved. Use the results of the latest edit instead. | 929 // image is being saved. Use the results of the latest edit instead. |
828 | 930 |
829 Ribbon.Item.prototype.overrideContent = function(canvas, metadata) { | 931 Ribbon.Item.prototype.overrideContent = function(canvas, metadata) { |
830 this.canvas_ = canvas; | 932 this.canvas_ = canvas; |
831 this.backupMetadata_ = this.metadata_; | 933 this.backupMetadata_ = this.metadata_; |
832 this.setMetadata(metadata); | 934 this.setMetadata(metadata); |
833 }; | 935 }; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 ShareMode.prototype.setUp = function() { | 1078 ShareMode.prototype.setUp = function() { |
977 ImageEditor.Mode.prototype.setUp.apply(this, arguments); | 1079 ImageEditor.Mode.prototype.setUp.apply(this, arguments); |
978 ImageUtil.setAttribute(this.menu_, 'hidden', false); | 1080 ImageUtil.setAttribute(this.menu_, 'hidden', false); |
979 ImageUtil.setAttribute(this.button_, 'pressed', false); | 1081 ImageUtil.setAttribute(this.button_, 'pressed', false); |
980 }; | 1082 }; |
981 | 1083 |
982 ShareMode.prototype.cleanUpUI = function() { | 1084 ShareMode.prototype.cleanUpUI = function() { |
983 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); | 1085 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); |
984 ImageUtil.setAttribute(this.menu_, 'hidden', true); | 1086 ImageUtil.setAttribute(this.menu_, 'hidden', true); |
985 }; | 1087 }; |
OLD | NEW |