Class: Foliokit::ContentStack

Inherits:
Object
  • Object
show all
Includes:
Modules::Element
Defined in:
lib/foliokit/content_stack.rb

Instance Method Summary collapse

Constructor Details

#initialize(element, package) ⇒ ContentStack

Returns a new instance of ContentStack.



17
18
19
# File 'lib/foliokit/content_stack.rb', line 17

def initialize(element, package)
  super(element, package)
end

Instance Method Details

#articlesObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/foliokit/content_stack.rb', line 38

def articles
  overlay_map = []
  max_index = asset_renditions.count - 1
  device_height = package.manifest.device_height
  overlays.each do |overlay|
    median_y = overlay.bounds.y + (overlay.bounds.height / 2)
    index = unify? ? 0 : [median_y / device_height, max_index].min
    offset_top = index * device_height
    overlay.bounds.translate(0, -offset_top)
    overlay_map[index] ||= []
    overlay_map[index].push(overlay)
  end
  overlay_map = [[]] if overlay_map.empty?
  unless unify?
    overlay_map.push([]) while overlay_map.length < asset_renditions.count
  end
  overlay_map.each_with_index.map { |overlays, index| Article.new(self, overlays, index) }
end

#renditions(index) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/foliokit/content_stack.rb', line 25

def renditions(index)
  if unify?
    asset_renditions.each_with_index.map do |rendition, i|
      rendition.bounds = Types::Bounds.new(0, package.manifest.device_height * i, rendition.width, rendition.height)
      rendition
    end
  else
    rendition = asset_renditions[index]
    rendition.bounds = Types::Bounds.new(0, 0, rendition.width, rendition.height)
    [rendition]
  end
end

#unify?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/foliokit/content_stack.rb', line 21

def unify?
  (smooth_scrolling == orientation) || (smooth_scrolling == "true")
end