Skip to content

Commit

Permalink
Refactor JS
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Dec 26, 2015
1 parent 4ced1f4 commit 4b0c599
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 62 deletions.
23 changes: 23 additions & 0 deletions assets/js/src/__init.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

window.Itch = Itch =
version: '0.0.0'
is: (property, value) -> this.app.dataset[property] is value
app: do -> document.body

$ ->
Itch.context = ->
# get the context from the first class name of body
# https://github.com/TryGhost/Ghost/wiki/Context-aware-Filters-and-Helpers
className = document.body.className.split(' ')[0].split('-')[0]
if className is '' then 'error' else className

Itch.device = ->
w = window.innerWidth
h = window.innerHeight
return 'mobile' if (w <= 480)
return 'tablet' if (w <= 1024)
'desktop'

# jQuery.smartresize
`!function(n,r){var t;t=function(n,r,t){var i;return i=void 0,function(){var e,u,a;a=this,e=arguments,u=function(){t||n.apply(a,e),i=null},i?clearTimeout(i):t&&n.apply(a,e),i=setTimeout(u,r||100)}},jQuery.fn[r]=function(n){return n?this.bind("resize",t(n)):this.trigger(r)}}(jQuery,"smartresize");`
29 changes: 29 additions & 0 deletions assets/js/src/main.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

$(window).load ->

casperFullImg = do ->
$('img').each ->
contentWidth = $('.post-content').outerWidth()
# Width of the content
imageWidth = $(this)[0].naturalWidth
# Original image resolution
method = if imageWidth >= contentWidth then 'addClass' else 'removeClass'
$(this)[method] 'full-img'

$(window).smartresize casperFullImg

$ ->
el = Itch.app
el.dataset.page = Itch.context()
el.dataset.device = Itch.device()

$('.post-content').fitVids()

if Itch.is 'device', 'desktop'
$('a').not('[href*="mailto:"]').click ->
if this.href.indexOf(location.hostname) is -1
window.open $(this).attr 'href'
false
else
FastClick.attach el
62 changes: 0 additions & 62 deletions assets/js/src/main.js

This file was deleted.

0 comments on commit 4b0c599

Please sign in to comment.