當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript is.object方法代碼示例

本文整理匯總了TypeScript中@interactjs/utils.is.object方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript is.object方法的具體用法?TypeScript is.object怎麽用?TypeScript is.object使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@interactjs/utils.is的用法示例。


在下文中一共展示了is.object方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: off

function off (type, listener, options) {
  if (utils.is.string(type) && type.search(' ') !== -1) {
    type = type.trim().split(/ +/)
  }

  if (utils.is.array(type)) {
    for (const eventType of type) {
      interact.off(eventType, listener, options)
    }

    return interact
  }

  if (utils.is.object(type)) {
    for (const prop in type) {
      interact.off(prop, type[prop], listener)
    }

    return interact
  }

  if (!utils.arr.contains(scope.actions.eventTypes, type)) {
    events.remove(scope.document, type, listener, options)
  }
  else {
    let index

    if (type in globalEvents &&
        (index = globalEvents[type].indexOf(listener)) !== -1) {
      globalEvents[type].splice(index, 1)
    }
  }

  return interact
}
開發者ID:taye,項目名稱:interact.js,代碼行數:35,代碼來源:interact.ts

示例2: resizable

function resizable (interactable: Interact.Interactable, options: Interact.OrBoolean<Interact.ResizableOptions> | boolean, scope: Scope) {
  if (utils.is.object(options)) {
    interactable.options.resize.enabled = options.enabled !== false
    interactable.setPerAction('resize', options)
    interactable.setOnEvents('resize', options)

    if (utils.is.string(options.axis) && /^x$|^y$|^xy$/.test(options.axis)) {
      interactable.options.resize.axis = options.axis
    }
    else if (options.axis === null) {
      interactable.options.resize.axis = scope.defaults.actions.resize.axis
    }

    if (utils.is.bool(options.preserveAspectRatio)) {
      interactable.options.resize.preserveAspectRatio = options.preserveAspectRatio
    }
    else if (utils.is.bool(options.square)) {
      interactable.options.resize.square = options.square
    }

    return interactable
  }
  if (utils.is.bool(options)) {
    interactable.options.resize.enabled = options

    return interactable
  }
  return interactable.options.resize
}
開發者ID:taye,項目名稱:interact.js,代碼行數:29,代碼來源:resize.ts

示例3: dropzoneMethod

function dropzoneMethod (interactable: Interact.Interactable, options?: Interact.DropzoneOptions | boolean) {
  if (utils.is.object(options)) {
    interactable.options.drop.enabled = options.enabled !== false

    if (options.listeners) {
      const normalized = utils.normalizeListeners(options.listeners)
      // rename 'drop' to '' as it will be prefixed with 'drop'
      const corrected = Object.keys(normalized).reduce((acc, type) => {
        const correctedType = /^(enter|leave)/.test(type)
          ? `drag${type}`
          : /^(activate|deactivate|move)/.test(type)
            ? `drop${type}`
            : type

        acc[correctedType] = normalized[type]

        return acc
      }, {})

      interactable.off(interactable.options.drop.listeners)
      interactable.on(corrected)
      interactable.options.drop.listeners = corrected
    }

    if (utils.is.func(options.ondrop)) { interactable.on('drop', options.ondrop) }
    if (utils.is.func(options.ondropactivate)) { interactable.on('dropactivate', options.ondropactivate) }
    if (utils.is.func(options.ondropdeactivate)) { interactable.on('dropdeactivate', options.ondropdeactivate) }
    if (utils.is.func(options.ondragenter)) { interactable.on('dragenter', options.ondragenter) }
    if (utils.is.func(options.ondragleave)) { interactable.on('dragleave', options.ondragleave) }
    if (utils.is.func(options.ondropmove)) { interactable.on('dropmove', options.ondropmove) }

    if (/^(pointer|center)$/.test(options.overlap as string)) {
      interactable.options.drop.overlap = options.overlap
    }
    else if (utils.is.number(options.overlap)) {
      interactable.options.drop.overlap = Math.max(Math.min(1, options.overlap), 0)
    }
    if ('accept' in options) {
      interactable.options.drop.accept = options.accept
    }
    if ('checker' in options) {
      interactable.options.drop.checker = options.checker
    }

    return interactable
  }

  if (utils.is.bool(options)) {
    interactable.options.drop.enabled = options

    return interactable
  }

  return interactable.options.drop
}
開發者ID:taye,項目名稱:interact.js,代碼行數:55,代碼來源:index.ts

示例4: uniqueProps

export function uniqueProps (obj) {
  for (const prop in obj) {
    if (!obj.hasOwnProperty(prop)) { continue }

    if (utils.is.object(obj)) {
      uniqueProps(obj[prop])
    }
    else {
      obj[prop] = (counter++)
    }
  }
}
開發者ID:taye,項目名稱:interact.js,代碼行數:12,代碼來源:_helpers.ts

示例5: function

  Interactable.prototype.gesturable = function (this: Interact.Interactable, options: Interact.GesturableOptions | boolean) {
    if (utils.is.object(options)) {
      this.options.gesture.enabled = options.enabled !== false
      this.setPerAction('gesture', options)
      this.setOnEvents('gesture', options)

      return this
    }

    if (utils.is.bool(options)) {
      this.options.gesture.enabled = options

      return this
    }

    return this.options.gesture as Interact.Options
  } as GesturableMethod
開發者ID:taye,項目名稱:interact.js,代碼行數:17,代碼來源:gesture.ts

示例6: on

function on (type: string | Interact.EventTypes, listener: Interact.ListenersArg, options?) {
  if (utils.is.string(type) && type.search(' ') !== -1) {
    type = type.trim().split(/ +/)
  }

  if (utils.is.array(type)) {
    for (const eventType of (type as any[])) {
      interact.on(eventType, listener, options)
    }

    return interact
  }

  if (utils.is.object(type)) {
    for (const prop in type) {
      interact.on(prop, (type as Interact.EventTypes)[prop], listener)
    }

    return interact
  }

  // if it is an InteractEvent type, add listener to globalEvents
  if (utils.arr.contains(scope.actions.eventTypes, type)) {
    // if this type of event was never bound
    if (!globalEvents[type]) {
      globalEvents[type] = [listener]
    }
    else {
      globalEvents[type].push(listener)
    }
  }
  // If non InteractEvent type, addEventListener to document
  else {
    events.add(scope.document, type, listener as Interact.Listener, { options })
  }

  return interact
}
開發者ID:taye,項目名稱:interact.js,代碼行數:38,代碼來源:interact.ts

示例7: test

test('modifiers/base', (t) => {
  const {
    scope,
    target,
    interaction,
    interactable,
  } = helpers.testEnv({ plugins: [modifiersBase] })

  scope.actions.eventTypes.push('TESTstart', 'TESTmove', 'TESTend')

  t.ok(utils.is.object(interaction.modifiers), 'modifiers prop is added new Interaction')

  const element = target as Element
  const startEvent = {
    pageX: 100,
    pageY: 200,
    clientX: 100,
    clientY: 200,
    target: element,
  } as any
  const moveEvent = {
    pageX: 400,
    pageY: 500,
    clientX: 400,
    clientY: 500,
    target: element,
  } as any
  const options: any = { target: { x: 100, y: 100 }, setStart: true }
  let firedEvents = []

  interactable.rectChecker(() => ({ top: 0, left: 0, bottom: 50, right: 50 }))
  interactable.on('TESTstart TESTmove TESTend', (event) => firedEvents.push(event))
  interaction.pointerDown(startEvent, startEvent, element)

  interactable.options.TEST = {
    enabled: true,
    modifiers: [
      {
        options,
        methods: targetModifier,
      },
    ],
  }

  interaction.start({ name: 'TEST' }, interactable, element)

  t.ok(
    options.started,
    'modifier methods.start() was called',
  )

  t.ok(
    options.setted,
    'modifier methods.set() was called',
  )

  t.deepEqual(
    interaction.prevEvent.page,
    options.target,
    'start event coords are modified')

  t.deepEqual(
    interaction.coords.start.page,
    { x: 100, y: 200 },
    'interaction.coords.start are restored after action start phase')

  t.deepEqual(
    interaction.coords.cur.page,
    { x: 100, y: 200 },
    'interaction.coords.cur are restored after action start phase')

  interaction.pointerMove(moveEvent, moveEvent, element)

  t.deepEqual(
    interaction.coords.cur.page,
    { x: moveEvent.pageX, y: moveEvent.pageY },
    'interaction.coords.cur are restored after action move phase')

  t.deepEqual(
    interaction.coords.start.page,
    { x: startEvent.pageX, y: startEvent.pageY },
    'interaction.coords.start are restored after action move phase')

  t.deepEqual(
    { x: interaction.prevEvent.x0, y: interaction.prevEvent.y0 },
    { x: 100, y: 100 },
    'move event start coords are modified')

  firedEvents = []
  const similarMoveEvent = { ...moveEvent, pageX: moveEvent.pageX + 0.5 }
  interaction.pointerMove(similarMoveEvent, similarMoveEvent, element)
  t.equal(firedEvents.length, 0, 'duplicate result coords are ignored')

  interaction.stop()

  t.ok(
    options.stopped,
    'modifier methods.stop() was called',
  )

//.........這裏部分代碼省略.........
開發者ID:taye,項目名稱:interact.js,代碼行數:101,代碼來源:base.spec.ts

示例8: checkResizeEdge

    interactable: Interact.Interactable,
    element: Element,
    interaction: Interaction,
    rect: Interact.Rect
  ) {
    if (!rect) { return null }

    const page = utils.extend({}, interaction.coords.cur.page)
    const options = interactable.options

    if (options.resize.enabled) {
      const resizeOptions = options.resize
      const resizeEdges: { [edge: string]: boolean } = { left: false, right: false, top: false, bottom: false }

      // if using resize.edges
      if (utils.is.object(resizeOptions.edges)) {
        for (const edge in resizeEdges) {
          resizeEdges[edge] = checkResizeEdge(edge,
            resizeOptions.edges[edge],
            page,
            interaction._latestPointer.eventTarget,
            element,
            rect,
            resizeOptions.margin || this.defaultMargin)
        }

        resizeEdges.left = resizeEdges.left && !resizeEdges.right
        resizeEdges.top  = resizeEdges.top  && !resizeEdges.bottom

        if (resizeEdges.left || resizeEdges.right || resizeEdges.top || resizeEdges.bottom) {
          return {
開發者ID:taye,項目名稱:interact.js,代碼行數:31,代碼來源:resize.ts


注:本文中的@interactjs/utils.is.object方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。