This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| window.command = ''; | |
| function sendCommand(s) { | |
| window.command = s; | |
| location.href = 'crab://test'; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (BOOL)webView:(UIWebView *)webView | |
| shouldStartLoadWithRequest:(NSURLRequest *)request | |
| navigationType:(UIWebViewNavigationType)navigationType { | |
| NSURL * url = [request URL]; | |
| if ([[url scheme] isEqualToString:@"crab"]) { | |
| // 在这里做js调native的事情 | |
| // .... | |
| // 做完之后用如下方法调回js | |
| [webView stringByEvaluatingJavaScriptFromString:@"window.command"]; | |
| return NO; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function createListView(id) { | |
| var listView = $('<div>').addClass('list').click(function(e) { | |
| var $this = $(this), | |
| $target = $(e.target); | |
| if ($(e).is('li')) { | |
| $(e.target).addClass('selected'); | |
| } | |
| $.data($this, 'selected', $target.text()); | |
| }).keypress(function(e) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var ListView = Backbone.View.extend({ | |
| tagName: 'div', | |
| className: 'list', | |
| events: { | |
| 'click li': 'clickItem', | |
| 'keypress': 'deleteOnKeypress' | |
| }, | |
| clickItem: function(e) { | |
| var $target = $(e.target); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 没有依赖Backbone的History机制,而是调用Native命令实现页面切换, | |
| // 由Native来统一管理History。 | |
| $(document).on('click', 'a, .url', function(e) { | |
| e.preventDefault(); | |
| var pattern = /#!(.+)/, | |
| $this = $(this), | |
| href = $this.attr('href') || $.this.data('url'); | |
| if (href && href.match(pattern)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .center { | |
| top: 25%; | |
| text-align: center; | |
| } | |
| <h1>居中的标题</h1> | |
| h1 { | |
| .center; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getPerfStats() { | |
| var timing = window.performance.timing; | |
| return { | |
| dns: timing.domainLookupEnd - timing.domainLookupStart, | |
| connect: timing.connectEnd - timing.connectStart, | |
| ttfb: timing.responseStart - timing.connectEnd, | |
| basePage: timing.responseEnd - timing.responseStart, | |
| frontEnd: timing.loadEventStart - timing.responseEnd | |
| }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export CA_COLOR_OPAQUE=1 | |
| export CA_LOG_MEMORY_USAGE=1 | |
| /Applications/Safari.app/Contents/MacOS/Safari | |
| /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _.utils.api('baidu.ting.song.play', { | |
| songid: sid | |
| }, { | |
| expires: 0 | |
| }).done(function(r) { | |
| self._curSong = r; | |
| self.setUrl(r.bitrate.file_link); | |
| self.trigger('player:fetch', r); | |
| }).fail(function(r) { | |
| // TODO: server返回错误,之后要记录日志或重试 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Backbone.Router.extend(_.extend(redirectRouter, { | |
| routes: { | |
| '': 'index', | |
| 'search/:query/p:page': 'search', // #search/kiwi/p7 | |
| 'song/:id/': 'song' // #song/87336123/ | |
| // ... | |
| }, | |
| search: function(query, page) { |
OlderNewer