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

shooting-star

v2.2.1

Published

ApostropheCMS Star Rating Field

Downloads

3

Readme

Shooting-Star ApostropheCMS Schema :star2: :star2: :star2: :star: :star:

Build Status

An ApostropheCMS Custom Schema for your own shooting star (Rating) field.

Shooting Star Example

Install

From within your apostrophe project npm install --save shooting-star

Include in app.js:

// In app.js
  modules: {
    'shooting-star': {},
    // ... other modules
}

Enable Shooting Star Schema

Simple :

addFields : [
    {
        type : 'shooting-star',
        name : 'rating',
        label : 'Rate Your Picture'
    }
]

Widget.html Get shooting-star Value

This shooting-star schema returns an object.

{
    priority : '<low|medium|high>',
    value : '<float value>'
}

If you did an example above , in widget.html you can simply get an object like this :

{{ data.widget.rating.priority }}
{{ data.widget.rating.value }}

or you can simply use apos.log() to see what's available on shooting-star objects :

{{ apos.log(data.widget.rating) }}

How priority works and what does it for ?

For example , let say we have 5 stars in total. But we have 3 rates available which is low , medium and high. Each star will be divided on each rates available so that you can use your nunjucks grouping each element OR you can put some inline style css on each rate. For example

<div style="{% if data.widget.rating.priority === 'medium' %}width : 66.67%;{% elif  data.widget.rating.priority === 'high' %}width : 100%;{% endif %}">

Shooting Star Options Available

// in lib/modules/shooting-star/index.js
module.exports = {
    star : {
        size : "<Number or String>", // Star Size - Default : 30px
        color : "<String>", // Star Base Color - Default : #ddd
        highlightColor : "<String>", // Star Color when Click - Default : #FFD700
        hoverColor : "<String>" // Star Color when Hover - Default : #FFED85
        total : "<Number>" // Total Number Of Stars - Default : 5
    }
}

How to Override/Change Existing Rate Tooltip ?

Easy , make sure the name of the rate is similar to default rate. Here is the default rate & tooltip(Mouse Hover Tooltip) :

// In lib/modules/shooting-star/index.js
module.exports = {
    star : {
        tooltip : [
            {
                rate: "low",
                value: "Low - $ Star"
            }, {
                rate: "medium",
                value: "Medium - $ Star"
            }, {
                rate: "high",
                value: "High - $ Star"
            }
        ]
    }
}

Once Hover your mouse on stars , you will see the tooltip :smile:

What is '$' sign available in tooltip.value ?

That is my friend , is a value of star replace with that dollar sign . When ever you hover on each stars available , the number will be shown on that tooltip. If not, it will not show the number when hover. :wink:

Specific Field Customization

What if I want to customize differently on each fields ? I don't want every styles apply TO ALL. How can I make different number of stars on each field ? Well , I figured you might say that. Here's the override technique . Let say you want your second field to have 10 stars available instead of default 5 :

addFields : [
    // Output default options
    {
        type : 'shooting-star',
        name : 'firstStar',
        label : "Rate your first star"
    },
    // Output additional options and merge with default
    {
        type : 'shooting-star',
        name : 'secondStar',
        label : "Rate your second customized star",
        star : {
            total : 10,
            size : "50px"
        }
    }
]

Your secondStar will produce 10 stars and 50px size of that star instead of 5 stars and 30px size. Awesome right ? No need to scratch your head :laughing:

You only can customized on specific field with these options only :

    {
        type : 'shooting-star',
        name : 'secondStar',
        label : "Rate your second customized star",
        star : {
            size : "<Number or String>", // Star Size - Default : 30px
            color : "<String>", // Star Base Color - Default : #ddd
            highlightColor : "<String>", // Star Color when Click - Default : #FFD700
            hoverColor : "<String>" // Star Color when Hover - Default : #FFED85
            total : "<Number>" // Total Number Of Stars - Default : 5
        }
    }

WARNING : You cannot add tooltip here. Make your tooltip inside project level module which is lib/modules/shooting-star/index.js

Browser

Browser Object

How can I get this schema browser object for my shooting-star ?

Simply you can find it on :

apos.shootingStar

Get Star Browser Options

You can get it via browser scripting

apos.shootingStar.star

Get Multiple Star Browser Options in Single Schema

Oops ! How can I get specific Star browser options object if I have two fields in a same schema ? I made a simple for you , let say you have this fields :

addFields : [
    {
        type : 'shooting-star',
        name : 'firstStar',
        label : 'Rate Your First Picture'
    },
    {
        type : 'shooting-star',
        name : 'secondStar',
        label : 'Rate Your Second Picture'
    }
]

Next, simply get the name property to get specific schema in browser object :

// First Editor
apos.shootingStar.firstStar.star

// Second Editor
apos.shootingStar.secondStar.star

Easy right ? Hell yeah it is ! :laughing:

Changelog

2.2.1

  • Add Unit Tests.
  • Adjust README with build tests link.

2.2.0

  • Fixed for click star issue on both mode whether they have apostrophe-workflow or not in the project. If they do not have, well . Use normal get checked attribute on radio button input.

2.0.0

  • Fixed for workflow problem that contains two type of fields. Live & Draft mode. Now you can see the UI changes beautifully when you change your mode.

1.0.4

  • README Changed and adjusted codes to minimize it.

1.0.3

  • Fixed when on browser Edge cannot automatically checked the input by using jQuery. Therefore, use oldschool technique where .checked attribute is use to set a boolean value on it.
  • README Changed