1

I would like to use a jquery plugin inside a typescript page of my Aurelia SPA. This plugin is called morelines

Here is my current solution so far:

my typescript file: post.ts

import './jquery.morelines'
export class Post {
    attached() {
            $('.card__description--details').moreLines({
                linecount: 6,
                baseclass: 'b-description',
                basejsclass: 'js-description',
                classspecific: '_readmore',
                buttontxtmore: "",
                buttontxtless: "",
                animationspeed: 400
            });
    }
}

the plugin jquery.morelines.js

Code visible here on github

(function ( $ ) {
    $.fn.moreLines = function (options) {
      ...
    }
 }(jQuery));

my tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "sourceMap": true,
    "target": "es5",
    "module": "amd",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "moduleResolution": "node",
    "lib": ["es2017", "dom"],
    "baseUrl": "src"
  },
  "include": [
    "./src/**/*.ts",
    "./test/**/*.ts"
  ],
  "atom": {
    "rewriteTsconfig": false
  }
}

It works at runtime but I got errors when bundling ( au build)

enter image description here

enter image description here

How to get rid of these errors ? How to properly reference this javascript jquery plugin inside my typescript file ?

1

1 Answer 1

1

Ok I got it by simply adding a reference to my jquery plugin like below:

aurelia.json

"dependencies": [
    ...
    ...
    {
        "name": "jquery.morelines",
        "path": "../javascript",
        "main": "jquery.morelines",
        "deps": [
          "jquery"
        ]
    }
]

No need to add any import in my typescript page.

posts.ts

    ...
    (<any>$('.card__description--details')).moreLines({
      linecount: 6,
      baseclass: 'b-description',
      basejsclass: 'js-description',
      classspecific: '_readmore',
      buttontxtmore: "",
      buttontxtless: "",
      animationspeed: 400
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.