Skip to content

Commit

Permalink
Merge pull request #1446 from lucasnetau/starRating
Browse files Browse the repository at this point in the history
Complete implementation of starRating
  • Loading branch information
kevinchappell authored Oct 14, 2023
2 parents 7475c35 + f34a259 commit 1c4bc4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
21 changes: 14 additions & 7 deletions src/js/control_plugins/starRating.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,32 @@ window.fbControls.push(function(controlClass) {
* javascript & css to load
*/
configure() {
this.js = '//cdnjs.cloudflare.com/ajax/libs/rateYo/2.2.0/jquery.rateyo.min.js'
this.css = '//cdnjs.cloudflare.com/ajax/libs/rateYo/2.2.0/jquery.rateyo.min.css'
this.js = 'https://cdnjs.cloudflare.com/ajax/libs/rateYo/2.3.2/jquery.rateyo.min.js'
this.css = 'https://cdnjs.cloudflare.com/ajax/libs/rateYo/2.3.2/jquery.rateyo.min.css'
}

/**
* build a text DOM element, supporting other jquery text form-control's
* @return {HTMLElement} DOM Element to be injected into the form.
* @return {HTMLElement|Object|HTMLElement[]} DOM Element to be injected into the form.
*/
build() {
this.dom = this.markup('span', null, { id: this.config.name })
return this.dom
this.input = this.markup('input', null, { ...this.config, type: 'hidden', })
this.field = this.markup('span')
return [this.input, this.field]
}

/**
* onRender callback
*/
onRender() {
const value = this.config.value || 3.6
$(this.dom).rateYo({ rating: value })
const value = this.config.userData ? this.config.userData[0] : this.config.value || 3.6
const input = $(this.input)
$(this.field).rateYo({
rating: value,
onSet: function(rating) {
input.val(rating)
}
})
}
}

Expand Down
6 changes: 4 additions & 2 deletions tests/control/control_plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ describe('Test Custom Control', () => {
expect(typeof controlInstance).toBe('object')
expect(controlInstance.constructor.name).toBe('controlStarRating')

const element = controlInstance.build()
expect(element.constructor.name).toBe('HTMLSpanElement')
const controlBuild = controlInstance.build()
const element = controlBuild[0]
expect(element.constructor.name).toBe('HTMLInputElement')
expect(element.id).toBe('star-1492424082853')
expect(element.type).toBe('hidden')
})
})

0 comments on commit 1c4bc4f

Please sign in to comment.