Материал из Module developer
Перейти к: навигация, поиск
// Refer to the wiget you want to copy 
  module = B.getModule(moduleID)
 var popup = module.GetPopup("Dimmer"); 
 for (var i = 1; i<=3; i++)
 {  // Create a wiget using cloning
  var widget = NewSubDevice.addWidget(Module.ClonePopup(popup, "Dimmer"+ i));
 }

Add a function to the dimmer which enables moving the slider:

// the user slider for the level 
function UserSlider(Level, Slider)
 {  
    Property = "X";
    Len = "Width";  
    // Function for calculating the slider position in relation to the level
    function Move(){
       Slider[Property] = Level.Value * (Level[Len] -50) / 100;
    }                 
    // Subscription for events     IR.AddListener(IR.EVENT_ITEM_PRESS, Level, Move); // pressing on the level 
    IR.AddListener(IR.EVENT_MOUSE_MOVE, Level, Move); // clicking on the level
    IR.AddListener(IR.EVENT_TOUCH_MOVE, Level, Move); // moving a finger on the level 
    IR.SetInterval(600, Move);  // auto-update in 600 ms
} 

The names of new widgets must be unique.