npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mobile-ppt

v1.0.6

Published

商业项目现阶段使用的移动端 PPT 加载方式

Downloads

9

Readme

MobilePPT

商业项目现阶段使用的移动端 PPT 加载方式

如何安装

使用 npm(推荐)

npm install mobile-ppt --save

使用 $.getScript()

var js = 'http://assets.dxycdn.com/templates/core/third-party/mobile-ppt/mobile-ppt.min.js';
$.getScript(js, function () {
    // 此处可以使用 MobilePPT 了
});

使用方法

方式一:商业项目中

该模块针对商业项目作了一些封装,以便可以快捷的使用该模块。下面以使用 npm 安装的方式为例 来演示如何使用:

var $ = require('jquery');
var MobilePPT = require('mobile-ppt');
var flash = $('.post__content object'); // PC 端 PPT 的 flash 对象

var isMobile = /mobile|dxyapp/i.test(navigator.userAgent);

// 仅在移动端,并且存在 flash 对象时调用
if (isMobile && flash.length) {
    MobilePPT.init('biz', {
        flash: flash,
        dataUrlBuilder: function (nid) {
            return 'http://www.dxy.cn/topic/biz/cah-photoswipe/2015/' + nid + '/ps-data.js';
        }
    });
}

说明:

flash 表示 PC 端 flash 的对象,参数的值可以是 jQuery 的对象(如上面的代码),可以是 DOMElement 节点, 也可以是一个选择器(如:.post__content object)。

dataUrlBuilder 是一个自定义的方法,用来生成 ps-data.js 的路径。该方法的唯一一个参数是 nid,表示当前 文章的 id

方式二:其他项目中

该模块也可以应用于其他项目中,但是不能像在商业项目那样调用。可以用下面的方法进行调用,上面提到 的 Mobile.init 方法其实就是对下面这种调用方式的封装,目的是兼容商业项目中一些老的调用方法。

var $ = require('jquery');
var MobilePPT = require('mobile-ppt');

var nid = 1234;
var dataUrl = 'http://www.dxy.cn/topic/biz/cah-photoswipe/2015/' + nid + '/ps-data.js';
var container = $('.ppt-container');

var ppt = new MobilePPT(container, {
    dataUrl: dataUrl
});
ppt.init();

说明:

options 中,dataUrl 用来指定 ps_data.js 的地址,另外,该地址不一定是一个 JS 的地址,也可以是一个 JSONP 接口的地址。

限制

该模块对面上存在多个 PPT 的情况支持的不好,主要原因是 ps_data.js 中使用了同一个全局变量 PS_DATA。 但如果 dataUrl 的地址是 JSONP 接口的话,就可以使用方法二的方式来初始化多个 MobilePPT 的实例来 实现加载多个 PPT 的功能。

开发

  1. Clone 本项目
  2. npm install
  3. 修改之后运行 npm run build
  4. 将模块发布到 npm 并且将 dist/ 目录下面的 mobile-ppt.jsmobile-ppt.min.js 复制一份到 svn 的 assets/templates/core/third-party/mobile-ppt/ 目录下替换掉之前的文件。

CHANGELOG