B2G/gecko/browser/devtools/responsivedesign/responsivedesign.jsm
/**
   * Add a preset to the list and the memory
   */
Add a preset to the list and the memory
Add a preset to the list and the memory
function RUI_addPreset() {
    let w = this.customPreset.width;
    let h = this.customPreset.height;
    let newName = {};
    let title = this.strings.GetStringFromName("responsiveUI.customNamePromptTitle");
    let message = this.strings.formatStringFromName("responsiveUI.customNamePromptMsg", [w, h], 2);
    Services.prompt.prompt(null, title, message, newName, null, {});
    let newPreset = {
      key: w + "x" + h,
      name: newName.value,
      width: w,
      height: h
    };
    this.presets.push(newPreset);
    this.presets.sort(function RUI_sortPresets(aPresetA, aPresetB) {
      if (aPresetA.custom && !aPresetB.custom) {
        return 1;
      }
      if (!aPresetA.custom && aPresetB.custom) {
        return -1;
      }
      if (aPresetA.width === aPresetB.width) {
        if (aPresetA.height === aPresetB.height) {
          return 0;
        } else {
          return aPresetA.height > aPresetB.height;
        }
      } else {
        return aPresetA.width > aPresetB.width;
      }
    });
    this.savePresets();
    let newMenuitem = this.chromeDoc.createElement("menuitem");
    newMenuitem.setAttribute("ispreset", true);
    this.setMenuLabel(newMenuitem, newPreset);
    this.menuitems.set(newMenuitem, newPreset);
    let idx = this.presets.indexOf(newPreset);
    let beforeMenuitem = this.menulist.firstChild.childNodes[idx + 1];
    this.menulist.firstChild.insertBefore(newMenuitem, beforeMenuitem);
    this.menulist.selectedItem = newMenuitem;
    this.currentPresetKey = newPreset.key;
    this.saveCurrentPreset();
  }
function RUI_addPreset ( ) { let w = this . customPreset . width ; let h = this . customPreset . height ; let newName = { } ; let title = this . strings . GetStringFromName ( "responsiveUI.customNamePromptTitle" ) ; let message = this . strings . formatStringFromName ( "responsiveUI.customNamePromptMsg" , [ w , h ] , 2 ) ; Services . prompt . prompt ( null , title , message , newName , null , { } ) ; let newPreset = { key : w + "x" + h , name : newName . value , width : w , height : h } ; this . presets . push ( newPreset ) ; this . presets . sort ( function RUI_sortPresets ( aPresetA , aPresetB ) { if ( aPresetA . custom && ! aPresetB . custom ) { return 1 ; } if ( ! aPresetA . custom && aPresetB . custom ) { return - 1 ; } if ( aPresetA . width === aPresetB . width ) { if ( aPresetA . height === aPresetB . height ) { return 0 ; } else { return aPresetA . height > aPresetB . height ; } } else { return aPresetA . width > aPresetB . width ; } } ) ; this . savePresets ( ) ; let newMenuitem = this . chromeDoc . createElement ( "menuitem" ) ; newMenuitem . setAttribute ( "ispreset" , true ) ; this . setMenuLabel ( newMenuitem , newPreset ) ; this . menuitems . set ( newMenuitem , newPreset ) ; let idx = this . presets . indexOf ( newPreset ) ; let beforeMenuitem = this . menulist . firstChild . childNodes [ idx + 1 ] ; this . menulist . firstChild . insertBefore ( newMenuitem , beforeMenuitem ) ; this . menulist . selectedItem = newMenuitem ; this . currentPresetKey = newPreset . key ; this . saveCurrentPreset ( ) ; }
Add a preset to the list and the memory
Add a preset to the list and the memory
// Sort the presets according to width/height ascending order // We keep custom preset at first