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

xpager

v0.0.1

Published

封装页面 JavaScript 代码逻辑, 负责页面生命周期管理, 统一管理事件

Downloads

9

Readme

xpager.js

用于封装[常规]页面 JavaScript 代码逻辑, 负责页面生命周期管理, 统一管理事件, 当前版本依赖 jQuery/Function.prototype.bind.

组件接口文档

  • inherits - 创建自定义 XPager 类, XPager.inherits(properties, [classProperties])
  • init - 如果定义了 init 函数, 当 XPager 实例化时该函数将被立即执行, 其参数为实例化 XPager 时, 传入的参数.
  • el - 所有 XPager 组件都拥有一个 DOM 元素(el 属性).
  • $ - jQuery 或 Zepto, 每个 XPager 都将拥有 $ 函数,可以在视图元素查询作用域内运行, 等价于运行: $(selector, this.el).
  • $el - DOM 元素 => jQuery (DOM 元素) 对象.
  • render - 默认为空函数, 重写该方法可以实现渲染相关视图模板, 推荐该方法总是 return this, 开启链式调用.
  • remove - 从 DOM 中移除视图, 等价于 $(view.el).remove().
  • delegateEvents - 采用 jQuery 的 delegate 函数来为视图内的 DOM 事件提供回调函数声明. 事件对象格式: {'event selector' : 'callback'}, 省略 selector 则事件被绑定到视图的根元素(this.el).

初始化组件

new XPager([options]),选项:

  • data {object|array} - 如果 XPager 组件进行初始化时需要数据, 可以通过外部传递 data, 组件内部可以通过 this.data 方式获取.
  • el {string} - 每一个 XPager 组件都拥有一个 DOM 元素(el 属性), this.el 根据 tagName, attributes, className, 以及 id 属性创建, 默认为一个空 div.
  • id {string} - 设置 XPager 组件 DOM 元素的 id.
  • attributes {object} - 设置 XPager 组件 DOM 元素的 attr.
  • className {string} - 设置 XPager 组件 DOM 元素的 class.
  • tagName {string} - 设置 XPager 组件 DOM 元素的 tag.

例子

var DemoPager = XPager.inherits({

    events: {
      'click .click': 'clickHandler',
      'click #clickId': 'clickHandler1'
    },

    render: function() {
      this.$el.append('<button id="clickId">DBClick</button>');
    },

    clickHandler: function(e) {
      console.log('=====> clickHandler');
    },

    clickHandler1: function(e) {
      console.log('=====> clickHandler1');
    }

  });

  var demoPager = new DemoPager({
    el: '.container'
  });
  demoPager.render();
var Pager = require('./pager');

var DemoPager = Pager.inherits({
  events: {
    'click .click': 'clickHandler',
    'click #clickId': 'clickHandler1'
  },

  render: function() {
    this.$el.append('<button id="clickId">DBClick</button>');
  },

  clickHandler: function(e) {
    console.log('=====> clickHandler');
  },

  clickHandler1: function(e) {
    console.log('=====> clickHandler1');
  }
});

var demoPager = new DemoPager({
  el: '#app'
});
demoPager.render();
import Pager from './pager';

const DemoPager = Pager.inherits({
  events: {
    'click .click': 'clickHandler',
    'click #clickId': 'clickHandler1'
  },

  render: function() {
    this.$el.append('<button id="clickId">DBClick</button>');
  },

  clickHandler: function(e) {
    console.log('=====> clickHandler');
  },

  clickHandler1: function(e) {
    console.log('=====> clickHandler1');
  }
});

const demoPager = new DemoPager({
  el: 'body'
});
demoPager.render();