1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is BlueGriffon.
16 * The Initial Developer of the Original Code is
17 * Disruptive Innovations SARL.
18 * Portions created by the Initial Developer are Copyright (C) 2008
19 * the Initial Developer. All Rights Reserved.
22 * Daniel Glazman <daniel.glazman@disruptive-innovations.com>, Original author
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 Components.utils.import("resource://gre/modules/colourPickerHelper.jsm");
40 var gFpb = null; // file picker
41 var gPreview = null; // preview iframe for colors
43 var gDescription = "";
46 var gTitleWasEdited = false;
47 var gAuthorWasEdited = false;
48 var gDescriptionWasEdited = false;
49 var gKeywordsWasEdited = false;
50 var gLanguageWasEdited = false;
53 var gUseSystemColors = true;
55 var gHorizPosition = "50%";
56 var gVertPosition = "50%";
62 var gFpb = gDialog["filepickerbutton"];
64 gFpb.appendFilters(Components.interfaces.nsIFilePicker.filterImages);
66 gPreview = gDialog["pagePreview"];
68 gRootElement = EditorUtils.getCurrentEditor().rootElement;
71 SetTextboxFocus(gDialog.pageTitle);
76 gDialog.pageTitle.value = EditorUtils.getDocumentTitle();
78 // Fill in with value from editor prefs
81 gAuthor = gPrefs.getCharPref("bluegriffon.author");
84 // if we still have no author name, use the system username if any
87 gAuthor = Components.classes["@mozilla.org/userinfo;1"]
88 .getService(Components.interfaces.nsIUserInfo).username;
91 gDialog.pageAuthor.value = gAuthor;
94 gUseSystemColors = gPrefs.getBoolPref("bluegriffon.display.use_system_colors");
95 gForegroundColor = gPrefs.getCharPref("bluegriffon.display.foreground_color");
96 gBackgroundColor = gPrefs.getCharPref("bluegriffon.display.background_color");
97 gActiveColor = gPrefs.getCharPref("bluegriffon.display.active_color");
98 gAnchorColor = gPrefs.getCharPref("bluegriffon.display.anchor_color");
99 gVisitedColor = gPrefs.getCharPref("bluegriffon.display.visited_color");
100 gDialog.underlineLinks.checked = gPrefs.getBoolPref("bluegriffon.display.underline_links");
101 gDialog.userDefinedColors.checked = !gUseSystemColors;
102 EnableUserDefinedColorsControls();
105 function EnableUserDefinedColorsControls()
107 var enabled = gDialog.userDefinedColors.checked;
108 gDialog.backgroundColorColorpicker.color = (enabled ? gBackgroundColor : "transparent");
109 gDialog.textColorColorpicker.color = (enabled ? gForegroundColor : "transparent");
110 gDialog.linksColorColorpicker.color = (enabled ? gAnchorColor : "transparent");
111 gDialog.activeLinksColorColorpicker.color = (enabled ? gActiveColor : "transparent");
112 gDialog.visitedLinksColorColorpicker.color = (enabled ? gVisitedColor : "transparent");
114 gDialog.pagePreview.style.backgroundColor = enabled ? gBackgroundColor : "#ffffff";
115 gDialog.textPreview.style.color = enabled ? gForegroundColor : "#000000";
116 gDialog.linksPreview.style.color = enabled ? gAnchorColor : "#0000ee";
117 gDialog.activeLinksPreview.style.color = enabled ? gActiveColor : "#ee0000";
118 gDialog.visitedLinksPreview.style.color = enabled ? gVisitedColor : "#551a8b";
120 var underline = gDialog.underlineLinks.checked || !enabled;
121 gDialog.linksPreview.style.textDecoration = underline ? "underline" : "none";
122 gDialog.activeLinksPreview.style.textDecoration = underline ? "underline" : "none";
123 gDialog.visitedLinksPreview.style.textDecoration = underline ? "underline" : "none";
125 SetEnabledElement(gDialog.backgroundColorColorpickerLabel, enabled);
126 SetEnabledElement(gDialog.backgroundColorColorpicker, enabled);
127 SetEnabledElement(gDialog.textColorColorpickerLabel, enabled);
128 SetEnabledElement(gDialog.textColorColorpicker, enabled);
129 SetEnabledElement(gDialog.linksColorColorpickerLabel, enabled);
130 SetEnabledElement(gDialog.linksColorColorpicker, enabled);
131 SetEnabledElement(gDialog.activeLinksColorColorpickerLabel, enabled);
132 SetEnabledElement(gDialog.activeLinksColorColorpicker, enabled);
133 SetEnabledElement(gDialog.visitedLinksColorColorpickerLabel, enabled);
134 SetEnabledElement(gDialog.visitedLinksColorColorpicker, enabled);
135 SetEnabledElement(gDialog.textPreview, enabled);
136 SetEnabledElement(gDialog.linksPreview, enabled);
137 SetEnabledElement(gDialog.activeLinksPreview, enabled);
138 SetEnabledElement(gDialog.visitedLinksPreview, enabled);
139 SetEnabledElement(gDialog.underlineLinks, enabled);
142 function onColorChange(aColorPicker)
144 switch (aColorPicker.id)
146 case "backgroundColorColorpicker":
147 gBackgroundColor = aColorPicker.color;
149 case "textColorColorpicker":
150 gForegroundColor = aColorPicker.color;
152 case "linksColorColorpicker":
153 gAnchorColor = aColorPicker.color;
155 case "activeLinksColorColorpicker":
156 gActiveColor = aColorPicker.color;
158 case "visitedLinksColorColorpicker":
159 gVisitedColor = aColorPicker.color;
161 default: break; // sanity code
163 EnableUserDefinedColorsControls();
166 var gColorPicker = {};
168 function OpenColorDialog(aElt, aColorObjectId)
172 case "backgroundColorColorpicker":
173 ColorPickerHelper.openColorPickerPanel("backgroundColor", "", true,
175 "colorPickerSheetIFrame",
183 function SelectLanguage(aElt)
185 var retValue = { lang: "" };
186 window.openDialog("chrome://bluegriffon/content/dialogs/languages.xul","_blank",
187 "chrome,modal=no,dialog=yes,titlebar", null, retValue);
188 gDialog.pageLanguage.value = retValue.lang;
191 function ShowBackgroundPosition(aEvent)
193 var x = aEvent.screenX - gDialog.backgroundPositionBox.boxObject.screenX;
194 var y = aEvent.screenY + 1 - gDialog.backgroundPositionBox.boxObject.screenY;
195 if (x < 0 || y < 0 || x > 100 | y > 100)
196 ExitBackgroundPosition(aEvent);
198 gDialog.horizPosition.value = x + "%";
199 gDialog.vertPosition.value = y + "%";
200 gDialog.horizPosition.style.color = "";
201 gDialog.vertPosition.style.color = "";
202 gDialog.horizPosition.style.fontWeight = "";
203 gDialog.vertPosition.style.fontWeight = "";
204 gDialog.backgroundPositionBox.style.backgroundPosition = (100-x) + "% " + (100-y) +"%";
207 function SetBackgroundPosition(aEvent)
209 var x = aEvent.screenX - gDialog.backgroundPositionBox.boxObject.screenX;
210 var y = aEvent.screenY + 1 - gDialog.backgroundPositionBox.boxObject.screenY;
211 if (x < 0 || y < 0 || x > 100 | y > 100)
212 ExitBackgroundPosition(aEvent);
214 ShowBackgroundPosition(aEvent)
216 gDialog.horizPosition.style.color = "red";
217 gDialog.vertPosition.style.color = "red";
218 gDialog.horizPosition.style.fontWeight = "bold";
219 gDialog.vertPosition.style.fontWeight = "bold";
220 gHorizPosition = gDialog.horizPosition.value;
221 gVertPosition = gDialog.vertPosition.value;
222 gDialog.backgroundImageBox.style.backgroundPosition = gHorizPosition + " " + gVertPosition;
225 function ExitBackgroundPosition(event)
227 gDialog.horizPosition.value = gHorizPosition;
228 gDialog.vertPosition.value = gVertPosition;
229 gDialog.horizPosition.style.color = "";
230 gDialog.vertPosition.style.color = "";
231 gDialog.horizPosition.style.fontWeight = "";
232 gDialog.vertPosition.style.fontWeight = "";
233 var x = parseInt(gHorizPosition);
234 var y = parseInt(gVertPosition);
235 gDialog.backgroundPositionBox.style.backgroundPosition = (100-x) + "% " + (100-y) +"%";
238 function SetBackgroundRepeat(aElt)
240 gDialog.backgroundImageBox.style.backgroundRepeat = aElt.value;
243 function onUsePageLayoutChanged(aCheckbox)
245 var enabled = aCheckbox.checked;
246 SetEnabledElementAndControl(gDialog.LayoutTypeMenulistLabel, enabled);
247 SetEnabledElementAndControl(gDialog.LayoutSubtypeMenulistLabel, enabled);
249 SetEnabledElement(gDialog.ContentRowsListbox, enabled);
251 SetEnabledElement(gDialog.ContentRowsPlusButton, enabled);
252 SetEnabledElement(gDialog.ContentRowsMinusButton, enabled && gDialog.ContentRowsListbox.itemCount);
253 // SetEnabledElement(gDialog.ContentRowsConfigButton, enabled);
255 SetEnabledElement(gDialog.LoremIpsumCheckbox, enabled);
258 function AddContentRow(aEvent)
260 var item = aEvent.originalTarget;
261 var label = item.label;
262 var value = item.value;
264 var listItem = gDialog.ContentRowsListbox.appendItem(label, value);
265 gDialog.ContentRowsListbox.selectItem(listItem);
266 SetEnabledElement(gDialog.ContentRowsMinusButton, true);
269 function RemoveContentRow()
271 var listbox = gDialog.ContentRowsListbox;
272 var item = listbox.selectedItem;
275 var index = listbox.getIndexOfItem(item);
276 listbox.removeItemAt(index);
277 var count = listbox.itemCount;
282 item = listbox.getItemAtIndex(index);
283 listbox.selectItem(item);
286 SetEnabledElement(gDialog.ContentRowsMinusButton, false);
292 var doc = EditorUtils.getCurrentDocument();
294 // UI CSS GRID LAYOUT
295 if (gDialog.usePageLayout.checked)
297 var loremIpusm = gDialog.LoremIpsumCheckbox.checked;
299 var linkElt = doc.createElement("link");
300 linkElt.setAttribute("type", "text/css");
301 linkElt.setAttribute("rel", "stylesheet");
302 linkElt.setAttribute("href", "http://yui.yahooapis.com/2.6.0/build/reset-fonts-grids/reset-fonts-grids.css");
303 EditorUtils.getHeadElement().appendChild(linkElt);
304 linkElt = doc.createElement("link");
305 linkElt.setAttribute("type", "text/css");
306 linkElt.setAttribute("rel", "stylesheet");
307 linkElt.setAttribute("href", "http://yui.yahooapis.com/2.6.0/build/base/base-min.css");
308 EditorUtils.getHeadElement().appendChild(linkElt);
310 var docId = gDialog.LayoutTypeMenulist.value;
311 var docClass = gDialog.LayoutSubtypeMenulist.value;
312 var outerDiv = doc.createElement("div");
313 outerDiv.setAttribute("id", docId);
314 outerDiv.setAttribute("class", docClass);
315 doc.body.innerHTML = "";
316 doc.body.appendChild(outerDiv);
318 var headerDiv = doc.createElement("div");
319 headerDiv.setAttribute("id", "hd");
320 var bodyDiv = doc.createElement("div");
321 bodyDiv.setAttribute("id", "bd");
322 var footerDiv = doc.createElement("div");
323 footerDiv.setAttribute("id", "ft");
324 outerDiv.appendChild(headerDiv);
325 outerDiv.appendChild(bodyDiv);
326 outerDiv.appendChild(footerDiv);
328 var loremIpsumStr = "<br>";
332 var loremIpsumProse = L10NUtils.getStringFromURL("loremIpsum",
333 "chrome://bluegriffon/locale/newPageWizard.properties");
334 var headerProse = L10NUtils.getStringFromURL("header",
335 "chrome://bluegriffon/locale/newPageWizard.properties");
336 var footerProse = L10NUtils.getStringFromURL("footer",
337 "chrome://bluegriffon/locale/newPageWizard.properties");
338 navProse = L10NUtils.getStringFromURL("nav",
339 "chrome://bluegriffon/locale/newPageWizard.properties");
341 var h1 = doc.createElement("h1");
342 var headerTextNode = doc.createTextNode(headerProse);
343 h1.appendChild(headerTextNode);
344 headerDiv.appendChild(h1);
345 var p = doc.createElement("p");
346 var footerTextNode = doc.createTextNode(footerProse);
347 p.appendChild(footerTextNode);
348 footerDiv.appendChild(p);
350 loremIpsumStr = "<p>" + loremIpsumProse + "</p>";
354 var headerBr = doc.createElement("br");
355 headerDiv.appendChild(headerBr);
356 var footerBr = doc.createElement("br");
357 footerDiv.appendChild(footerBr);
360 var mainContainer = bodyDiv;
361 if (docClass != "yui-t7")
363 mainContainer = doc.createElement("div");
364 mainContainer.setAttribute("class", "yui-b");
365 mainContainerContainer = doc.createElement("div");
366 mainContainerContainer.setAttribute("id", "yui-main");
368 mainContainerContainer.appendChild(mainContainer);
369 bodyDiv.appendChild(mainContainerContainer);
372 var listbox = gDialog.ContentRowsListbox;
373 for (var i = 0 ; i < listbox.itemCount; i++)
375 var item = listbox.getItemAtIndex(i);
376 var value = item.value;
381 ihtml = "<div class='yui-g'>" + loremIpsumStr + "</div>";
382 break; // oneColumn100
384 case "2": // .yui-g > .yui-u.first + .yui-u
385 ihtml = "<div class='yui-g'><div class='yui-u first'>" + loremIpsumStr +
386 "</div><div class='yui-u'>" + loremIpsumStr +
388 break; // twoColumns5050
390 case "3": // .yui-gc > .yui-u.first + .yui-u
391 ihtml = "<div class='yui-gc'><div class='yui-u first'>" + loremIpsumStr +
392 "</div><div class='yui-u'>" + loremIpsumStr +
394 break; // twoColumns6633
396 case "4": // .yui-gd > .yui-u.first + .yui-u
397 ihtml = "<div class='yui-gd'><div class='yui-u first'>" + loremIpsumStr +
398 "</div><div class='yui-u'>" + loremIpsumStr +
400 break; // twoColumns3366
402 case "5": // .yui-ge > .yui-u.first + .yui-u
403 ihtml = "<div class='yui-ge'><div class='yui-u first'>" + loremIpsumStr +
404 "</div><div class='yui-u'>" + loremIpsumStr +
406 break; // twoColumns7525
408 case "6": // .yui-gf > .yui-u.first + .yui-u
409 ihtml = "<div class='yui-gf'><div class='yui-u first'>" + loremIpsumStr +
410 "</div><div class='yui-u'>" + loremIpsumStr +
412 break; // twoColumns2575
414 case "7": // .yui-gb > .yui-u.first + .yui-u + .yui-u
415 ihtml = "<div class='yui-gb'><div class='yui-u first'>" + loremIpsumStr +
416 "</div><div class='yui-u'>" + loremIpsumStr +
417 "</div><div class='yui-u'>" + loremIpsumStr +
419 break; // threeColumns333333
421 case "8": // .yui-g > .yui-u first + .yui-g > .yui-u.first + .yui-u
422 ihtml = "<div class='yui-g'><div class='yui-u first'>" + loremIpsumStr +
423 "</div><div class='yui-g'><div class='yui-u first'>" + loremIpsumStr +
424 "</div><div class='yui-u'>" + loremIpsumStr +
425 "</div></div></div>";
426 break; // threeColumns502525
428 case "9": // .yui-g > .yui-g.first ( > .yui-u.first + .yui-u ) + .yui-u
429 ihtml = "<div class='yui-g'><div class='yui-g first'><div class='yui-u first'>" + loremIpsumStr +
430 "</div><div class='yui-u'>" + loremIpsumStr +
431 "</div></div><div class='yui-u'>" + loremIpsumStr +
433 break; // threeColumns252550
435 case "10": // .yui-g > .yui-g.first ( > .yui-u.first + .yui-u ) + .yui-g ( > .yui-u.first + .yui-u )
436 ihtml = "<div class='yui-g'><div class='yui-g first'><div class='yui-u first'>" + loremIpsumStr +
437 "</div><div class='yui-u'>" + loremIpsumStr +
438 "</div></div><div class='yui-g'><div class='yui-u first'>" + loremIpsumStr +
439 "</div><div class='yui-u'>" + loremIpsumStr +
440 "</div></div></div>";
441 break; // fourColumns25252525
443 default: break // should not happen
445 mainContainer.innerHTML += ihtml;
448 // the sidebar now...
449 if (docClass != "yui-t7")
451 bodyDiv.innerHTML += "<div class='yui-b'>" + navProse + "</div>";
456 if (gDialog.pageTitle.value)
458 EditorUtils.setDocumentTitle(gDialog.pageTitle.value);
461 if (gDialog.pageAuthor.value)
463 var meta = EditorUtils.createMetaElement("author");
464 EditorUtils.insertMetaElement(meta, gDialog.pageAuthor.value, true, false);
467 if (gDialog.pageDescription.value)
469 meta = EditorUtils.createMetaElement("description");
470 EditorUtils.insertMetaElement(meta, gDialog.pageDescription.value, true, false);
473 if (gDialog.pageKeywords.value)
475 meta = EditorUtils.createMetaElement("keywords");
476 EditorUtils.insertMetaElement(meta, gDialog.pageKeywords.value, true, false);
479 meta = EditorUtils.createMetaElement("generator");
480 EditorUtils.insertMetaElement(meta, "BlueGriffon wysiwyg editor", true, false);
482 if (gDialog.pageLanguage.value)
483 EditorUtils.getCurrentDocument().documentElement.
484 setAttribute("lang", gDialog.pageLanguage.value);
487 var prefs = GetPrefs();
488 if (gDialog.makeColorsDefault.checked)
489 prefs.setBoolPref("bluegriffon.display.use_system_colors", !gDialog.userDefinedColors.checked)
490 if (gDialog.userDefinedColors.checked)
492 var bgColor = gDialog.backgroundColorColorpicker.color;
493 var fgColor = gDialog.textColorColorpicker.color;
494 var linksColor = gDialog.linksColorColorpicker.color;
495 var activeColor = gDialog.activeLinksColorColorpicker.color;
496 var visitedColor = gDialog.visitedLinksColorColorpicker.color;
498 CssUtils.getStyleSheetForScreen(doc);
499 CssUtils.addRuleForSelector(doc, "html", [ { property: "background-color",
501 priority: false } ] );
502 CssUtils.addRuleForSelector(doc, "body", [ { property: "background-color",
508 priority: false } ] );
509 CssUtils.addRuleForSelector(doc, ":link", [ { property: "color",
511 priority: false } ] );
512 if (!gDialog.underlineLinks.checked)
513 CssUtils.addRuleForSelector(doc, ":link", [ { property: "text-decoration",
515 priority: false } ] );
516 CssUtils.addRuleForSelector(doc, ":link:active", [ { property: "color",
518 priority: false } ] );
519 CssUtils.addRuleForSelector(doc, ":link:visited", [ { property: "color",
521 priority: false } ] );
523 if (gDialog.makeColorsDefault.checked)
525 prefs.setCharPref("bluegriffon.display.foreground_color", fgColor);
526 prefs.setCharPref("bluegriffon.display.background_color", bgColor);
527 prefs.setCharPref("bluegriffon.display.active_color", activeColor);
528 prefs.setCharPref("bluegriffon.display.anchor_color", linksColor);
529 prefs.setCharPref("bluegriffon.display.visited_color", visitedColor);
530 prefs.setBoolPref("bluegriffon.display.underline_links", gDialog.underlineLinks.checked);
535 var bgImage = gDialog.backgroundImage.value;
538 var bgRepeat = gDialog.backgroundTile.value;
539 var bgAttachment = gDialog.backgroundScroll.value;
540 var bgPosition = gDialog.horizPosition.value + " " + gDialog.vertPosition.value;
541 CssUtils.addRuleForSelector(doc, "body", [ { property: "background-image",
542 value: 'url("' + bgImage + '")',
545 property: "background-repeat",
549 property: "background-attachment",
553 property: "background-position",
555 priority: false } ] );
560 function OpenColorDialog(aColorObjectId, aElt)
562 var cph = ColorPickerHelper;
563 cph.openColorPicker(window, aColorObjectId, "tagada", true);
564 if (!cph.isCancelled(aColorObjectId))
566 aElt.firstChild.style.backgroundColor = cph.getCurrentColor(aColorObjectId);