mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
171 lines
5.2 KiB
TypeScript
171 lines
5.2 KiB
TypeScript
import {Directive, ElementRef, Renderer} from 'angular2/angular2';
|
|
import {Platform, Navbar} from 'ionic/ionic';
|
|
|
|
|
|
import * as actionSheets from './action-sheets/action-sheets';
|
|
import * as buttons from './buttons/buttons';
|
|
import * as cards from './cards/cards';
|
|
|
|
import {FormsPage,
|
|
FixedInlinePage,
|
|
FloatingPage,
|
|
InlinePage,
|
|
InsetPage,
|
|
PlaceholderPage,
|
|
StackedPage} from './forms/forms';
|
|
|
|
import {IconsPage} from './icons/icons';
|
|
|
|
import {CheckboxPage,
|
|
RadioPage,
|
|
RangePage,
|
|
SelectPage,
|
|
SwitchPage} from './inputs/inputs';
|
|
|
|
import {BasicListsPage,
|
|
AvatarListsPage,
|
|
IconListsPage,
|
|
BasicDividersPage,
|
|
BasicInsetListsPage,
|
|
ListHeadersPage,
|
|
MultilineListsPage,
|
|
ThumbnailListsPage} from './lists/lists';
|
|
|
|
import {MenusPage} from './menus/menus';
|
|
import {ModalsPage} from './modals/modals';
|
|
import {NavigationPage} from './navigation/navigation';
|
|
import {PopupsPage} from './popups/popups';
|
|
import {SlidesPage} from './slides/slides';
|
|
|
|
import {TabsPage} from './tabs/tabs';
|
|
import {TabsIconPage} from './tabs/tabs-icon';
|
|
import {TabsIconTextPage} from './tabs/tabs-icon-text';
|
|
|
|
|
|
@Directive({
|
|
selector: '.android-attr',
|
|
})
|
|
export class AndroidAttribute {
|
|
|
|
constructor (platform: Platform, elementRef: ElementRef, renderer: Renderer) {
|
|
this.isAndroid = platform.is('android');
|
|
renderer.setElementAttribute(elementRef, 'primary', this.isAndroid ? true : null);
|
|
}
|
|
|
|
}
|
|
|
|
export function toTitleCase(str) {
|
|
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
|
|
}
|
|
|
|
export function hasScrollbar() {
|
|
|
|
if (typeof window.top.innerWidth === 'number') {
|
|
return window.top.innerWidth > window.top.document.documentElement.clientWidth;
|
|
}
|
|
|
|
// rootElem for quirksmode
|
|
var rootElem = window.top.document.documentElement || window.top.document.body;
|
|
|
|
// Check overflow style property on body for fauxscrollbars
|
|
var overflowStyle;
|
|
|
|
if (typeof rootElem.currentStyle !== 'undefined') {
|
|
overflowStyle = rootElem.currentStyle.overflow;
|
|
}
|
|
|
|
overflowStyle = overflowStyle || window.top.getComputedStyle(rootElem, '').overflow;
|
|
|
|
// Also need to check the Y axis overflow
|
|
var overflowYStyle;
|
|
|
|
if (typeof rootElem.currentStyle !== 'undefined') {
|
|
overflowYStyle = rootElem.currentStyle.overflowY;
|
|
}
|
|
|
|
overflowYStyle = overflowYStyle || window.top.getComputedStyle(rootElem, '').overflowY;
|
|
|
|
var contentOverflows = rootElem.scrollHeight > rootElem.clientHeight;
|
|
var overflowShown = /^(visible|auto)$/.test(overflowStyle) || /^(visible|auto)$/.test(overflowYStyle);
|
|
var alwaysShowScroll = overflowStyle === 'scroll' || overflowYStyle === 'scroll';
|
|
|
|
return (contentOverflows && overflowShown) || (alwaysShowScroll)
|
|
}
|
|
|
|
export function getPageFor(hash) {
|
|
return {
|
|
'action-sheets': actionSheets.BasicPage,
|
|
|
|
'buttons': buttons.BasicPage,
|
|
'block-buttons': buttons.BlockPage,
|
|
'clear-buttons': buttons.ClearPage,
|
|
'full-buttons': buttons.FullPage,
|
|
'outline-buttons': buttons.OutlinePage,
|
|
'round-buttons': buttons.RoundPage,
|
|
'floating-action-buttons': buttons.FabPage,
|
|
'buttons-in-components': buttons.ComponentsPage,
|
|
'button-sizes': buttons.SizesPage,
|
|
'icon-buttons': buttons.IconsPage,
|
|
|
|
'cards': cards.BasicPage,
|
|
'card-header': cards.HeaderPage,
|
|
'card-list': cards.ListPage,
|
|
'card-image': cards.ImagePage,
|
|
'card-background': cards.BackgroundPage,
|
|
'advanced-cards': cards.AdvancedSocialPage,
|
|
'card-advanced-map': cards.AdvancedMapPage,
|
|
'card-advanced-social': cards.AdvancedSocialPage,
|
|
'card-advanced-weather': cards.AdvancedWeatherPage,
|
|
|
|
'checkbox': CheckboxPage,
|
|
'radio': RadioPage,
|
|
'range': RangePage,
|
|
'select': SelectPage,
|
|
'switch': SwitchPage,
|
|
|
|
'inputs': FormsPage,
|
|
'fixed-inline-labels': FixedInlinePage,
|
|
'floating-labels': FloatingPage,
|
|
'inline-labels': InlinePage,
|
|
'inset-labels': InsetPage,
|
|
'placeholder-labels': PlaceholderPage,
|
|
'stacked-labels': StackedPage,
|
|
|
|
'icons': IconsPage,
|
|
|
|
'lists': BasicListsPage,
|
|
'avatar-list': AvatarListsPage,
|
|
'icon-list': IconListsPage,
|
|
'list-dividers': BasicDividersPage,
|
|
'inset-list': BasicInsetListsPage,
|
|
'list-headers': ListHeadersPage,
|
|
'multiline-list': MultilineListsPage,
|
|
'thumbnail-list': ThumbnailListsPage,
|
|
|
|
'menus': MenusPage,
|
|
'modals': ModalsPage,
|
|
'navigation': NavigationPage,
|
|
'popups': PopupsPage,
|
|
'slides': SlidesPage,
|
|
|
|
'tabs': TabsPage,
|
|
'tabs-icon': TabsIconPage,
|
|
'tabs-icon-text': TabsIconTextPage,
|
|
}[hash]
|
|
}
|
|
|
|
export function debounce(func, wait, immediate) {
|
|
var timeout;
|
|
return function() {
|
|
var context = this, args = arguments;
|
|
var later = function() {
|
|
timeout = null;
|
|
if (!immediate) func.apply(context, args);
|
|
};
|
|
var callNow = immediate && !timeout;
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(later, wait);
|
|
if (callNow) func.apply(context, args);
|
|
};
|
|
};
|