スポンサー
Support Framework7

アプリ / コア

    アプリを初期化する際には、new Framework7 コンストラクタを使用し、アプリのメインパラメータを含むオブジェクトを渡します。

    var app = new Framework7({
      // アプリID
      id: 'com.myapp.test',
      // スワイプパネルの有効化
      panel: {
        swipe: true,
      },
      // ... その他のパラメータ
    });

    このコンストラクタは、メインアプリのFramework7インスタンスを返します。

    アプリのパラメータ

    利用可能なパラメータの一覧を見てみましょう。

    ParameterTypeDefaultDescription
    elstringbodyアプリのルート要素。メインアプリのレイアウトが <body> の直接の子でない場合は、ここでルート要素を指定する必要があります。
    componentRouter Componentパスされた メインアプリコンポーネントからアプリのレイアウトをロードします。Framework7 Coreバージョンのみ
    componentUrlstring ComponentXHRで読み込むシングルファイルメインアプリコンポーネントへのパスを指定します。Framework7 Coreバージョンのみ
    idstringio.framework7.testappアプリのバンドルID。
    namestringFramework7アプリの名前。例えば、Dialogコンポーネントのデフォルトタイトルとして、他のコンポーネントで使用することができます。
    versionstring1.0.0アプリのバージョン。他のコンポーネントでも使用可能。
    themestringautoアプリのテーマ。テーマは ios, md, aurora, auto のいずれかです。auto`の場合、iOSデバイスにはiOSテーマが、Electron環境で動作するデスクトップデバイスにはAuroraテーマが、その他のデバイスにはMDテーマが使われます。
    languagestringアプリの言語。他のコンポーネントで使用することができます。デフォルトでは、現在のブラウザ/ウェブビューの言語(つまり、navigator.language)と同じです。
    userAgentstringユーザーエージェントの文字列。サーバーサイド環境で使用する場合、デバイスを正しく検出するために必要です。
    routesarray[]すべてのビューへのデフォルトルートを持つ配列です。
    lazyModulesPathstringFramework7の遅延コンポーネントへのパスです。ブラウザモジュールで遅延モジュールを使用する際に必要です。
    autoDarkThemebooleanfalseユーザーシステムの配色設定に基づいて、自動的にダークテーマを有効にします。この機能のサポートは、(prefers-color-scheme) media query supportに基づいています。
    initbooleantrueデフォルトでは、new Framework7()を呼び出すと、Framework7が自動的に初期化されます。この動作を防ぎたい場合は、このオプションで無効にして、必要なときにapp.init()で手動で初期化することができます。
    initOnDeviceReadybooleantrue自動初期化が init: true パラメータで有効になっていて、アプリが cordova 環境で動作している場合は、deviceready イベントで初期化されます。
    iosTranslucentBarsbooleantrueiOS テーマのナビゲーションバーで半透明効果 (背景をぼかす) を有効にする (iOS デバイスの場合)
    iosTranslucentModalsbooleantrueiOS テーマでモーダル (Dialog, Popover, Actions) の半透明効果 (背景のぼかし) を有効にします (iOS デバイスの場合)。
    onobject{}

    イベントハンドラーを持つオブジェクト。例えば、以下のようなものです。

    var app = new Framework7({
      on: {
        init: function () {
          console.log('App initialized');
        },
        pageInit: function () {
          console.log('Page initialized');
        },
      }
    })
    Clicks Module Parameters
    clicksobjectclicks-module 関連のパラメータを持つオブジェクト。
    var app = new Framework7({
      clicks: {
        externalLinks: '.external',
      }
    })
    {
    externalLinksstring'.external'外部リンクとして扱われ、Framework7で処理されるべきでないリンクのためのCSSセレクタ。例えば、`(クラスが "external")のようなリンクには、'.external'の値がマッチします。
    }
    Touch Module Parameters
    touchobjectタッチモジュール関連のパラメータを持つオブジェクトです。
    var app = new Framework7({
      touch: {
        tapHold: true,
      }
    })
    {
    touchClicksDistanceThresholdnumber5短いスワイプを防ぐための距離のしきい値(px単位)。つまり、タップ/移動距離がこの値よりも大きい場合、「クリック」はトリガーされません。(fastClicksが無効の場合、タッチイベントにのみ使用されます)。
    disableContextMenubooleanfalseコンテキストメニューを無効にするには、trueを設定します(右クリックまたはタップ&ホールドで)。
    tapHoldbooleanfalseタップホールドを有効にする
    tapHoldDelaynumber750タップホールドイベントがターゲット要素で発生するまでのユーザーのタップ保持時間(ms)を決定します。
    tapHoldPreventClicksbooleantrue有効(デフォルト)にすると、タップホールドイベントの後、クリックイベントは発生しません。
    activeStatebooleantrue有効にすると、現在タッチされている(:active)要素に "active-state "クラスが追加されます。
    activeStateElementsstringa, button, label, span, .actions-button, .stepper-button, .stepper-button-plus, .stepper-button-minus, .card-expandable, .menu-item, .link, .item-link, .accordion-item-toggleactiveState "が有効な要素のCSSセレクタには、適切なactiveクラスが追加されます。
    activeStateOnMouseMovebooleanfalse有効にすると、マウスの移動時に "active state" を維持します。
    iosTouchRipplebooleanfalseiOSテーマのタッチリップル効果を有効にする
    mdTouchRipplebooleantrueMDテーマのタッチリップル効果を有効にする
    auroraTouchRipplebooleanfalseAuroraテーマのタッチリップル効果を有効にする
    touchRippleElementsstring.ripple, .link, .item-link, .list-button, .links-list a, .button, button, .input-clear-button, .dialog-button, .tab-link, .item-radio, .item-checkbox, .actions-button, .searchbar-disable-button, .fab a, .checkbox, .radio, .data-table .sortable-cell:not(.input-cell), .notification-close-button, .stepper-button, .stepper-button-minus, .stepper-button-plus, .menu-item-content, .list.accordion-list .accordion-item-toggleクリック時にタッチリップル効果を適用する要素のCSSセレクタ
    touchRippleInsetElementsstring.ripple-inset, .icon-only, .searchbar-disable-button, .input-clear-button, .notification-close-button, .md .navbar .link.backクリック時にインセットのタッチリップル効果を適用する要素のCSSセレクタ
    }
    serviceWorkerobjectサービスワーカーモジュールのパラメータを持つオブジェクトです。
    var app = new Framework7({
      serviceWorker: {
        path: './service-worker.js',
        scope: '/',
      }
    })
    {
    pathstringサービスワーカーファイルへのパス
    scopestringサービスワーカーのスコープへのパス
    }

    これらは、アプリコアモジュールのデフォルトのアプリパラメータです。

    JavaScript APIを持つ多くのコンポーネントは、コンポーネントという名前のプロパティを使って、このパラメータのリストを拡張することができます。例えば、Panelコンポーネントは、アプリのパラメータを panel プロパティで拡張し、Panel 固有のパラメータを受け入れます。

    var app = new Framework7({
      id: 'com.myapp.test',
      // Panelコンポーネントによって拡張されます。
      panel: {
        swipe: true,
        visibleBreakpoint: 1024,
      },
      // ダイアログコンポーネントによって拡張されます。
      dialog: {
        title: 'My App',
      },
      // Statusbarコンポーネントによって拡張されます。
      statusbar: {
        iosOverlaysWebview: true,
      },
    });

    アプリのメソッドとプロパティ

    返されたFramework7のインスタンス app には、たくさんの便利なプロパティやメソッドが含まれています。

    Properties
    app.idパラメータで渡されるアプリID
    app.nameパラメーターで渡されるアプリの名前
    app.versionアプリのバージョン
    app.routesアプリのルート
    app.languageアプリの言語
    app.elアプリルートの HTML 要素
    app.$elアプリのルートHTML要素を持つDom7インスタンス
    app.rtlアプリがRTLレイアウトであるかどうかを示すBooleanプロパティ
    app.theme現在のアプリのテーマを表す文字列です。mdiosaurora`のいずれかです。
    app.darkThemeダークテーマが有効であるかどうかを示すブール値のプロパティです。このプロパティは autoDarkTheme が有効な場合にのみ影響を与えます。
    app.widthアプリの幅 (px)
    app.heightアプリの高さ (px)
    app.leftアプリの左端のオフセット (px)
    app.topApp top offset in px
    app.initializedアプリが初期化されているかどうかを示すブール値のプロパティ
    app.$Dom7エイリアス
    app.paramsアプリのパラメータ
    app.supportサポートされている機能に関するプロパティを持つオブジェクトです。サポートのユーティリティーセクションを確認してください。
    app.deviceデバイスに関するプロパティを持つオブジェクト。Deviceのユーティリティーセクションをご覧ください。
    app.utilsいくつかの便利なユーティリティを持つオブジェクトです。Utilsセクションをご覧ください。
    app.requestXHR リクエストを処理するメソッドが含まれています。Requestのユーティリティーセクションをご覧ください。
    app.serviceWorker.registration登録されたサービスワーカーの配列
    app.onlineアプリの接続状態を示すブール値のプロパティです。(オンラインの場合は「true」となります。)
    Methods
    app.enableAutoDarkTheme()ダークテーマの自動検出を有効にする
    app.disableAutoDarkTheme()暗いテーマの自動検出を無効にする
    app.on(event, handler)イベントハンドラの追加
    app.once(event, handler)イベントハンドラーを追加します。このイベントハンドラーは起動後に削除されます。
    app.off(event, handler)イベントハンドラの削除
    app.off(event)指定したイベントのハンドラをすべて削除する
    app.emit(event, ...args)インスタンスでイベントを発生させる
    app.init()アプリを初期化します。init: false` パラメータで自動初期化を無効にしている場合は、アプリを初期化します。
    app.serviceWorker.register(path, scope)サービスワーカーを登録します。これは ServiceWorkerRegistration で解決される約束を返します。
    app.serviceWorker.unregister(registration)サービスワーカーの登録を解除します。サービスワーカーが登録解除されたときに解決されるプロミスを返します。

    アプリのパラメータと同様に、JavaScriptのAPIを持つコンポーネントの多くは、コンポーネントという名前のプロパティでこのプロパティリストを拡張することができます。例えば、Panel コンポーネントは、アプリのインスタンスプロパティを panel プロパティで拡張し、Panel 固有のプロパティやメソッドを受け入れます。

    // パネルを開く
    app.panel.open('left');
    
    // ステータスバーを隠す
    app.statusbar.hide();

    アプリのイベント

    アプリのインスタンスは、以下のコアイベントを発行します。

    EventArgumentsDescription
    initイベントはアプリの初期化時に発生します。自動的に new Framework7() の後、または自動初期化を無効にした場合は app.init() の後に発生します。
    resizeイベントはアプリのリサイズ(ウィンドウのリサイズ)時に発生します。
    orientationchangeアプリの向きが変わったとき(ウィンドウの向きが変わったとき)にイベントが発生します。
    click(event)アプリのクリックでイベントが発生します
    touchstart:active(event)touch start (mousedown) イベントをアクティブリスナーとして追加するとイベントが発生します(デフォルトでは発生しないようにすることも可能です)。
    touchmove:active(event)アクティブリスナーとして追加されたタッチ移動(mousemove)イベントでイベントが発生します(デフォルトでは防止できない可能性があります
    touchend:active(event)イベントは、アクティブリスナーとして追加されたタッチ終了(mouseup)イベントで発生します(デフォルトでは防止できない可能性があります
    touchstart:passive(event)パッシブリスナーとして追加されたタッチ開始(mousedown)イベントでイベントが発生する(デフォルトでは防止できない)
    touchmove:passive(event)イベントはパッシブリスナーとして追加されます(デフォルトでは防ぐことができません)。
    touchend:passive(event)イベントは、パッシブリスナーとして追加されたタッチ終了(mouseup)イベントで発生します(デフォルトでは防止できません
    serviceWorkerRegisterSuccess(registration)サービスワーカーの登録が完了するとイベントが発生する
    serviceWorkerRegisterError(error)サービスワーカーの登録が失敗したときにイベントが発生する
    serviceWorkerUnregisterSuccess(registration)サービスワーカーの登録解除が成功したときにイベントが発生する
    serviceWorkerUnregisterError(registration, error)サービスワーカーの登録解除が失敗したときにイベントが発生します
    onlineアプリがオンラインになったときにイベントが発生する
    offlineアプリがオフラインになるとイベントが発生する
    connection(isOnline)ネットワークの状態が変化するとイベントが発生する
    darkThemeChange(isDarkTheme)デバイスの優先カラースキームが変更されたときにイベントが発生します。autoDarkTheme`が有効な場合のみ効果があります。

    また、JavaScript APIを持つほとんどのコンポーネントは、このイベントリストを拡張することができます。例えば、Panelコンポーネントは、アプリのインスタンスで追加のイベントをトリガーします。

    app.on('panelOpen', function (panel) {
      console.log('Panel ' + panel.side + ' opened');
    });
    
    app.on('connection', function (isOnline) {
      if (isOnline) {
        console.log('app is online now')
      } else {
        console.log('app is offline now')
      }
    });
    
    app.on('darkThemeChange', function (isDark) {
      if (isDark) {
        console.log('color scheme changed to Dark')
      } else {
        console.log('color scheme changed to Light')
      }
    });
    

    CSS 変数

    :root {
      --f7-theme-color: #007aff;
      --f7-theme-color-rgb: 0, 122, 255;
      --f7-theme-color-shade: #0066d6;
      --f7-theme-color-tint: #298fff;
      --f7-safe-area-left: 0px;
      --f7-safe-area-right: 0px;
      --f7-safe-area-top: 0px;
      --f7-safe-area-bottom: 0px;
      --f7-safe-area-outer-left: 0px;
      --f7-safe-area-outer-right: 0px;
      --f7-device-pixel-ratio: 1;
    }
    @supports (left: env(safe-area-inset-left)) {
      :root {
        --f7-safe-area-top: env(safe-area-inset-top);
        --f7-safe-area-bottom: env(safe-area-inset-bottom);
      }
      :root .ios-left-edge,
      :root .ios-edges,
      :root .safe-area-left,
      :root .safe-areas,
      :root .popup,
      :root .sheet-modal,
      :root .panel-left {
        --f7-safe-area-left: env(safe-area-inset-left);
        --f7-safe-area-outer-left: env(safe-area-inset-left);
      }
      :root .ios-right-edge,
      :root .ios-edges,
      :root .safe-area-right,
      :root .safe-areas,
      :root .popup,
      :root .sheet-modal,
      :root .panel-right {
        --f7-safe-area-right: env(safe-area-inset-right);
        --f7-safe-area-outer-right: env(safe-area-inset-right);
      }
      :root .no-safe-areas,
      :root .no-safe-area-left,
      :root .no-ios-edges,
      :root .no-ios-left-edge {
        --f7-safe-area-left: 0px;
        --f7-safe-area-outer-left: 0px;
      }
      :root .no-safe-areas,
      :root .no-safe-area-right,
      :root .no-ios-edges,
      :root .no-ios-right-edge {
        --f7-safe-area-right: 0px;
        --f7-safe-area-outer-right: 0px;
      }
    }
    @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {
      :root {
        --f7-device-pixel-ratio: 2;
      }
    }
    @media (-webkit-min-device-pixel-ratio: 3), (min-resolution: 3dppx) {
      :root {
        --f7-device-pixel-ratio: 3;
      }
    }
    /*====================
      Fonts & Bars
      ==================== */
    :root {
      --f7-font-size: 14px;
      /*
      --f7-bars-link-color: var(--f7-theme-color);
      */
      --f7-bars-bg-image: none;
      --f7-bars-translucent-opacity: 0.8;
      --f7-bars-translucent-blur: 20px;
      --f7-bars-shadow-bottom-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0.08) 40%, rgba(0, 0, 0, 0.04) 50%, rgba(0, 0, 0, 0) 90%, rgba(0, 0, 0, 0) 100%);
      --f7-bars-shadow-top-image: linear-gradient(to top, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0.08) 40%, rgba(0, 0, 0, 0.04) 50%, rgba(0, 0, 0, 0) 90%, rgba(0, 0, 0, 0) 100%);
      --f7-bars-text-color: #000;
      --f7-bars-bg-color: #f7f7f8;
      --f7-bars-bg-color-rgb: 247, 247, 248;
    }
    :root .theme-dark,
    :root.theme-dark {
      --f7-bars-text-color: #fff;
    }
    .ios {
      --f7-font-family: -apple-system, SF Pro Text, SF UI Text, system-ui, Helvetica Neue, Helvetica, Arial, sans-serif;
      --f7-line-height: 1.4;
      --f7-text-color: #000;
      --f7-bars-border-color: rgba(0, 0, 0, 0.25);
    }
    .ios .theme-dark,
    .ios.theme-dark {
      --f7-text-color: #fff;
      --f7-bars-bg-color: #121212;
      --f7-bars-bg-color-rgb: 19, 19, 19;
      --f7-bars-border-color: rgba(255, 255, 255, 0.1);
    }
    .md {
      --f7-font-family: Roboto, system-ui, Noto, Helvetica, Arial, sans-serif;
      --f7-line-height: 1.5;
      --f7-bars-border-color: transparent;
      --f7-text-color: #212121;
    }
    .md .theme-dark,
    .md.theme-dark {
      --f7-text-color: rgba(255, 255, 255, 0.87);
      --f7-bars-bg-color: #202020;
    }
    .aurora {
      --f7-font-family: -apple-system, system-ui, Helvetica, Arial, sans-serif;
      --f7-line-height: 1.5;
      --f7-text-color: #000;
      --f7-bars-border-color: rgba(0, 0, 0, 0.2);
    }
    .aurora .theme-dark,
    .aurora.theme-dark {
      --f7-text-color: #fff;
      --f7-bars-bg-color: #202020;
      --f7-bars-border-color: rgba(255, 255, 255, 0.1);
    }