diff --git a/app/assets/javascripts/mobile.js b/app/assets/javascripts/mobile.js new file mode 100644 index 000000000..a4d84f44b --- /dev/null +++ b/app/assets/javascripts/mobile.js @@ -0,0 +1,16 @@ +// This is a manifest file that'll be compiled into including all the files listed below. +// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically +// be included in the compiled file accessible from http://example.com/assets/application.js +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// the compiled file. +// +//= require jquery +//= require lib/jquery.preload.min.js +//= require cycle2 +//= require mobile/jquery.mu.image.resize +//= require mobile/orbit.mobile +//= require mobile/jquery.mobile-1.2.0.min +//= require mobile/jquery.swipeplanes-1.2.min +//= require mobile/add2home +//= require mobile/gmAPI +//= require mobile/jquery.ui.map \ No newline at end of file diff --git a/app/assets/javascripts/mobile/add2home.js b/app/assets/javascripts/mobile/add2home.js new file mode 100644 index 000000000..38b35bfa1 --- /dev/null +++ b/app/assets/javascripts/mobile/add2home.js @@ -0,0 +1,350 @@ +/*! + * Add to Homescreen v2.0.4 ~ Copyright (c) 2012 Matteo Spinelli, http://cubiq.org + * Released under MIT license, http://cubiq.org/license + */ +var addToHome = (function (w) { + var nav = w.navigator, + isIDevice = 'platform' in nav && (/iphone|ipod|ipad/gi).test(nav.platform), + isIPad, + isRetina, + isSafari, + isStandalone, + OSVersion, + startX = 0, + startY = 0, + lastVisit = 0, + isExpired, + isSessionActive, + isReturningVisitor, + balloon, + overrideChecks, + + positionInterval, + closeTimeout, + + options = { + autostart: true, // Automatically open the balloon + returningVisitor: false, // Show the balloon to returning visitors only (setting this to true is HIGHLY RECCOMENDED) + animationIn: 'bubble', // drop || bubble || fade + animationOut: 'drop', // drop || bubble || fade + startDelay: 2000, // 2 seconds from page load before the balloon appears + lifespan: 10000, // 15 seconds before it is automatically destroyed + bottomOffset: 14, // Distance of the balloon from bottom + expire: 0, // Minutes to wait before showing the popup again (0 = always displayed) + message: '', // Customize your message or force a language ('' = automatic) + touchIcon: true, // Display the touch icon + arrow: true, // Display the balloon arrow + hookOnLoad: true, // Should we hook to onload event? (really advanced usage) + iterations: 100 // Internal/debug use + }, + + intl = { + ca_es: 'Per instal·lar aquesta aplicació al vostre %device premeu %icon i llavors Afegir a pantalla d\'inici.', + cs_cz: 'Pro instalaci aplikace na Váš %device, stiskněte %icon a v nabídce Přidat na plochu.', + da_dk: 'Tilføj denne side til din %device: tryk på %icon og derefter Føj til hjemmeskærm.', + de_de: 'Installieren Sie diese App auf Ihrem %device: %icon antippen und dann Zum Home-Bildschirm.', + el_gr: 'Εγκαταστήσετε αυτήν την Εφαρμογή στήν συσκευή σας %device: %icon μετά πατάτε Προσθήκη σε Αφετηρία.', + en_us: 'Install this web app on your %device: tap %icon and then Add to Home Screen.', + es_es: 'Para instalar esta app en su %device, pulse %icon y seleccione Añadir a pantalla de inicio.', + fi_fi: 'Asenna tämä web-sovellus laitteeseesi %device: paina %icon ja sen jälkeen valitse Lisää Koti-valikkoon.', + fr_fr: 'Ajoutez cette application sur votre %device en cliquant sur %icon, puis Ajouter à l\'écran d\'accueil.', + he_il: 'התקן אפליקציה זו על ה-%device שלך: הקש %icon ואז הוסף למסך הבית.', + hr_hr: 'Instaliraj ovu aplikaciju na svoj %device: klikni na %icon i odaberi Dodaj u početni zaslon.', + hu_hu: 'Telepítse ezt a web-alkalmazást az Ön %device-jára: nyomjon a %icon-ra majd a Főképernyőhöz adás gombra.', + it_it: 'Installa questa applicazione sul tuo %device: premi su %icon e poi Aggiungi a Home.', + ja_jp: 'このウェブアプリをあなたの%deviceにインストールするには%iconをタップしてホーム画面に追加を選んでください。', + ko_kr: '%device에 웹앱을 설치하려면 %icon을 터치 후 "홈화면에 추가"를 선택하세요', + nb_no: 'Installer denne appen på din %device: trykk på %icon og deretter Legg til på Hjem-skjerm', + nl_nl: 'Installeer deze webapp op uw %device: tik %icon en dan Zet in beginscherm.', + pl_pl: 'Aby zainstalować tę aplikacje na %device: naciśnij %icon a następnie Dodaj jako ikonę.', + pt_br: 'Instale este web app em seu %device: aperte %icon e selecione Adicionar à Tela Inicio.', + pt_pt: 'Para instalar esta aplicação no seu %device, prima o %icon e depois o Adicionar ao ecrã principal.', + ru_ru: 'Установите это веб-приложение на ваш %device: нажмите %icon, затем Добавить в «Домой».', + sv_se: 'Lägg till denna webbapplikation på din %device: tryck på %icon och därefter Lägg till på hemskärmen.', + th_th: 'ติดตั้งเว็บแอพฯ นี้บน %device ของคุณ: แตะ %icon และ เพิ่มที่หน้าจอโฮม', + tr_tr: '%device için bu uygulamayı kurduktan sonra %icon simgesine dokunarak Ana Ekrana Ekleyin.', + zh_cn: '您可以将此应用程式安装到您的 %device 上。请按 %icon 然后点选添加至主屏幕。', + zh_tw: '您可以將此應用程式安裝到您的 %device 上。請按 %icon 然後點選加入主畫面螢幕。' + }; + + function init () { + // Preliminary check, all further checks are performed on iDevices only + if ( !isIDevice ) return; + + var now = Date.now(), + i; + + // Merge local with global options + if ( w.addToHomeConfig ) { + for ( i in w.addToHomeConfig ) { + options[i] = w.addToHomeConfig[i]; + } + } + if ( !options.autostart ) options.hookOnLoad = false; + + isIPad = (/ipad/gi).test(nav.platform); + isRetina = w.devicePixelRatio && w.devicePixelRatio > 1; + isSafari = (/Safari/i).test(nav.appVersion) && !(/CriOS/i).test(nav.appVersion); + isStandalone = nav.standalone; + OSVersion = nav.appVersion.match(/OS (\d+_\d+)/i); + OSVersion = OSVersion[1] ? +OSVersion[1].replace('_', '.') : 0; + + lastVisit = +w.localStorage.getItem('addToHome'); + + isSessionActive = w.sessionStorage.getItem('addToHomeSession'); + isReturningVisitor = options.returningVisitor ? lastVisit && lastVisit + 28*24*60*60*1000 > now : true; + + if ( !lastVisit ) lastVisit = now; + + // If it is expired we need to reissue a new balloon + isExpired = isReturningVisitor && lastVisit <= now; + + if ( options.hookOnLoad ) w.addEventListener('load', loaded, false); + else if ( !options.hookOnLoad && options.autostart ) loaded(); + } + + function loaded () { + w.removeEventListener('load', loaded, false); + + if ( !isReturningVisitor ) w.localStorage.setItem('addToHome', Date.now()); + else if ( options.expire && isExpired ) w.localStorage.setItem('addToHome', Date.now() + options.expire * 60000); + + if ( !overrideChecks && ( !isSafari || !isExpired || isSessionActive || isStandalone || !isReturningVisitor ) ) return; + + var icons = options.touchIcon ? document.querySelectorAll('head link[rel=apple-touch-icon],head link[rel=apple-touch-icon-precomposed]') : [], + sizes, + touchIcon = '', + closeButton, + platform = nav.platform.split(' ')[0], + language = nav.language.replace('-', '_'), + i, l; + + balloon = document.createElement('div'); + balloon.id = 'addToHomeScreen'; + balloon.style.cssText += 'left:-9999px;-webkit-transition-property:-webkit-transform,opacity;-webkit-transition-duration:0;-webkit-transform:translate3d(0,0,0);position:' + (OSVersion < 5 ? 'absolute' : 'fixed'); + + // Localize message + if ( options.message in intl ) { // You may force a language despite the user's locale + language = options.message; + options.message = ''; + } + if ( options.message === '' ) { // We look for a suitable language (defaulted to en_us) + options.message = language in intl ? intl[language] : intl['en_us']; + } + + // Search for the apple-touch-icon + if ( icons.length ) { + for ( i = 0, l = icons.length; i < l; i++ ) { + sizes = icons[i].getAttribute('sizes'); + + if ( sizes ) { + if ( isRetina && sizes == '114x114' ) { + touchIcon = icons[i].href; + break; + } + } else { + touchIcon = icons[i].href; + } + } + + touchIcon = ''; + } + + balloon.className = (isIPad ? 'addToHomeIpad' : 'addToHomeIphone') + (touchIcon ? ' addToHomeWide' : ''); + balloon.innerHTML = touchIcon + + options.message.replace('%device', platform).replace('%icon', OSVersion >= 4.2 ? '' : '+') + + (options.arrow ? '' : '') + + '\u00D7'; + + document.body.appendChild(balloon); + + // Add the close action + closeButton = balloon.querySelector('.addToHomeClose'); + if ( closeButton ) closeButton.addEventListener('click', clicked, false); + + if ( !isIPad && OSVersion >= 6 ) window.addEventListener('orientationchange', orientationCheck, false); + + setTimeout(show, options.startDelay); + } + + function show () { + var duration, + iPadXShift = 208; + + // Set the initial position + if ( isIPad ) { + if ( OSVersion < 5 ) { + startY = w.scrollY; + startX = w.scrollX; + } else if ( OSVersion < 6 ) { + iPadXShift = 160; + } + + balloon.style.top = startY + options.bottomOffset + 'px'; + balloon.style.left = startX + iPadXShift - Math.round(balloon.offsetWidth / 2) + 'px'; + + switch ( options.animationIn ) { + case 'drop': + duration = '0.6s'; + balloon.style.webkitTransform = 'translate3d(0,' + -(w.scrollY + options.bottomOffset + balloon.offsetHeight) + 'px,0)'; + break; + case 'bubble': + duration = '0.6s'; + balloon.style.opacity = '0'; + balloon.style.webkitTransform = 'translate3d(0,' + (startY + 50) + 'px,0)'; + break; + default: + duration = '1s'; + balloon.style.opacity = '0'; + } + } else { + startY = w.innerHeight + w.scrollY; + + if ( OSVersion < 5 ) { + startX = Math.round((w.innerWidth - balloon.offsetWidth) / 2) + w.scrollX; + balloon.style.left = startX + 'px'; + balloon.style.top = startY - balloon.offsetHeight - options.bottomOffset + 'px'; + } else { + balloon.style.left = '50%'; + balloon.style.marginLeft = -Math.round(balloon.offsetWidth / 2) - ( w.orientation%180 && OSVersion >= 6 ? 40 : 0 ) + 'px'; + balloon.style.bottom = options.bottomOffset + 'px'; + } + + switch (options.animationIn) { + case 'drop': + duration = '1s'; + balloon.style.webkitTransform = 'translate3d(0,' + -(startY + options.bottomOffset) + 'px,0)'; + break; + case 'bubble': + duration = '0.6s'; + balloon.style.webkitTransform = 'translate3d(0,' + (balloon.offsetHeight + options.bottomOffset + 50) + 'px,0)'; + break; + default: + duration = '1s'; + balloon.style.opacity = '0'; + } + } + + balloon.offsetHeight; // repaint trick + balloon.style.webkitTransitionDuration = duration; + balloon.style.opacity = '1'; + balloon.style.webkitTransform = 'translate3d(0,0,0)'; + balloon.addEventListener('webkitTransitionEnd', transitionEnd, false); + + closeTimeout = setTimeout(close, options.lifespan); + } + + function manualShow (override) { + if ( !isIDevice || balloon ) return; + + overrideChecks = override; + loaded(); + } + + function close () { + clearInterval( positionInterval ); + clearTimeout( closeTimeout ); + closeTimeout = null; + + var posY = 0, + posX = 0, + opacity = '1', + duration = '0', + closeButton = balloon.querySelector('.addToHomeClose'); + + if ( closeButton ) closeButton.removeEventListener('click', close, false); + if ( !isIPad && OSVersion >= 6 ) window.removeEventListener('orientationchange', orientationCheck, false); + + if ( OSVersion < 5 ) { + posY = isIPad ? w.scrollY - startY : w.scrollY + w.innerHeight - startY; + posX = isIPad ? w.scrollX - startX : w.scrollX + Math.round((w.innerWidth - balloon.offsetWidth)/2) - startX; + } + + balloon.style.webkitTransitionProperty = '-webkit-transform,opacity'; + + switch ( options.animationOut ) { + case 'drop': + if ( isIPad ) { + duration = '0.4s'; + opacity = '0'; + posY = posY + 50; + } else { + duration = '0.6s'; + posY = posY + balloon.offsetHeight + options.bottomOffset + 50; + } + break; + case 'bubble': + if ( isIPad ) { + duration = '0.8s'; + posY = posY - balloon.offsetHeight - options.bottomOffset - 50; + } else { + duration = '0.4s'; + opacity = '0'; + posY = posY - 50; + } + break; + default: + duration = '0.8s'; + opacity = '0'; + } + + balloon.addEventListener('webkitTransitionEnd', transitionEnd, false); + balloon.style.opacity = opacity; + balloon.style.webkitTransitionDuration = duration; + balloon.style.webkitTransform = 'translate3d(' + posX + 'px,' + posY + 'px,0)'; + } + + + function clicked () { + w.sessionStorage.setItem('addToHomeSession', '1'); + isSessionActive = true; + close(); + } + + function transitionEnd () { + balloon.removeEventListener('webkitTransitionEnd', transitionEnd, false); + + balloon.style.webkitTransitionProperty = '-webkit-transform'; + balloon.style.webkitTransitionDuration = '0.2s'; + + // We reached the end! + if ( !closeTimeout ) { + balloon.parentNode.removeChild(balloon); + balloon = null; + return; + } + + // On iOS 4 we start checking the element position + if ( OSVersion < 5 && closeTimeout ) positionInterval = setInterval(setPosition, options.iterations); + } + + function setPosition () { + var matrix = new WebKitCSSMatrix(w.getComputedStyle(balloon, null).webkitTransform), + posY = isIPad ? w.scrollY - startY : w.scrollY + w.innerHeight - startY, + posX = isIPad ? w.scrollX - startX : w.scrollX + Math.round((w.innerWidth - balloon.offsetWidth) / 2) - startX; + + // Screen didn't move + if ( posY == matrix.m42 && posX == matrix.m41 ) return; + + balloon.style.webkitTransform = 'translate3d(' + posX + 'px,' + posY + 'px,0)'; + } + + // Clear local and session storages (this is useful primarily in development) + function reset () { + w.localStorage.removeItem('addToHome'); + w.sessionStorage.removeItem('addToHomeSession'); + } + + function orientationCheck () { + balloon.style.marginLeft = -Math.round(balloon.offsetWidth / 2) - ( w.orientation%180 && OSVersion >= 6 ? 40 : 0 ) + 'px'; + } + + // Bootstrap! + init(); + + return { + show: manualShow, + close: close, + reset: reset + }; +})(window); diff --git a/app/assets/javascripts/mobile/gmAPI.js b/app/assets/javascripts/mobile/gmAPI.js new file mode 100644 index 000000000..ab078c3af --- /dev/null +++ b/app/assets/javascripts/mobile/gmAPI.js @@ -0,0 +1,34 @@ + String.prototype.format = function() { a = this; for ( k in arguments ) { a = a.replace("{" + k + "}", arguments[k]); } return a; }; + window.gmAPI = { + 'version': '3.0-rc1', + 'ga': '', + 'primaryUrl': 'http://code.google.com/p/jquery-ui-map/', + 'url': 'http://jquery-ui-map.googlecode.com/', + 'forum': 'http://groups.google.com/group/jquery-ui-map-discuss/feed/rss_v2_0_msgs.xml', + 'subscribe': 'http://groups.google.com/group/jquery-ui-map-discuss/boxsubscribe', + 'exception': 'Unable to load due to either poor internet connection or some CDN\'s aren\'t as responsive as we would like them to be. Try refreshing the page :D.', + 'init': function() { + //window._gaq = [['_setAccount', this.ga], ['_trackPageview'], ['_trackPageLoadTime']]; + //Modernizr.load({ 'test': ( location.href.indexOf(this.url) > -1 ), 'yep': 'http://www.google-analytics.com/ga.js' }); + this.test('Backbone', function() { + $('#forum').append('
Benchmark case ' + i + '
' + t.desc + '
e||Math.abs(c.pageY-n)>e,o&&!d&&H("vmousecancel",b,f),H("vmousemove",b,f),F()}function M(a){if(r)return;C();var b=z(a.target),c;H("vmouseup",a,b);if(!o){var d=H("vclick",a,b);d&&d.isDefaultPrevented()&&(c=x(a).changedTouches[0],p.push({touchID:v,x:c.clientX,y:c.clientY}),q=!0)}H("vmouseout",a,b),o=!1,F()}function N(b){var c=a.data(b,e),d;if(c)for(d in c)if(c[d])return!0;return!1}function O(){}function P(b){var c=b.substr(1);return{setup:function(d,f){N(this)||a.data(this,e,{});var g=a.data(this,e);g[b]=!0,k[b]=(k[b]||0)+1,k[b]===1&&t.bind(c,I),a(this).bind(c,O),s&&(k.touchstart=(k.touchstart||0)+1,k.touchstart===1&&t.bind("touchstart",J).bind("touchend",M).bind("touchmove",L).bind("scroll",K))},teardown:function(d,f){--k[b],k[b]||t.unbind(c,I),s&&(--k.touchstart,k.touchstart||t.unbind("touchstart",J).unbind("touchmove",L).unbind("touchend",M).unbind("scroll",K));var g=a(this),h=a.data(this,e);h&&(h[b]=!1),g.unbind(c,O),N(this)||g.removeData(e)}}}var e="virtualMouseBindings",f="virtualTouchID",g="vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split(" "),h="clientX clientY pageX pageY screenX screenY".split(" "),i=a.event.mouseHooks?a.event.mouseHooks.props:[],j=a.event.props.concat(i),k={},l=0,m=0,n=0,o=!1,p=[],q=!1,r=!1,s="addEventListener"in c,t=a(c),u=1,v=0,w;a.vmouse={moveDistanceThreshold:10,clickDistanceThreshold:10,resetTimerDuration:1500};for(var Q=0;Q