Class: GuindillaGUI::Input

Inherits:
Element show all
Defined in:
lib/guindilla_gui/guindilla_classes.rb

Overview

—————————————————————————-#

Input                                        #

—————————————————————————-#

Instance Attribute Summary collapse

Attributes inherited from Element

#attributes, #id

Attributes inherited from Guindilla

#active_id, #blocks, #elements, #inputs, #socket

Instance Method Summary collapse

Methods inherited from Element

#get_position

Methods inherited from Guindilla

#after, #alert, #align, #append, #attributes, #audio_out, #background, #border, #border_color, #border_radius, #border_width, #bullet_list, #button, #canvas, #chart, #checkbox, #circle, #color, #color_input, #container, #display, #every, #file_input, #font, #font_family, #font_size, #h_box, #h_rule, #heading, #height, #hide, #image, #justify, #line_break, #link, #margin, #move_to, #number_input, #on_click, #on_hover, #on_leave, #on_mouse_move, #opacity, #ordered_list, #padding, #para, #polygon, #radio_button, #range_slider, #rectangle, #rotate, #show, #size, #source, #square, #style, #sub_script, #sup_script, #text, #text_align, #text_input, #toggle, #transition, #triangle, #url_input, #v_box, #video_out, #web_frame, #width

Constructor Details

#initialize(type, label, attributes, &block) ⇒ Input

Returns a new instance of Input.



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/guindilla_gui/guindilla_classes.rb', line 411

def initialize(type, label, attributes, &block)
  attributes[:hidden] = true
  min = attributes.delete(:min) if attributes.has_key?(:min)
  max = attributes.delete(:max) if attributes.has_key?(:max)
  step = attributes.delete(:step) if attributes.has_key?(:step)
  value = attributes.delete(:value) if attributes.has_key?(:value)
  super("input", attributes)

  send_js(%Q~ #{self.id}.type = "#{type}"; ~)
  @@gui.inputs[:"#{self.id}"] = self
  @@gui.blocks[:"#{self.id}"] = block if block_given?
  group = attributes[:group]   #####

  case type
  when "checkbox"
    send_js(%Q~
      #{self.id}.oninput = function(event){
        socket.send("#{self.id}:!!:input:!!:" + #{self.id}.checked);
        event.stopPropagation();
      };
    ~)
    self.check if attributes[:checked]
  when "color"
    send_js(%Q~
      #{self.id}.oninput = function(event){
        socket.send("#{self.id}:!!:input:!!:" + #{self.id}.value);
        event.stopPropagation();
      };
    ~)
  when "file"
    send_js(%Q~
      #{self.id}.oninput = function(event){
        socket.send("#{self.id}:!!:input:!!:" + URL.createObjectURL(#{self.id}.files[0]));
        event.stopPropagation();
      };
      #{self.id}.setAttribute('multiple', '');
    ~)
  when "number"
    send_js(%Q~
      #{self.id}.setAttribute('min', '#{min}') ;
      #{self.id}.setAttribute('max', '#{max}') ;
    ~)
    send_js(%Q~
      #{self.id}.onchange = function(event){
        socket.send("#{self.id}:!!:input:!!:" + #{self.id}.value);
        event.stopPropagation();
      };
    ~)
  when "radio"
    send_js(%Q~ #{self.id}.name = "#{group}"; ~)
    send_js(%Q~
      #{self.id}.oninput = function(event){
        socket.send("#{self.id}:!!:input:!!:" + #{self.id}.checked);
        event.stopPropagation();
      };
    ~)
    self.check if attributes[:checked]
  when "range"
    send_js(%Q~
      #{self.id}.setAttribute('min', '#{min}') ;
      #{self.id}.setAttribute('max', '#{max}') ;
      #{self.id}.setAttribute('step', '#{step}') ;
      #{self.id}.setAttribute('value', '#{value}') ;
    ~)
    send_js(%Q~
      #{self.id}.onchange = function(event){
        socket.send("#{self.id}:!!:input:!!:" + #{self.id}.value);
        event.stopPropagation();
      };
    ~)
  when "text"
    send_js(%Q~
      #{self.id}.oninput = function(event){
        socket.send("#{self.id}:!!:input:!!:" + #{self.id}.value);
        event.stopPropagation();
      };
    ~)
  when "url"
    send_js(%Q~
      #{self.id}.oninput = function(event){
        socket.send("#{self.id}:!!:input:!!:" + #{self.id}.value);
        event.stopPropagation();
      };
    ~)
  end #case type

  @label = Element.new("label")
  send_js(%Q~ #{@label.id}.innerHTML = "#{label}"; ~)
  @label.append(self)
  @label.show
  return self  ## ?
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



409
410
411
# File 'lib/guindilla_gui/guindilla_classes.rb', line 409

def label
  @label
end

#valueObject

Returns the value of attribute value.



409
410
411
# File 'lib/guindilla_gui/guindilla_classes.rb', line 409

def value
  @value
end

Instance Method Details

#checkObject

initialize



504
505
506
# File 'lib/guindilla_gui/guindilla_classes.rb', line 504

def check
  send_js(%Q~ #{self.id}.checked = true; ~)
end

#uncheckObject



508
509
510
# File 'lib/guindilla_gui/guindilla_classes.rb', line 508

def uncheck
  send_js(%Q~ #{self.id}.checked = false; ~)
end