Sha256: 89da716a09b7c926e068a9190f77f7681106b1b142145a8a53c84225fa73958e
Contents?: true
Size: 997 Bytes
Versions: 9
Compression:
Stored size: 997 Bytes
Contents
# frozen_string_literal: true class Atome def html(obj = nil) if obj @html = obj else @html end end def descendant_of?(ancestor) HTML.is_descendant(ancestor, id) end def to_px(particle) ruby_wasm_code = <<-JS var div = document.getElementById("#{@id}"); var style = window.getComputedStyle(div); var original_value = style.getPropertyValue("#{particle}"); var parsed_value = parseInt(original_value); return parsed_value; JS JS.eval(ruby_wasm_code).to_f end def to_percent(property) parent = grab(attach) parent_width = parent.to_px(:width) parent_height = parent.to_px(:height) property_needed_px = to_px(property) case property when :width, :left "#{(property_needed_px / parent_width.to_f) * 100}%" when :height, :top "#{(property_needed_px / parent_height.to_f) * 100}%" else raise ArgumentError # unsupported property use left , top, width an height end end end
Version data entries
9 entries across 9 versions & 1 rubygems