Changeset 1016
- Timestamp:
- 06/25/08 21:33:00 (11 years ago)
- Location:
- branches/new-dialogs/plugins/BackgroundImage
- Files:
-
- 1 added
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new-dialogs/plugins/BackgroundImage/background-image.js
r856 r1016 9 9 function BackgroundImage(editor) { 10 10 this.editor = editor; 11 12 11 var cfg = editor.config; 12 var self = this; 13 13 cfg.registerButton({ 14 15 tooltip : this._lc("Set page background image"),16 17 18 19 self.buttonPress(editor);20 21 22 14 id : "bgImage", 15 tooltip : Xinha._lc("Set page background image", 'BackgroundImage'), 16 image : editor.imgURL("ed_bgimage.gif", "BackgroundImage"), 17 textMode : false, 18 action : function(editor) { 19 self.show(); 20 } 21 }) 22 cfg.addToolbarElement("bgImage", "inserthorizontalrule", 1); 23 23 } 24 24 25 25 BackgroundImage._pluginInfo = { 26 27 28 29 30 31 32 33 26 name : "BackgroundImage", 27 version : "1.0", 28 developer : "Udo Schmal", 29 developer_url : "http://www.schaffrath-neuemedien.de/", 30 c_owner : "Udo Schmal & Schaffrath NeueMedien", 31 sponsor : "L.N.Schaffrath NeueMedien", 32 sponsor_url : "http://www.schaffrath-neuemedien.de.de/", 33 license : "htmlArea" 34 34 }; 35 35 36 BackgroundImage.prototype._lc = function(string) { 37 return Xinha._lc(string, 'BackgroundImage'); 36 BackgroundImage.prototype.onGenerateOnce = function(editor){ 37 // Load assets 38 var self = BackgroundImage; 39 if (self.loading) return; 40 41 // A list of jpgs that are expected to be in ./backgrounds with thumbnails. 42 var backgrounds = {blufur:'',palecnvs:'', ppplcnvs:'', ylwsand:''}; 43 44 self.loading = true; 45 self.methodsReady = true; 46 47 // When we get back from loading the dialog, we'll process our image template to handle as many images as specified. 48 Xinha._getback(_editor_url + 'plugins/BackgroundImage/dialog.html', function(getback) { 49 50 // Replace the template line with one line per image. 51 self.html = getback.replace(/<template>(.*?)<\/template>/ig, function(fullString, template) { 52 var replacement = ''; 53 54 for (bg in backgrounds) 55 { 56 var thumbURL = _editor_url + 'plugins/BackgroundImage/backgrounds/thumbnails/' + bg + '.jpg'; 57 var imageURL = _editor_url + 'plugins/BackgroundImage/backgrounds/' + bg + '.jpg'; 58 replacement += template.replace(/%thumbnail%/,thumbURL).replace(/%image%/,imageURL); 59 } 60 return replacement; 61 }); 62 self.dialogReady = true; 63 }); 64 } 65 66 BackgroundImage.prototype.onUpdateToolbar = function(editor){ 67 // Keep our toolbar image greyed until we're fully loaded. 68 if (!(BackgroundImage.dialogReady && BackgroundImage.methodsReady)) 69 { 70 this.editor._toolbarObjects.BackgroundImage.state("enabled", false); 71 } 72 else this.onUpdateToolbar = null; 73 74 } 75 76 BackgroundImage.prototype.prepareDialog = function(editor){ 77 var self = this; 78 var editor = this.editor; 79 80 var dialog = this.dialog = new Xinha.Dialog(editor, BackgroundImage.html, 'Xinha',{width:400}) 81 // 82 // Hookup the buttons with our actions 83 dialog.getElementById('set').onclick = function() {self.apply();} 84 dialog.getElementById('delete').onclick = function() {self.deleteBg();} 85 dialog.getElementById('cancel').onclick = function() { self.dialog.hide()}; 86 87 this.dialogReady = true; 88 } 89 90 BackgroundImage.prototype.show = function(editor){ 91 if (!this.dialog) this.prepareDialog(); 92 93 var editor = this.editor; 94 95 // After clearing the background property, it returns the current URL, and so 96 // we need to check the extension to find out if it really has a background. 97 if (editor._doc.body.background.split('.').pop() in {jpg:'', gif:'', png:'', jpeg:'', tiff:''}) 98 { 99 var background = editor._doc.body.background; 100 } 101 else 102 { 103 var background = ''; 104 } 105 var values = 106 { 107 "background" : background 108 } 109 110 // now calling the show method of the Xinha.Dialog object to set the values and show the actual dialog 111 this.dialog.show(values); 112 } 113 114 BackgroundImage.prototype.deleteBg = function(){ 115 var editor = this.editor; 116 this.dialog.hide(); 117 118 if (Xinha.is_ie) 119 editor.focusEditor(); 120 121 editor._doc.body.background = ""; 122 } 123 124 BackgroundImage.prototype.apply = function(){ 125 var editor = this.editor; 126 var doc = editor._doc; 127 128 // selection is only restored on dialog.hide() 129 var param = this.dialog.hide(); 130 // assign the given arguments 131 132 if (Xinha.is_ie) 133 editor.focusEditor(); 134 135 doc.body.background = param.background; 38 136 }; 39 40 BackgroundImage.prototype.buttonPress = function(editor) {41 //var doc = this.editor._doc;42 editor._popupDialog( "plugin://BackgroundImage/bgimage", function( bgImage ) {43 if(bgImage) {44 if(Xinha.is_ie) editor.focusEditor();45 if(bgImage=="*") {46 editor._doc.body.background = "";47 } else {48 editor._doc.body.background = bgImage;49 }50 }51 }, null);52 };
Note: See TracChangeset
for help on using the changeset viewer.