diff --git a/app/assets/javascripts/supplier/app/application.js.coffee b/app/assets/javascripts/supplier/app/application.js.coffee index 5c8f4836..67d71ab7 100644 --- a/app/assets/javascripts/supplier/app/application.js.coffee +++ b/app/assets/javascripts/supplier/app/application.js.coffee @@ -6,6 +6,7 @@ #= require shared-ember-helpers/all #= require ./app #= require ./controllers/modals/base_controller +#= require ion.sound #= require_tree . @$assets_path = '/assets/'; @EmberENV = {FEATURES: {'query-params-new': true}} diff --git a/app/assets/javascripts/supplier/app/controllers/application_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/application_controller.js.coffee index 42de8efe..98ba449d 100644 --- a/app/assets/javascripts/supplier/app/controllers/application_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/application_controller.js.coffee @@ -1,5 +1,6 @@ App.ApplicationController = Ember.Controller.extend active_section: null + flash_message: '' #init: -> #success = (supplier)=> ## A supplier record with id current and with the content of the returned supplier is created diff --git a/app/assets/javascripts/supplier/app/models/order.js.coffee b/app/assets/javascripts/supplier/app/models/order.js.coffee index e5958877..2c70da81 100644 --- a/app/assets/javascripts/supplier/app/models/order.js.coffee +++ b/app/assets/javascripts/supplier/app/models/order.js.coffee @@ -33,6 +33,11 @@ App.Order = DS.Model.extend @get('product_orders').map((po) -> "#{po.get('quantity')} x #{po.get('product.name')}").join(', ') ).property('product_orders.@each.quantity', 'product_orders.@each.product.@each.name') + display_with_table: (-> + table = t('models.table').toLowerCase() + "#{@get('display')} #{table} #{@get('list.table.number')}".htmlSafe() + ).property('display', 'list.table.number') + display_tag: (-> "#{@get('display')}".htmlSafe() ).property('display', 'state') diff --git a/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb b/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb index 8c5e915d..01c319c4 100644 --- a/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb +++ b/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb @@ -69,16 +69,36 @@ App.ApplicationRoute = Ember.Route.extend body: options.body cancel: options.cancel ok: options.ok + newOrder: (order_id)-> + @store.findById('order', order_id).then (order)=> + controller = @controllerFor('application') + return if controller.get('active_section.id') and order.get('section.id') isnt controller.get('active_section.id') + $('body').addClass('new-order') + controller.set 'flash_message', order.get('display_with_table') + setTimeout (-> $('body').removeClass('new-order')), 4000 + try ion.sound.play('water_droplet') events: - list_needs_help: (data) -> list.markNeedsHelp() if list = @store.getById('list', data.id) - list_needs_payment: (data) -> list.markNeedsPayment() if list = @store.getById('list', data.id) + list_needs_help: (data) -> + if list = @store.getById('list', data.id) + list.markNeedsHelp() + controller = @controllerFor('application') + return if controller.get('active_section.id') and list.get('section.id') isnt controller.get('active_section.id') + try ion.sound.play 'bell_ring' + list_needs_payment: (data) -> + if list = @store.getById('list', data.id) + list.markNeedsPayment() + controller = @controllerFor('application') + return if controller.get('active_section.id') and list.get('section.id') isnt controller.get('active_section.id') + try ion.sound.play 'water_droplet_3' list_is_paid: (data) -> list.markIsPaid() if list = @store.getById('list', data.id) list_update: (data) -> + if data.new_order_id + @send 'newOrder', data.new_order_id @store.pushPayload('list', data) # Fix broken reference. TODO: remove this when single source of # truth is working - @store.findById('list', e.data.list.id).then (list)-> - list.get('table').then (table)->table.set('active_list', list) + #@store.findById('list', data.list.id).then (list)-> + # list.get('table').then (table)->table.set('active_list', list) list_changed_table: (data) -> @store.pushPayload('list', lists: [data.list]) list_closed: (data) -> list.markClosed() if list = @store.getById('list', data.id) list_helped: (data) -> list.markHelped() if list = @store.getById('list', data.id) diff --git a/app/assets/javascripts/supplier/app/templates/application.emblem b/app/assets/javascripts/supplier/app/templates/application.emblem index e8cb0449..3927fda7 100644 --- a/app/assets/javascripts/supplier/app/templates/application.emblem +++ b/app/assets/javascripts/supplier/app/templates/application.emblem @@ -1,3 +1,4 @@ = partial "global/top_menu" .main-section= outlet += view flash_message = outlet modal diff --git a/app/assets/javascripts/supplier/app/templates/flash_message.emblem b/app/assets/javascripts/supplier/app/templates/flash_message.emblem new file mode 100644 index 00000000..7b97c850 --- /dev/null +++ b/app/assets/javascripts/supplier/app/templates/flash_message.emblem @@ -0,0 +1 @@ += flash_message diff --git a/app/assets/javascripts/supplier/app/views/application_view.js.coffee b/app/assets/javascripts/supplier/app/views/application_view.js.coffee index 3337bf0f..3a34c4eb 100644 --- a/app/assets/javascripts/supplier/app/views/application_view.js.coffee +++ b/app/assets/javascripts/supplier/app/views/application_view.js.coffee @@ -11,6 +11,14 @@ App.ApplicationView = Ember.View.extend menu.show().animate left: 0 toggle.animate left: 222 - 30, -> $(@).addClass('open') + ion.sound + sounds: [ + {name: "bell_ring", volume: 0.8} + {name: "water_droplet"} + {name: "water_droplet_3"} + ] + path: "/sounds/" + preload: true #selector_mappings = #'.top-menu-root': '/' #'.top-menu-lists': 'lists' diff --git a/app/assets/javascripts/supplier/app/views/flash-message.js.coffee b/app/assets/javascripts/supplier/app/views/flash-message.js.coffee new file mode 100644 index 00000000..60ed4036 --- /dev/null +++ b/app/assets/javascripts/supplier/app/views/flash-message.js.coffee @@ -0,0 +1,10 @@ +App.FlashMessageView = Ember.View.extend + templateName: 'flash_message' + classNames: ['flash-message'] + classNameBindings: ['message:active'] + message: (-> @get('controller.flash_message')).property('controller.flash_message') + + inactivator: (-> + if @get('message') + Ember.run.later (=> @set 'controller.flash_message', ''), 4000 + ).observes('message') diff --git a/app/assets/stylesheets/supplier/foundation1/application.css.sass b/app/assets/stylesheets/supplier/foundation1/application.css.sass index 9bc28b7d..bace7c1c 100644 --- a/app/assets/stylesheets/supplier/foundation1/application.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/application.css.sass @@ -1,6 +1,7 @@ //= require qtip //= require_directory ../base1-shared //= require pickdate +@import bourbon @import ./qconstants @import ./foundation_and_overrides @import ./qstructure diff --git a/app/assets/stylesheets/supplier/foundation1/components/_flash_message.css.sass b/app/assets/stylesheets/supplier/foundation1/components/_flash_message.css.sass new file mode 100644 index 00000000..54fb4451 --- /dev/null +++ b/app/assets/stylesheets/supplier/foundation1/components/_flash_message.css.sass @@ -0,0 +1,25 @@ +.flash-message + position: fixed + top: 60px + right: -440px + background-color: rgba(200,200,200,0.8) + padding: 20px + width: 400px + border-radius: 9999px + font-weight: bold + font-size: 1.4 + +animation(flashMessageInactive 0.5s) + &.active + +animation(flashMessageActive 0.5s) + right: 20px + ++keyframes(flashMessageActive) + from + right: -440px + to + right: 20px ++keyframes(flashMessageInactive) + from + right: 20px + to + right: -440px diff --git a/app/models/list.rb b/app/models/list.rb index f01c5683..007a5dd0 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -286,7 +286,7 @@ class List broadcast_users 'new_order', UserExtendedListSerializer.new(order.list).as_json # broadcast_users 'orders_placed_count', count: orders_placed_count - broadcast_supplier supplier.id, 'list_update', SupplierListSerializer.new(self).as_json + broadcast_supplier supplier.id, 'list_update', SupplierListSerializer.new(self).as_json.merge(new_order_id: order.id) # broadcast_supplier supplier.id, 'new_order', OrderSerializer.new(order) broadcast_supplier supplier.id, 'orders_placed_count', count: orders_placed_count order diff --git a/public/sounds/beer_can_opening.aac b/public/sounds/beer_can_opening.aac new file mode 100644 index 00000000..93a28d03 Binary files /dev/null and b/public/sounds/beer_can_opening.aac differ diff --git a/public/sounds/beer_can_opening.mp3 b/public/sounds/beer_can_opening.mp3 new file mode 100644 index 00000000..0b3973a2 Binary files /dev/null and b/public/sounds/beer_can_opening.mp3 differ diff --git a/public/sounds/beer_can_opening.ogg b/public/sounds/beer_can_opening.ogg new file mode 100644 index 00000000..efa8723e Binary files /dev/null and b/public/sounds/beer_can_opening.ogg differ diff --git a/public/sounds/bell_ring.aac b/public/sounds/bell_ring.aac new file mode 100644 index 00000000..05dbe8f9 Binary files /dev/null and b/public/sounds/bell_ring.aac differ diff --git a/public/sounds/bell_ring.mp3 b/public/sounds/bell_ring.mp3 new file mode 100644 index 00000000..f6618819 Binary files /dev/null and b/public/sounds/bell_ring.mp3 differ diff --git a/public/sounds/bell_ring.ogg b/public/sounds/bell_ring.ogg new file mode 100644 index 00000000..9ac98765 Binary files /dev/null and b/public/sounds/bell_ring.ogg differ diff --git a/public/sounds/branch_break.aac b/public/sounds/branch_break.aac new file mode 100644 index 00000000..e964799c Binary files /dev/null and b/public/sounds/branch_break.aac differ diff --git a/public/sounds/branch_break.mp3 b/public/sounds/branch_break.mp3 new file mode 100644 index 00000000..ab209433 Binary files /dev/null and b/public/sounds/branch_break.mp3 differ diff --git a/public/sounds/branch_break.ogg b/public/sounds/branch_break.ogg new file mode 100644 index 00000000..7ddc6299 Binary files /dev/null and b/public/sounds/branch_break.ogg differ diff --git a/public/sounds/button_click.aac b/public/sounds/button_click.aac new file mode 100644 index 00000000..d3d7bbde Binary files /dev/null and b/public/sounds/button_click.aac differ diff --git a/public/sounds/button_click.mp3 b/public/sounds/button_click.mp3 new file mode 100644 index 00000000..5e6bb639 Binary files /dev/null and b/public/sounds/button_click.mp3 differ diff --git a/public/sounds/button_click.ogg b/public/sounds/button_click.ogg new file mode 100644 index 00000000..acd9d7aa Binary files /dev/null and b/public/sounds/button_click.ogg differ diff --git a/public/sounds/button_click_on.aac b/public/sounds/button_click_on.aac new file mode 100644 index 00000000..7fda0c0c Binary files /dev/null and b/public/sounds/button_click_on.aac differ diff --git a/public/sounds/button_click_on.mp3 b/public/sounds/button_click_on.mp3 new file mode 100644 index 00000000..af2f5b26 Binary files /dev/null and b/public/sounds/button_click_on.mp3 differ diff --git a/public/sounds/button_click_on.ogg b/public/sounds/button_click_on.ogg new file mode 100644 index 00000000..8f46c6c9 Binary files /dev/null and b/public/sounds/button_click_on.ogg differ diff --git a/public/sounds/button_push.aac b/public/sounds/button_push.aac new file mode 100644 index 00000000..7b802f8a Binary files /dev/null and b/public/sounds/button_push.aac differ diff --git a/public/sounds/button_push.mp3 b/public/sounds/button_push.mp3 new file mode 100644 index 00000000..6cb4f7cc Binary files /dev/null and b/public/sounds/button_push.mp3 differ diff --git a/public/sounds/button_push.ogg b/public/sounds/button_push.ogg new file mode 100644 index 00000000..38ed0b8c Binary files /dev/null and b/public/sounds/button_push.ogg differ diff --git a/public/sounds/button_tiny.aac b/public/sounds/button_tiny.aac new file mode 100644 index 00000000..0934ea70 Binary files /dev/null and b/public/sounds/button_tiny.aac differ diff --git a/public/sounds/button_tiny.mp3 b/public/sounds/button_tiny.mp3 new file mode 100644 index 00000000..db994950 Binary files /dev/null and b/public/sounds/button_tiny.mp3 differ diff --git a/public/sounds/button_tiny.ogg b/public/sounds/button_tiny.ogg new file mode 100644 index 00000000..b4910bc6 Binary files /dev/null and b/public/sounds/button_tiny.ogg differ diff --git a/public/sounds/camera_flashing.aac b/public/sounds/camera_flashing.aac new file mode 100644 index 00000000..9b67d9b3 Binary files /dev/null and b/public/sounds/camera_flashing.aac differ diff --git a/public/sounds/camera_flashing.mp3 b/public/sounds/camera_flashing.mp3 new file mode 100644 index 00000000..edf02fb2 Binary files /dev/null and b/public/sounds/camera_flashing.mp3 differ diff --git a/public/sounds/camera_flashing.ogg b/public/sounds/camera_flashing.ogg new file mode 100644 index 00000000..615b7a27 Binary files /dev/null and b/public/sounds/camera_flashing.ogg differ diff --git a/public/sounds/camera_flashing_2.aac b/public/sounds/camera_flashing_2.aac new file mode 100644 index 00000000..31345d40 Binary files /dev/null and b/public/sounds/camera_flashing_2.aac differ diff --git a/public/sounds/camera_flashing_2.mp3 b/public/sounds/camera_flashing_2.mp3 new file mode 100644 index 00000000..17cd7abe Binary files /dev/null and b/public/sounds/camera_flashing_2.mp3 differ diff --git a/public/sounds/camera_flashing_2.ogg b/public/sounds/camera_flashing_2.ogg new file mode 100644 index 00000000..0bf1328d Binary files /dev/null and b/public/sounds/camera_flashing_2.ogg differ diff --git a/public/sounds/cd_tray.aac b/public/sounds/cd_tray.aac new file mode 100644 index 00000000..b13094b7 Binary files /dev/null and b/public/sounds/cd_tray.aac differ diff --git a/public/sounds/cd_tray.mp3 b/public/sounds/cd_tray.mp3 new file mode 100644 index 00000000..d872331e Binary files /dev/null and b/public/sounds/cd_tray.mp3 differ diff --git a/public/sounds/cd_tray.ogg b/public/sounds/cd_tray.ogg new file mode 100644 index 00000000..d91b190d Binary files /dev/null and b/public/sounds/cd_tray.ogg differ diff --git a/public/sounds/computer_error.aac b/public/sounds/computer_error.aac new file mode 100644 index 00000000..8e4abd2f Binary files /dev/null and b/public/sounds/computer_error.aac differ diff --git a/public/sounds/computer_error.mp3 b/public/sounds/computer_error.mp3 new file mode 100644 index 00000000..17a3a535 Binary files /dev/null and b/public/sounds/computer_error.mp3 differ diff --git a/public/sounds/computer_error.ogg b/public/sounds/computer_error.ogg new file mode 100644 index 00000000..e864dfac Binary files /dev/null and b/public/sounds/computer_error.ogg differ diff --git a/public/sounds/door_bell.aac b/public/sounds/door_bell.aac new file mode 100644 index 00000000..926eca19 Binary files /dev/null and b/public/sounds/door_bell.aac differ diff --git a/public/sounds/door_bell.mp3 b/public/sounds/door_bell.mp3 new file mode 100644 index 00000000..d01d5992 Binary files /dev/null and b/public/sounds/door_bell.mp3 differ diff --git a/public/sounds/door_bell.ogg b/public/sounds/door_bell.ogg new file mode 100644 index 00000000..9f94b2c4 Binary files /dev/null and b/public/sounds/door_bell.ogg differ diff --git a/public/sounds/door_bump.aac b/public/sounds/door_bump.aac new file mode 100644 index 00000000..ed41bbba Binary files /dev/null and b/public/sounds/door_bump.aac differ diff --git a/public/sounds/door_bump.mp3 b/public/sounds/door_bump.mp3 new file mode 100644 index 00000000..5aca04e7 Binary files /dev/null and b/public/sounds/door_bump.mp3 differ diff --git a/public/sounds/door_bump.ogg b/public/sounds/door_bump.ogg new file mode 100644 index 00000000..21801dfe Binary files /dev/null and b/public/sounds/door_bump.ogg differ diff --git a/public/sounds/glass.aac b/public/sounds/glass.aac new file mode 100644 index 00000000..f93060fc Binary files /dev/null and b/public/sounds/glass.aac differ diff --git a/public/sounds/glass.mp3 b/public/sounds/glass.mp3 new file mode 100644 index 00000000..e1956909 Binary files /dev/null and b/public/sounds/glass.mp3 differ diff --git a/public/sounds/glass.ogg b/public/sounds/glass.ogg new file mode 100644 index 00000000..9dabb838 Binary files /dev/null and b/public/sounds/glass.ogg differ diff --git a/public/sounds/keyboard_desk.aac b/public/sounds/keyboard_desk.aac new file mode 100644 index 00000000..372acdc5 Binary files /dev/null and b/public/sounds/keyboard_desk.aac differ diff --git a/public/sounds/keyboard_desk.mp3 b/public/sounds/keyboard_desk.mp3 new file mode 100644 index 00000000..6bf2827f Binary files /dev/null and b/public/sounds/keyboard_desk.mp3 differ diff --git a/public/sounds/keyboard_desk.ogg b/public/sounds/keyboard_desk.ogg new file mode 100644 index 00000000..82bcac18 Binary files /dev/null and b/public/sounds/keyboard_desk.ogg differ diff --git a/public/sounds/light_bulb_breaking.aac b/public/sounds/light_bulb_breaking.aac new file mode 100644 index 00000000..686fafcf Binary files /dev/null and b/public/sounds/light_bulb_breaking.aac differ diff --git a/public/sounds/light_bulb_breaking.mp3 b/public/sounds/light_bulb_breaking.mp3 new file mode 100644 index 00000000..7e227787 Binary files /dev/null and b/public/sounds/light_bulb_breaking.mp3 differ diff --git a/public/sounds/light_bulb_breaking.ogg b/public/sounds/light_bulb_breaking.ogg new file mode 100644 index 00000000..9e1a0926 Binary files /dev/null and b/public/sounds/light_bulb_breaking.ogg differ diff --git a/public/sounds/metal_plate.aac b/public/sounds/metal_plate.aac new file mode 100644 index 00000000..96745736 Binary files /dev/null and b/public/sounds/metal_plate.aac differ diff --git a/public/sounds/metal_plate.mp3 b/public/sounds/metal_plate.mp3 new file mode 100644 index 00000000..d406d4a0 Binary files /dev/null and b/public/sounds/metal_plate.mp3 differ diff --git a/public/sounds/metal_plate.ogg b/public/sounds/metal_plate.ogg new file mode 100644 index 00000000..de0b1e8e Binary files /dev/null and b/public/sounds/metal_plate.ogg differ diff --git a/public/sounds/metal_plate_2.aac b/public/sounds/metal_plate_2.aac new file mode 100644 index 00000000..3b36c8a9 Binary files /dev/null and b/public/sounds/metal_plate_2.aac differ diff --git a/public/sounds/metal_plate_2.mp3 b/public/sounds/metal_plate_2.mp3 new file mode 100644 index 00000000..eb8bd7b7 Binary files /dev/null and b/public/sounds/metal_plate_2.mp3 differ diff --git a/public/sounds/metal_plate_2.ogg b/public/sounds/metal_plate_2.ogg new file mode 100644 index 00000000..af383f61 Binary files /dev/null and b/public/sounds/metal_plate_2.ogg differ diff --git a/public/sounds/pop_cork.aac b/public/sounds/pop_cork.aac new file mode 100644 index 00000000..dfdb94d7 Binary files /dev/null and b/public/sounds/pop_cork.aac differ diff --git a/public/sounds/pop_cork.mp3 b/public/sounds/pop_cork.mp3 new file mode 100644 index 00000000..716643b5 Binary files /dev/null and b/public/sounds/pop_cork.mp3 differ diff --git a/public/sounds/pop_cork.ogg b/public/sounds/pop_cork.ogg new file mode 100644 index 00000000..0fcb1eef Binary files /dev/null and b/public/sounds/pop_cork.ogg differ diff --git a/public/sounds/snap.aac b/public/sounds/snap.aac new file mode 100644 index 00000000..033d29b6 Binary files /dev/null and b/public/sounds/snap.aac differ diff --git a/public/sounds/snap.mp3 b/public/sounds/snap.mp3 new file mode 100644 index 00000000..8a004685 Binary files /dev/null and b/public/sounds/snap.mp3 differ diff --git a/public/sounds/snap.ogg b/public/sounds/snap.ogg new file mode 100644 index 00000000..ecd81e7e Binary files /dev/null and b/public/sounds/snap.ogg differ diff --git a/public/sounds/staple_gun.aac b/public/sounds/staple_gun.aac new file mode 100644 index 00000000..a68a5a27 Binary files /dev/null and b/public/sounds/staple_gun.aac differ diff --git a/public/sounds/staple_gun.mp3 b/public/sounds/staple_gun.mp3 new file mode 100644 index 00000000..f57358ac Binary files /dev/null and b/public/sounds/staple_gun.mp3 differ diff --git a/public/sounds/staple_gun.ogg b/public/sounds/staple_gun.ogg new file mode 100644 index 00000000..1c7ed017 Binary files /dev/null and b/public/sounds/staple_gun.ogg differ diff --git a/public/sounds/tap.aac b/public/sounds/tap.aac new file mode 100644 index 00000000..0c1afffe Binary files /dev/null and b/public/sounds/tap.aac differ diff --git a/public/sounds/tap.mp3 b/public/sounds/tap.mp3 new file mode 100644 index 00000000..4970a1b5 Binary files /dev/null and b/public/sounds/tap.mp3 differ diff --git a/public/sounds/tap.ogg b/public/sounds/tap.ogg new file mode 100644 index 00000000..0306e123 Binary files /dev/null and b/public/sounds/tap.ogg differ diff --git a/public/sounds/water_droplet.aac b/public/sounds/water_droplet.aac new file mode 100644 index 00000000..cbcc91da Binary files /dev/null and b/public/sounds/water_droplet.aac differ diff --git a/public/sounds/water_droplet.mp3 b/public/sounds/water_droplet.mp3 new file mode 100644 index 00000000..8e6bae2f Binary files /dev/null and b/public/sounds/water_droplet.mp3 differ diff --git a/public/sounds/water_droplet.ogg b/public/sounds/water_droplet.ogg new file mode 100644 index 00000000..3fb2dbf2 Binary files /dev/null and b/public/sounds/water_droplet.ogg differ diff --git a/public/sounds/water_droplet_2.aac b/public/sounds/water_droplet_2.aac new file mode 100644 index 00000000..8ba8c875 Binary files /dev/null and b/public/sounds/water_droplet_2.aac differ diff --git a/public/sounds/water_droplet_2.mp3 b/public/sounds/water_droplet_2.mp3 new file mode 100644 index 00000000..1fe6e805 Binary files /dev/null and b/public/sounds/water_droplet_2.mp3 differ diff --git a/public/sounds/water_droplet_2.ogg b/public/sounds/water_droplet_2.ogg new file mode 100644 index 00000000..225e2936 Binary files /dev/null and b/public/sounds/water_droplet_2.ogg differ diff --git a/public/sounds/water_droplet_3.aac b/public/sounds/water_droplet_3.aac new file mode 100644 index 00000000..69e2d3b1 Binary files /dev/null and b/public/sounds/water_droplet_3.aac differ diff --git a/public/sounds/water_droplet_3.mp3 b/public/sounds/water_droplet_3.mp3 new file mode 100644 index 00000000..450f6e1d Binary files /dev/null and b/public/sounds/water_droplet_3.mp3 differ diff --git a/public/sounds/water_droplet_3.ogg b/public/sounds/water_droplet_3.ogg new file mode 100644 index 00000000..0928ef05 Binary files /dev/null and b/public/sounds/water_droplet_3.ogg differ diff --git a/vendor/assets/javascripts/ion.sound.js b/vendor/assets/javascripts/ion.sound.js new file mode 100644 index 00000000..05eea0ca --- /dev/null +++ b/vendor/assets/javascripts/ion.sound.js @@ -0,0 +1,345 @@ +/** + * Ion.Sound + * version 2.1.3 Build 47 + * © 2014 Denis Ineshin | IonDen.com + * + * Project page: http://ionden.com/a/plugins/ion.sound/en.html + * GitHub page: https://github.com/IonDen/ion.sound + * + * Released under MIT licence: + * http://ionden.com/a/plugins/licence-en.html + */ + +var ion = ion || {}; + +(function (ion) { + + var warn = function (text) { + if (text && console) { + if (console.warn && typeof console.warn === "function") { + console.warn(text); + } else if (console.log && typeof console.log === "function") { + console.log(text); + } + } + }; + + if (ion.sound) { + warn("ion.sound already exists!"); + return; + } + + if (typeof Audio !== "function" && typeof Audio !== "object") { + var func = function () { + warn("HTML5 Audio is not supported in this browser"); + }; + ion.sound = function () {}; + ion.sound.play = func; + ion.sound.stop = func; + ion.sound.destroy = func; + func(); + return; + } + + + + var Sound, + is_iOS = /iPad|iPhone/.test(navigator.appVersion), + global_sound, + settings = {}, + sounds = {}, + sounds_num, + ext, + i; + + + + if (is_iOS) { + + Sound = function (options) { + this.name = options.name; + this.loop = false; + this.paused = false; + this.sound = null; + this.callback = null; + }; + + Sound.prototype = { + init: function () { + this.sound = global_sound; + }, + + play: function (obj) { + if (!obj) { + obj = {}; + } + + if (obj.loop) { + if (this.paused) { + this._playLoop(this.loop + 1); + } else { + this._playLoop(obj.loop); + } + } else { + this.loop = false; + this._play(); + } + + if (obj.onEnded && typeof obj.onEnded === "function") { + this.callback = obj.onEnded; + } + }, + + _play: function () { + if (this.paused) { + this.paused = false; + } else { + try { + this.sound.currentTime = 0; + } catch (e) {} + } + + this.sound.removeEventListener("ended"); + this.sound.addEventListener("ended", this._ended.bind(this), false); + this.sound.src = settings.path + this.name + ext; + this.sound.load(); + this.sound.play(); + } + } + + } else { + + Sound = function (options) { + this.name = options.name; + this.volume = settings.volume || 0.5; + this.preload = settings.preload ? "auto" : "none"; + this.loop = false; + this.paused = false; + this.sound = null; + this.callback = null; + + if ("volume" in options) { + this.volume = +options.volume; + } + + if ("preload" in options) { + this.preload = options.preload ? "auto" : "none" + } + }; + + Sound.prototype = { + init: function () { + this.sound = new Audio(); + this.sound.src = settings.path + this.name + ext; + this.sound.load(); + this.sound.preload = this.preload; + this.sound.volume = this.volume; + + this.sound.addEventListener("ended", this._ended.bind(this), false); + }, + + play: function (obj) { + if (!obj) { + obj = {}; + } + + if (obj.volume || obj.volume === 0) { + this.volume = +obj.volume; + this.sound.volume = this.volume; + } + + if (obj.loop) { + if (this.paused) { + this._playLoop(this.loop + 1); + } else { + this._playLoop(obj.loop); + } + } else { + this.loop = false; + this._play(); + } + + if (obj.onEnded && typeof obj.onEnded === "function") { + this.callback = obj.onEnded; + } + }, + + _play: function () { + if (this.paused) { + this.paused = false; + } else { + try { + this.sound.currentTime = 0; + } catch (e) {} + } + + this.sound.play(); + } + }; + + } + + Sound.prototype._playLoop = function (loop) { + if (typeof loop === "boolean") { + // FF 3.6 and iOS, + // sound.loop = true not supported or buggy + this.loop = 9999999; + this._play(); + } else if (typeof loop === "number") { + this.loop = loop - 1; + this._play(); + } + }; + + Sound.prototype._ended = function () { + if (this.loop > 0) { + this.loop -= 1; + this._play(); + } + + if (this.callback) { + this.callback(this.name); + } + }; + + Sound.prototype.pause = function () { + this.paused = true; + this.sound.pause(); + }; + + Sound.prototype.stop = function () { + this.loop = false; + this.sound.pause(); + + try { + this.sound.currentTime = 0; + } catch (e) {} + }; + + Sound.prototype.destroy = function () { + this.stop(); + this.sound.removeEventListener("ended", this._ended.bind(this), false); + this.sound.src = ""; + this.sound = null; + }; + + + + var checkSupport = function () { + global_sound = new Audio(); + + var can_play_mp3 = global_sound.canPlayType('audio/mpeg'), + can_play_ogg = global_sound.canPlayType('audio/ogg'), + can_play_aac = global_sound.canPlayType('audio/mp4; codecs="mp4a.40.2"'); + + if (is_iOS) { + + if (can_play_mp3 === "probably") { + ext = ".mp3"; + } else if (can_play_aac === "probably") { + ext = ".aac"; + } else if (can_play_mp3 === "maybe") { + ext = ".mp3"; + } else if (can_play_aac === "maybe") { + ext = ".aac"; + } + + } else { + + if (can_play_mp3 === "probably") { + ext = ".mp3"; + } else if (can_play_ogg === "probably") { + ext = ".ogg"; + } else if (can_play_mp3 === "maybe") { + ext = ".mp3"; + } else if (can_play_ogg === "maybe") { + ext = ".ogg"; + } else { + ext = ".wav"; + } + + } + }; + + var createSound = function (obj) { + sounds[obj.name] = new Sound(obj); + sounds[obj.name].init(); + }; + + ion.sound = function (options) { + settings = JSON.parse(JSON.stringify(options)); + settings.path = settings.path || ""; + settings.volume = settings.volume || 0.5; + settings.preload = settings.preload || false; + settings.mix = settings.mix || true; + + sounds_num = settings.sounds.length; + + if (!sounds_num) { + warn("No sound-files provided!"); + return; + } + + checkSupport(); + + for (i = 0; i < sounds_num; i++) { + createSound(settings.sounds[i]); + } + }; + + ion.sound.version = "2.1.3"; + + ion.sound.play = function (name, options) { + if (sounds[name]) { + sounds[name].play(options); + } + }; + + ion.sound.pause = function (name) { + if (name && sounds[name]) { + sounds[name].pause(); + } else { + for (i in sounds) { + if (!sounds.hasOwnProperty(i)) { + continue; + } + if (sounds[i]) { + sounds[i].pause(); + } + } + } + }; + + ion.sound.stop = function (name) { + if (name && sounds[name]) { + sounds[name].stop(); + } else { + for (i in sounds) { + if (!sounds.hasOwnProperty(i)) { + continue; + } + if (sounds[i]) { + sounds[i].stop(); + } + } + } + }; + + ion.sound.destroy = function (name) { + if (name && sounds[name]) { + sounds[name].destroy(); + sounds[name] = null; + } else { + for (i in sounds) { + if (!sounds.hasOwnProperty(i)) { + continue; + } + if (sounds[i]) { + sounds[i].destroy(); + sounds[i] = null; + } + } + } + }; + +} (ion));