Полезная информация

Хотите узнать больше о расширениях? Посмотрите ролики, рассказывающие о работе с расширениями Firefox.

№121-05-2012 01:41:58

init
Участник
 
Группа: Members
Зарегистрирован: 14-04-2012
Сообщений: 42
UA: Firefox 12.0

[CB] Open/close find bar (with input autoclear button)

Open/close find bar (with input autoclear button)(Firefox 4+)
Автор: init
Описание: Кнопка позволяет открывать/закрывать панель быстрого поиска, добавляет кнопку в поле ввода текста для его быстрой очистки.

Старая версия
Код кнопки:

Выделить код

Код:

custombutton://%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3Ccustombutton%20xmlns%3Acb%3D%22http%3A//xsms.nm.ru/custombuttons/%22%3E%0A%20%20%3Cname%3EOpen/close%20find%20bar%20%28with%20input%20autoclear%20button%29%3C/name%3E%0A%20%20%3Cimage%3E%3C%21%5BCDATA%5Bcustombuttons-stdicon-1%5D%5D%3E%3C/image%3E%0A%20%20%3Cmode%3E0%3C/mode%3E%0A%20%20%3Cinitcode%3E%3C%21%5BCDATA%5Bthis.setAttribute%28%22style%22%2C%22list-style-image%3Aurl%28%27chrome%3A//global/skin/icons/Search-glass.png%27%29%21important%3B-moz-image-region%3A%20rect%280px%2C%2048px%2C%2016px%2C%2032px%29%21important%3B%22%29%3B%0A%0Avar%20quickSearchBar%20%3D%20document.getAnonymousElementByAttribute%28gFindBar%2C%20%22anonid%22%2C%20%22findbar-textbox%22%29%3B%0A%0A//%20--Clear%20old%20garbage%20to%20avoid%20inneccessary%20duplicates%20while%20testing%0Avar%20oldClearInputFieldButton%20%3D%20document.getAnonymousElementByAttribute%28gFindBar%2C%20%22anonid%22%2C%20%22clear-button%22%29%3B%0Aif%20%28oldClearInputFieldButton%29%20oldClearInputFieldButton.parentNode.removeChild%28oldClearInputFieldButton%29%3B%0A%0Avar%20clearInputFieldButton%3Ddocument.createElement%28%27toolbarbutton%27%29%3B%0AclearInputFieldButton.setAttribute%28%27oncommand%27%2C%22var%20quickSearchBar%20%3D%20document.getAnonymousElementByAttribute%28gFindBar%2C%20%27anonid%27%2C%20%27findbar-textbox%27%29%3BquickSearchBar.value%20%3D%20%28%27%27%29%3BquickSearchBar.removeAttribute%28%27status%27%29%3BquickSearchBar.focus%28%29%3B%22%29%3B%0AclearInputFieldButton.setAttribute%28%27image%27%2C%28%22data%3Aimage/png%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABIAAAANCAYAAACkTj4ZAAAACXBIWXMAAAsRAAALEQF/ZF+RAAAA90lEQVQoz42QsY2EMBBF36wQDZDsbREEWwEC6UQNdOB6qIaMHN0hE1DCQnBQAMlcApJhDdov2bL/jL//H1FVROQb+OMz/B4JVV03eAL64fryCQUu0bYt8zyzLAsAYRjuzgBZlr2ABzC4b2/upaoq0jQlz3OstfR9j7WWPM9J05SmaSjLEuD15syNVhSFuvDdjTFqjNnFVFVkHfYT+EmShGma6LrubcJxHBNF0Y6r6xrgoarDTuh+vwMwjuPmFAARYasdsfZKcCSduLv4IuIV2npvZ4XNiY8/fCBeoaPIlRNxisGZwBV3FLl0dAafiOto8M3gJLI36z/+8qWK7HHcZQAAAABJRU5ErkJggg%3D%3D%22%29%29%3B%0AclearInputFieldButton.setAttribute%28%27anonid%27%2C%27clear-button%27%29%3B%0AclearInputFieldButton.setAttribute%28%27style%27%2C%27-moz-appearance%3Anone%21important%3Bmax-height%3A16px%3Bpadding%3A2px%21important%3Bborder%3A0%3Bcursor%3Adefault%3B%27%29%3B%0AquickSearchBar.appendChild%28clearInputFieldButton%29%3B%5D%5D%3E%3C/initcode%3E%0A%20%20%3Ccode%3E%3C%21%5BCDATA%5BgFindBar.hidden%20%3F%20gFindBar.onFindCommand%28%29%20%3A%20gFindBar.close%28%29%5D%5D%3E%3C/code%3E%0A%20%20%3Caccelkey%3E%3C%21%5BCDATA%5B%5D%5D%3E%3C/accelkey%3E%0A%20%20%3Chelp%3E%3C%21%5BCDATA%5B%5D%5D%3E%3C/help%3E%0A%20%20%3Cattributes/%3E%0A%3C/custombutton%3E

Код инициализации:

Выделить код

Код:

this.setAttribute("style","list-style-image:url('chrome://global/skin/icons/Search-glass.png')!important;-moz-image-region: rect(0px, 48px, 16px, 32px)!important;");

var quickSearchBar = document.getAnonymousElementByAttribute(gFindBar, "anonid", "findbar-textbox");

// --Clear old garbage to avoid inneccessary duplicates while testing
var oldClearInputFieldButton = document.getAnonymousElementByAttribute(gFindBar, "anonid", "clear-button");
if (oldClearInputFieldButton) oldClearInputFieldButton.parentNode.removeChild(oldClearInputFieldButton);

var clearInputFieldButton=document.createElement('toolbarbutton');
clearInputFieldButton.setAttribute('oncommand',"var quickSearchBar = document.getAnonymousElementByAttribute(gFindBar, 'anonid', 'findbar-textbox');quickSearchBar.value = ('');quickSearchBar.removeAttribute('status');quickSearchBar.focus();");
clearInputFieldButton.setAttribute('image',("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAANCAYAAACkTj4ZAAAACXBIWXMAAAsRAAALEQF/ZF+RAAAA90lEQVQoz42QsY2EMBBF36wQDZDsbREEWwEC6UQNdOB6qIaMHN0hE1DCQnBQAMlcApJhDdov2bL/jL//H1FVROQb+OMz/B4JVV03eAL64fryCQUu0bYt8zyzLAsAYRjuzgBZlr2ABzC4b2/upaoq0jQlz3OstfR9j7WWPM9J05SmaSjLEuD15syNVhSFuvDdjTFqjNnFVFVkHfYT+EmShGma6LrubcJxHBNF0Y6r6xrgoarDTuh+vwMwjuPmFAARYasdsfZKcCSduLv4IuIV2npvZ4XNiY8/fCBeoaPIlRNxisGZwBV3FLl0dAafiOto8M3gJLI36z/+8qWK7HHcZQAAAABJRU5ErkJggg=="));
clearInputFieldButton.setAttribute('anonid','clear-button');
clearInputFieldButton.setAttribute('style','-moz-appearance:none!important;max-height:16px;padding:2px!important;border:0;cursor:default;');
quickSearchBar.appendChild(clearInputFieldButton);

Код:

Выделить код

Код:

gFindBar.hidden ? gFindBar.onFindCommand() : gFindBar.close()

Отредактировано init (06-07-2012 20:15:54)

Отсутствует

 

№221-05-2012 10:09:38

Inko7
Участник
 
Группа: Members
Зарегистрирован: 09-11-2009
Сообщений: 957
UA: Firefox 12.0

Re: [CB] Open/close find bar (with input autoclear button)

init
все отлично!
Но можно иконку очистки справа, а не слева? Вот так:
9db4887fceb3.jpg

Отсутствует

 

№306-07-2012 20:23:07

init
Участник
 
Группа: Members
Зарегистрирован: 14-04-2012
Сообщений: 42
UA: Firefox 13.0

Re: [CB] Open/close find bar (with input autoclear button)

Изменения: Добавлена возможность выбрать расположение кнопки слева или справа от поля ввода текста при помощи контекстного меню. Обычное меню кнопок доступное по щелчку с нажатой клавишей ctrl, shift или alt.
Расположение справа реализовано конечно не очень, но пока по-другому не получилось сделать.

Последняя версия
Код кнопки:

Выделить код

Код:

custombutton://%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3Ccustombutton%20xmlns%3Acb%3D%22http%3A//xsms.nm.ru/custombuttons/%22%3E%0A%20%20%3Cname%3EOpen/close%20find%20bar%20%28with%20input%20autoclear%20button%29%3C/name%3E%0A%20%20%3Cimage%3E%3C%21%5BCDATA%5Bcustombuttons-stdicon-1%5D%5D%3E%3C/image%3E%0A%20%20%3Cmode%3E0%3C/mode%3E%0A%20%20%3Cinitcode%3E%3C%21%5BCDATA%5Bvar%20buttonAppendPosPref%20%3D%20%22customButton.toggleFindbar.clearButtonPos%22%3B%0Avar%20buttonAppendPos%20%3D%20cbu.getPrefs%28buttonAppendPosPref%29%3B%0Aif%20%28%21buttonAppendPos%29%20%7B%0A%09buttonAppendPos%20%3D%20%22left%22%3B%0A%09cbu.setPrefs%28buttonAppendPosPref%2C%20buttonAppendPos%29%3B%0A%7D%0A%0Athis.appendMenu%20%3D%20this.appendChild%28cbu.makeXML%28%0A%09%3Cmenupopup%20xmlns%3D%22http%3A//www.mozilla.org/keymaster/gatekeeper/there.is.only.xul%22%3E%0A%20%09%3Cmenuitem%20type%3D%22radio%22%20label%3D%22%22%20oncommand%3D%22this.parentNode.parentNode.toggleRightPos%28%27left%27%29%3B%22%20/%3E%0A%20%09%3Cmenuitem%20type%3D%22radio%22%20label%3D%22%22%20oncommand%3D%22this.parentNode.parentNode.toggleRightPos%28%27right%27%29%3B%22%20/%3E%0A%09%3C/menupopup%3E%0A%29%29%3B%0Aif%28cbu.getPrefs%28%22general.useragent.locale%22%29%20%3D%3D%20%22ru%22%29%20%7B%0A%09var%20menuLabel1%20%3D%20%22%u041A%u043D%u043E%u043F%u043A%u0430%20%u043E%u0447%u0438%u0441%u0442%u043A%u0438%20%u0441%u043B%u0435%u0432%u0430%22%3B%0A%09var%20menuLabel2%20%3D%20%22%u041A%u043D%u043E%u043F%u043A%u0430%20%u043E%u0447%u0438%u0441%u0442%u043A%u0438%20%u0441%u043F%u0440%u0430%u0432%u0430%22%3B%0A%7D%20else%20%7B%0A%09var%20menuLabel1%20%3D%20%22Place%20clear%20button%20to%20the%20left%22%3B%0A%09var%20menuLabel2%20%3D%20%22Place%20clear%20button%20to%20the%20right%22%3B%0A%7D%0Athis.appendMenu.children%5B0%5D.label%20%3D%20menuLabel1%3B%0Athis.appendMenu.children%5B1%5D.label%20%3D%20menuLabel2%3B%0Aif%28buttonAppendPos%20%3D%3D%20%27left%27%29%20%7B%0A%09this.appendMenu.children%5B0%5D.setAttribute%28%22checked%22%2C%20%22true%22%29%3B%0A%7D%20else%20%7B%0A%09this.appendMenu.children%5B1%5D.setAttribute%28%22checked%22%2C%20%22true%22%29%3B%0A%7D%0A%0Athis.onclick%20%3D%20function%28event%29%20%7B%0A%20if%28event.button%20%3D%3D%200%29%20%7B%0A%20%20%20if%28event.target%20%3D%3D%20this%29%20%7B%0A%20%09gFindBar.hidden%20%3F%20gFindBar.onFindCommand%28%29%20%3A%20gFindBar.close%28%29%3B%0A%20%20%20%7D%0A%20%7D%0A%20if%28event.button%20%3D%3D%202%20%26%26%20%21event.ctrlKey%20%26%26%20%21event.shiftKey%20%26%26%20%21event.altKey%20%26%26%20%21event.metaKey%29%20%7B%0A%20%20this.showMenu%28event%2C%20true%2C%20this.appendMenu%29%3B%0A%20%7D%0A%7D%3B%0A%0Athis.oncontextmenu%20%3D%20function%28event%29%20%7B%0A%20if%28event.button%20%3D%3D%202%20%26%26%20%21event.ctrlKey%20%26%26%20%21event.shiftKey%20%26%26%20%21event.altKey%20%26%26%20%21event.metaKey%29%20%7B%0A%20%20%20%20%20%20%20%20event.preventDefault%28%29%3B%0A%20%20%20%20%20%20%20%20event.stopPropagation%28%29%3B%0A%20%7D%0A%7D%3B%0Athis.showMenu%20%3D%20function%28e%2C%20isContext%2C%20appendMenu%29%20%7B%0A%09document.popupNode%20%3D%20this.ownerDocument.popupNode%20%3D%20this%3B%0A%09if%28%21appendMenu%29%0A%09%09appendMenu%20%3D%20this.appendMenu%3B%0A%09if%28%22openPopupAtScreen%22%20in%20appendMenu%29%0A%09%09appendMenu.openPopupAtScreen%28e.screenX%2C%20e.screenY%2C%20isContext%29%3B%0A%09else%0A%09%09appendMenu.showPopup%28this%2C%20e.screenX%2C%20e.screenY%2C%20isContext%20%3F%20%22context%22%20%3A%20%22popup%22%2C%20null%2C%20null%29%3B%0A%7D%0A%0Athis.toggleRightPos%20%3D%20function%28pos%29%20%7B%0A%09buttonAppendPos%20%3D%20pos%3B%0A%09cbu.setPrefs%28buttonAppendPosPref%2C%20buttonAppendPos%29%3B%0A%09clearOldButton%28%29%3B%0A%09appendNewButton%28%29%3B%0A%7D%0A%0A//-------------------------------------------------------------------------------------------------------%0A%0Athis.setAttribute%28%22style%22%2C%22list-style-image%3Aurl%28%27chrome%3A//global/skin/icons/Search-glass.png%27%29%21important%3B-moz-image-region%3A%20rect%280px%2C%2048px%2C%2016px%2C%2032px%29%21important%3B%22%29%3B%0A%0Avar%20quickSearchBar%20%3D%20document.getAnonymousElementByAttribute%28gFindBar%2C%20%22anonid%22%2C%20%22findbar-textbox%22%29%3B%0A%0A//%20--Clear%20old%20button%0Avar%20clearOldButton%20%3D%20function%28%29%20%7B%0A%09var%20oldClearInputFieldButton%20%3D%20document.getAnonymousElementByAttribute%28gFindBar%2C%20%22anonid%22%2C%20%22clear-button%22%29%3B%0A%09if%20%28oldClearInputFieldButton%29%20oldClearInputFieldButton.parentNode.removeChild%28oldClearInputFieldButton%29%3B%0A%7D%0A%0A//%20--Append%20new%20button%0Avar%20appendNewButton%20%3D%20function%28%29%20%7B%0A%09var%20clearInputFieldButton%3Ddocument.createElement%28%27toolbarbutton%27%29%3B%0A%09clearInputFieldButton.setAttribute%28%27oncommand%27%2C%22var%20quickSearchBar%20%3D%20document.getAnonymousElementByAttribute%28gFindBar%2C%20%27anonid%27%2C%20%27findbar-textbox%27%29%3BquickSearchBar.value%20%3D%20%28%27%27%29%3BquickSearchBar.removeAttribute%28%27status%27%29%3BquickSearchBar.focus%28%29%3B%22%29%3B%0A%09clearInputFieldButton.setAttribute%28%27image%27%2C%28%22data%3Aimage/png%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABIAAAANCAYAAACkTj4ZAAAACXBIWXMAAAsRAAALEQF/ZF+RAAAA90lEQVQoz42QsY2EMBBF36wQDZDsbREEWwEC6UQNdOB6qIaMHN0hE1DCQnBQAMlcApJhDdov2bL/jL//H1FVROQb+OMz/B4JVV03eAL64fryCQUu0bYt8zyzLAsAYRjuzgBZlr2ABzC4b2/upaoq0jQlz3OstfR9j7WWPM9J05SmaSjLEuD15syNVhSFuvDdjTFqjNnFVFVkHfYT+EmShGma6LrubcJxHBNF0Y6r6xrgoarDTuh+vwMwjuPmFAARYasdsfZKcCSduLv4IuIV2npvZ4XNiY8/fCBeoaPIlRNxisGZwBV3FLl0dAafiOto8M3gJLI36z/+8qWK7HHcZQAAAABJRU5ErkJggg%3D%3D%22%29%29%3B%0A%09clearInputFieldButton.setAttribute%28%27anonid%27%2C%27clear-button%27%29%3B%0A%09if%20%28buttonAppendPos%20%3D%3D%20%27left%27%29%20%7B%0A%09%09clearInputFieldButton.setAttribute%28%27style%27%2C%27-moz-appearance%3Anone%21important%3Bmax-height%3A16px%3Bpadding%3A2px%21important%3Bborder%3A0%3Bcursor%3Adefault%3B%27%29%3B%0A%09%09quickSearchBar.appendChild%28clearInputFieldButton%29%3B%0A%09%7D%20else%20if%20%28buttonAppendPos%20%3D%3D%20%27right%27%29%20%7B%0A%09%09clearInputFieldButton.setAttribute%28%27style%27%2C%27-moz-appearance%3Anone%21important%3Bpadding%3A3px%21important%3Bmargin-left%3A-5px%3Bborder%3A0%3Bcursor%3Adefault%3B-moz-transform%3Ascale%28-1%2C1%29%3B%27%29%3B%0A%09%09quickSearchBar.parentNode.insertBefore%28clearInputFieldButton%2C%20quickSearchBar.nextSibling%29%3B%0A%09%7D%0A%7D%0A%0AclearOldButton%28%29%3B%0AappendNewButton%28%29%3B%5D%5D%3E%3C/initcode%3E%0A%20%20%3Ccode%3E%3C%21%5BCDATA%5B/*CODE*/%5D%5D%3E%3C/code%3E%0A%20%20%3Caccelkey%3E%3C%21%5BCDATA%5B%5D%5D%3E%3C/accelkey%3E%0A%20%20%3Chelp%3E%3C%21%5BCDATA%5B%5D%5D%3E%3C/help%3E%0A%20%20%3Cattributes/%3E%0A%3C/custombutton%3E

Код инициализации:

Выделить код

Код:

var buttonAppendPosPref = "customButton.toggleFindbar.clearButtonPos";
var buttonAppendPos = cbu.getPrefs(buttonAppendPosPref);
if (!buttonAppendPos) {
    buttonAppendPos = "left";
    cbu.setPrefs(buttonAppendPosPref, buttonAppendPos);
}

this.appendMenu = this.appendChild(cbu.makeXML(
    <menupopup xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     <menuitem type="radio" label="" oncommand="this.parentNode.parentNode.toggleRightPos('left');" />
     <menuitem type="radio" label="" oncommand="this.parentNode.parentNode.toggleRightPos('right');" />
    </menupopup>
));
if(cbu.getPrefs("general.useragent.locale") == "ru") {
    var menuLabel1 = "Кнопка очистки слева";
    var menuLabel2 = "Кнопка очистки справа";
} else {
    var menuLabel1 = "Place clear button to the left";
    var menuLabel2 = "Place clear button to the right";
}
this.appendMenu.children[0].label = menuLabel1;
this.appendMenu.children[1].label = menuLabel2;
if(buttonAppendPos == 'left') {
    this.appendMenu.children[0].setAttribute("checked", "true");
} else {
    this.appendMenu.children[1].setAttribute("checked", "true");
}

this.onclick = function(event) {
 if(event.button == 0) {
   if(event.target == this) {
     gFindBar.hidden ? gFindBar.onFindCommand() : gFindBar.close();
   }
 }
 if(event.button == 2 && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
  this.showMenu(event, true, this.appendMenu);
 }
};

this.oncontextmenu = function(event) {
 if(event.button == 2 && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
        event.preventDefault();
        event.stopPropagation();
 }
};
this.showMenu = function(e, isContext, appendMenu) {
    document.popupNode = this.ownerDocument.popupNode = this;
    if(!appendMenu)
        appendMenu = this.appendMenu;
    if("openPopupAtScreen" in appendMenu)
        appendMenu.openPopupAtScreen(e.screenX, e.screenY, isContext);
    else
        appendMenu.showPopup(this, e.screenX, e.screenY, isContext ? "context" : "popup", null, null);
}

this.toggleRightPos = function(pos) {
    buttonAppendPos = pos;
    cbu.setPrefs(buttonAppendPosPref, buttonAppendPos);
    clearOldButton();
    appendNewButton();
}

//-------------------------------------------------------------------------------------------------------

this.setAttribute("style","list-style-image:url('chrome://global/skin/icons/Search-glass.png')!important;-moz-image-region: rect(0px, 48px, 16px, 32px)!important;");

var quickSearchBar = document.getAnonymousElementByAttribute(gFindBar, "anonid", "findbar-textbox");

// --Clear old button
var clearOldButton = function() {
    var oldClearInputFieldButton = document.getAnonymousElementByAttribute(gFindBar, "anonid", "clear-button");
    if (oldClearInputFieldButton) oldClearInputFieldButton.parentNode.removeChild(oldClearInputFieldButton);
}

// --Append new button
var appendNewButton = function() {
    var clearInputFieldButton=document.createElement('toolbarbutton');
    clearInputFieldButton.setAttribute('oncommand',"var quickSearchBar = document.getAnonymousElementByAttribute(gFindBar, 'anonid', 'findbar-textbox');quickSearchBar.value = ('');quickSearchBar.removeAttribute('status');quickSearchBar.focus();");
    clearInputFieldButton.setAttribute('image',("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAANCAYAAACkTj4ZAAAACXBIWXMAAAsRAAALEQF/ZF+RAAAA90lEQVQoz42QsY2EMBBF36wQDZDsbREEWwEC6UQNdOB6qIaMHN0hE1DCQnBQAMlcApJhDdov2bL/jL//H1FVROQb+OMz/B4JVV03eAL64fryCQUu0bYt8zyzLAsAYRjuzgBZlr2ABzC4b2/upaoq0jQlz3OstfR9j7WWPM9J05SmaSjLEuD15syNVhSFuvDdjTFqjNnFVFVkHfYT+EmShGma6LrubcJxHBNF0Y6r6xrgoarDTuh+vwMwjuPmFAARYasdsfZKcCSduLv4IuIV2npvZ4XNiY8/fCBeoaPIlRNxisGZwBV3FLl0dAafiOto8M3gJLI36z/+8qWK7HHcZQAAAABJRU5ErkJggg=="));
    clearInputFieldButton.setAttribute('anonid','clear-button');
    if (buttonAppendPos == 'left') {
        clearInputFieldButton.setAttribute('style','-moz-appearance:none!important;max-height:16px;padding:2px!important;border:0;cursor:default;');
        quickSearchBar.appendChild(clearInputFieldButton);
    } else if (buttonAppendPos == 'right') {
        clearInputFieldButton.setAttribute('style','-moz-appearance:none!important;padding:3px!important;margin-left:-5px;border:0;cursor:default;-moz-transform:scale(-1,1);');
        quickSearchBar.parentNode.insertBefore(clearInputFieldButton, quickSearchBar.nextSibling);
    }
}

clearOldButton();
appendNewButton();

Отсутствует

 

Board footer

Powered by PunBB
Modified by Mozilla Russia
Copyright © 2004–2020 Mozilla Russia GitHub mark
Язык отображения форума: [Русский] [English]