Commit 6c04da0d authored by neil.fraser@gmail.com's avatar neil.fraser@gmail.com

Fix sounds on iOS.

git-svn-id: http://blockly.googlecode.com/svn/trunk@1757 c400ca83-b69d-9dd7-9705-49c6b8615e23
parent d052fc5c
appengine/apple-touch-icon.png

3.89 KB | W: | H:

appengine/apple-touch-icon.png

3.93 KB | W: | H:

appengine/apple-touch-icon.png
appengine/apple-touch-icon.png
appengine/apple-touch-icon.png
appengine/apple-touch-icon.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -1231,7 +1231,7 @@ Blockly.onKeyDown_=function(a){if(!Blockly.isTargetInput_(a))if(27==a.keyCode)Bl ...@@ -1231,7 +1231,7 @@ Blockly.onKeyDown_=function(a){if(!Blockly.isTargetInput_(a))if(27==a.keyCode)Bl
Blockly.showContextMenu_=function(a){if(!Blockly.readOnly){var b=[];if(Blockly.collapse){for(var c=!1,d=!1,e=Blockly.mainWorkspace.getTopBlocks(!1),f=0;f<e.length;f++)for(var g=e[f];g;)g.isCollapsed()?c=!0:d=!0,g=g.getNextBlock();d={enabled:d};d.text=Blockly.Msg.COLLAPSE_ALL;d.callback=function(){for(var a=0,b=0;b<e.length;b++)for(var c=e[b];c;)setTimeout(c.setCollapsed.bind(c,!0),a),c=c.getNextBlock(),a+=10};b.push(d);c={enabled:c};c.text=Blockly.Msg.EXPAND_ALL;c.callback=function(){for(var a=0, Blockly.showContextMenu_=function(a){if(!Blockly.readOnly){var b=[];if(Blockly.collapse){for(var c=!1,d=!1,e=Blockly.mainWorkspace.getTopBlocks(!1),f=0;f<e.length;f++)for(var g=e[f];g;)g.isCollapsed()?c=!0:d=!0,g=g.getNextBlock();d={enabled:d};d.text=Blockly.Msg.COLLAPSE_ALL;d.callback=function(){for(var a=0,b=0;b<e.length;b++)for(var c=e[b];c;)setTimeout(c.setCollapsed.bind(c,!0),a),c=c.getNextBlock(),a+=10};b.push(d);c={enabled:c};c.text=Blockly.Msg.EXPAND_ALL;c.callback=function(){for(var a=0,
b=0;b<e.length;b++)for(var c=e[b];c;)setTimeout(c.setCollapsed.bind(c,!1),a),c=c.getNextBlock(),a+=10};b.push(c)}Blockly.ContextMenu.show(a,b)}};Blockly.onContextMenu_=function(a){Blockly.isTargetInput_(a)||a.preventDefault()};Blockly.hideChaff=function(a){Blockly.Tooltip.hide();Blockly.WidgetDiv.hide();!a&&Blockly.Toolbox.flyout_&&Blockly.Toolbox.flyout_.autoClose&&Blockly.Toolbox.clearSelection()}; b=0;b<e.length;b++)for(var c=e[b];c;)setTimeout(c.setCollapsed.bind(c,!1),a),c=c.getNextBlock(),a+=10};b.push(c)}Blockly.ContextMenu.show(a,b)}};Blockly.onContextMenu_=function(a){Blockly.isTargetInput_(a)||a.preventDefault()};Blockly.hideChaff=function(a){Blockly.Tooltip.hide();Blockly.WidgetDiv.hide();!a&&Blockly.Toolbox.flyout_&&Blockly.Toolbox.flyout_.autoClose&&Blockly.Toolbox.clearSelection()};
Blockly.removeAllRanges=function(){if(window.getSelection){var a=window.getSelection();a&&a.removeAllRanges&&(a.removeAllRanges(),window.setTimeout(function(){try{window.getSelection().removeAllRanges()}catch(a){}},0))}};Blockly.isTargetInput_=function(a){return"textarea"==a.target.type||"text"==a.target.type}; Blockly.removeAllRanges=function(){if(window.getSelection){var a=window.getSelection();a&&a.removeAllRanges&&(a.removeAllRanges(),window.setTimeout(function(){try{window.getSelection().removeAllRanges()}catch(a){}},0))}};Blockly.isTargetInput_=function(a){return"textarea"==a.target.type||"text"==a.target.type};
Blockly.loadAudio_=function(a,b){if(window.Audio&&a.length){for(var c,d=new window.Audio,e=0;e<a.length;e++){var f=a[e],g=f.match(/\.(\w+)$/);if(g&&d.canPlayType("audio/"+g[1])){c=new window.Audio(Blockly.pathToBlockly+f);break}}c&&c.play&&(Blockly.SOUNDS_[b]=c)}};Blockly.preloadAudio_=function(){for(var a in Blockly.SOUNDS_){var b=Blockly.SOUNDS_[a];b.volume=.01;b.play();b.pause()}}; Blockly.loadAudio_=function(a,b){if(window.Audio&&a.length){for(var c,d=new window.Audio,e=0;e<a.length;e++){var f=a[e],g=f.match(/\.(\w+)$/);if(g&&d.canPlayType("audio/"+g[1])){c=new window.Audio(Blockly.pathToBlockly+f);break}}c&&c.play&&(Blockly.SOUNDS_[b]=c)}};Blockly.preloadAudio_=function(){for(var a in Blockly.SOUNDS_){var b=Blockly.SOUNDS_[a];b.volume=.01;b.play();b.pause();if(goog.userAgent.IPAD||goog.userAgent.IPHONE)break}};
Blockly.playAudio=function(a,b){var c=Blockly.SOUNDS_[a];c&&(c=goog.userAgent.DOCUMENT_MODE&&9===goog.userAgent.DOCUMENT_MODE||goog.userAgent.IPAD||goog.userAgent.ANDROID?c:c.cloneNode(),c.volume=void 0===b?1:b,c.play())};Blockly.setCursorHand_=function(a){if(!Blockly.readOnly){var b="";a&&(b="url("+Blockly.pathToBlockly+"media/handclosed.cur) 7 3, auto");Blockly.selected&&(Blockly.selected.getSvgRoot().style.cursor=b);Blockly.svg.style.cursor=b}}; Blockly.playAudio=function(a,b){var c=Blockly.SOUNDS_[a];c&&(c=goog.userAgent.DOCUMENT_MODE&&9===goog.userAgent.DOCUMENT_MODE||goog.userAgent.IPAD||goog.userAgent.ANDROID?c:c.cloneNode(),c.volume=void 0===b?1:b,c.play())};Blockly.setCursorHand_=function(a){if(!Blockly.readOnly){var b="";a&&(b="url("+Blockly.pathToBlockly+"media/handclosed.cur) 7 3, auto");Blockly.selected&&(Blockly.selected.getSvgRoot().style.cursor=b);Blockly.svg.style.cursor=b}};
Blockly.getMainWorkspaceMetrics_=function(){var a=Blockly.svgSize();a.width-=Blockly.Toolbox.width;var b=a.width-Blockly.Scrollbar.scrollbarThickness,c=a.height-Blockly.Scrollbar.scrollbarThickness;try{var d=Blockly.mainWorkspace.getCanvas().getBBox()}catch(e){return null}if(Blockly.mainWorkspace.scrollbar)var f=Math.min(d.x-b/2,d.x+d.width-b),b=Math.max(d.x+d.width+b/2,d.x+b),g=Math.min(d.y-c/2,d.y+d.height-c),c=Math.max(d.y+d.height+c/2,d.y+c);else f=d.x,b=f+d.width,g=d.y,c=g+d.height;return{viewHeight:a.height, Blockly.getMainWorkspaceMetrics_=function(){var a=Blockly.svgSize();a.width-=Blockly.Toolbox.width;var b=a.width-Blockly.Scrollbar.scrollbarThickness,c=a.height-Blockly.Scrollbar.scrollbarThickness;try{var d=Blockly.mainWorkspace.getCanvas().getBBox()}catch(e){return null}if(Blockly.mainWorkspace.scrollbar)var f=Math.min(d.x-b/2,d.x+d.width-b),b=Math.max(d.x+d.width+b/2,d.x+b),g=Math.min(d.y-c/2,d.y+d.height-c),c=Math.max(d.y+d.height+c/2,d.y+c);else f=d.x,b=f+d.width,g=d.y,c=g+d.height;return{viewHeight:a.height,
viewWidth:a.width,contentHeight:c-g,contentWidth:b-f,viewTop:-Blockly.mainWorkspace.scrollY,viewLeft:-Blockly.mainWorkspace.scrollX,contentTop:g,contentLeft:f,absoluteTop:0,absoluteLeft:Blockly.RTL?0:Blockly.Toolbox.width}}; viewWidth:a.width,contentHeight:c-g,contentWidth:b-f,viewTop:-Blockly.mainWorkspace.scrollY,viewLeft:-Blockly.mainWorkspace.scrollX,contentTop:g,contentLeft:f,absoluteTop:0,absoluteLeft:Blockly.RTL?0:Blockly.Toolbox.width}};
......
...@@ -581,6 +581,11 @@ Blockly.preloadAudio_ = function() { ...@@ -581,6 +581,11 @@ Blockly.preloadAudio_ = function() {
sound.volume = .01; sound.volume = .01;
sound.play(); sound.play();
sound.pause(); sound.pause();
// iOS can only process one sound at a time. Trying to load more than one
// corrupts the earlier ones. Just load one and leave the others uncached.
if (goog.userAgent.IPAD || goog.userAgent.IPHONE) {
break;
}
} }
}; };
......
...@@ -162,11 +162,14 @@ Blockly.Blocks.addTemplate = function(details) { ...@@ -162,11 +162,14 @@ Blockly.Blocks.addTemplate = function(details) {
Blockly.Block.prototype.interpolateMsg.apply(this, interpArgs); Blockly.Block.prototype.interpolateMsg.apply(this, interpArgs);
}; };
// Create mutationToDom if needed.
if (details.switchable) { if (details.switchable) {
/**
* Create mutationToDom if needed.
* @this Blockly.Block
*/
block.mutationToDom = function() { block.mutationToDom = function() {
var container = details.mutationToDomFunc ? details.mutatationToDomFunc() var container = details.mutationToDomFunc ?
: document.createElement('mutation'); details.mutatationToDomFunc() : document.createElement('mutation');
container.setAttribute('is_statement', this['isStatement'] || false); container.setAttribute('is_statement', this['isStatement'] || false);
return container; return container;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment