Retrospring/app/javascript/packs/legacy/application.coffee

93 lines
2.5 KiB
CoffeeScript
Raw Normal View History

import 'core-js/stable'
import 'regenerator-runtime/runtime'
import './jquery'
import './bootstrap'
import {} from 'jquery-ujs'
import 'jquery.turbolinks/src/jquery.turbolinks'
import 'jquery.guillotine'
import 'particleground/jquery.particleground.min'
import 'jquery.growl'
2020-12-25 06:50:34 -08:00
import 'sweetalert'
import NProgress from 'nprogress'
import Cookies from 'js-cookie'
import moment from 'moment'
require('nprogress/nprogress.css')
require('jquery.growl/stylesheets/jquery.growl.css')
require('jquery.guillotine/css/jquery.guillotine.css')
require('sweetalert/dist/sweetalert.css')
2020-12-25 06:07:47 -08:00
# this file is generated by Rails
import I18n from './i18n'
import './answerbox'
import './questionbox'
import './inbox'
2020-12-25 06:38:38 -08:00
import './lists'
import './memes'
import './notifications'
import './pagination'
import './question'
import './settings'
import './user'
import './report'
import './locale-box'
import './util'
window.moment = moment
NProgress.configure
showSpinner: false
2014-11-10 09:19:04 -08:00
2015-06-08 07:49:47 -07:00
window.translate = (scope, options) ->
# for some reason I18n errors when calling it by assign proxy, so we got to wrap it
I18n.translate(scope, options)
2014-12-08 06:42:34 -08:00
window.showNotification = (text, success=true) ->
args =
2015-06-08 07:49:47 -07:00
title: translate((if success then 'frontend.success.title' else 'frontend.error.title'))
message: text
if success
$.growl.notice args
else
$.growl.error args
2014-11-11 09:02:59 -08:00
2015-06-08 07:49:47 -07:00
I18n.defaultLocale = 'en';
I18n.locale = Cookies.get('hl') || 'en';
window.showNotificationXHRError = (jqxhr, status, error) ->
console.log jqxhr, status, error
showNotification translate('frontend.error.message'), false
2014-11-10 09:19:04 -08:00
$(document).on "click", "button#create-account", ->
Turbolinks.visit "/sign_up"
_ready = ->
if typeof sweetAlertInitialize != "undefined"
sweetAlertInitialize()
if document.getElementById('particles')?
jumbo = $ '.j2-jumbo'
bodyColorOrig = jumbo.css 'background-color'
bodyColor = doppler 0.25, bodyColorOrig
console.log bodyColor, bodyColorOrig
particleground document.getElementById('particles'),
dotColor: bodyColor
lineColor: bodyColor
2015-09-20 06:16:24 -07:00
density: 23000
2015-05-12 14:53:42 -07:00
$(".announcement").each ->
2020-04-19 14:27:50 -07:00
aId = $(this)[0].dataset.announcementId
unless (window.localStorage.getItem("announcement#{aId}"))
$(this).toggleClass("d-none")
2020-04-19 14:27:50 -07:00
$(document).on "click", ".announcement button.close", (evt) ->
announcement = event.target.closest(".announcement")
2020-04-19 14:27:50 -07:00
aId = announcement.dataset.announcementId
window.localStorage.setItem("announcement#{aId}", true)
2015-06-13 07:53:11 -07:00
$(document).ready _ready
$(document).on 'page:load', _ready