IF / THEN咖啡脚本链接
IF / THEN coffee script links
我正在学习咖啡脚本…我有一些代码,默认为一个JS弹出-但我也想自定义一些邮件和其他内容的链接,并有JS默认只有当没有主方向
例如…如果用户点击请求管理权限,我想要一个邮件来弹出,而不是JS说"此功能尚未可用"
onPhotosLoaded = (sampledata) ->
if !sampledata || sampledata?.success == false
jvmw.empty().append('Gallery not found')
return
# once the photos are loaded
jvu.waitCss $("#jv_mw"), 'jv-colorbox-css-loaded', ->
$.colorbox.init()
jvmw.empty()
afterPhotosAndTags() # don't load tags before getting here.
email = "#{gal_code}@phto.us"
addMorePhotosInfoDiv = $ """<div/>"""
addMorePhotosButton = $ """<div style="float:left;font-size:32px"><br>Everyone's photos from "<span class="jvreplacewitheventname">this event</span>" <a class="jvaddmorephotosbutton" href="#">+Add yours!</a> <br/> </div>"""
addMorePhotosInfoDiv.append addMorePhotosButton
dragDropDiv = $ '<div class="jvdragzoneparent" />'
addMorePhotosInfoDiv.append(dragDropDiv).append('<div style="clear:both;" />')
extraTestButtons = $ '<div id="jvextratestbut" />'
extraTestButtons.append('<a href="mailto:adminplease@albumpl.us">Request Admin Privileges</a> | | <a href="#">Turn SMART BROWSE (ON)</a> | ' +
' | <a href="#">Purchase prints and other merchandise</a>|| <a href="http://www.albumpl.us/gallery/#{gal_code}/live">Live View</a>')
extraTestButtons.find('a').click ->
if $(this).text() == 'Request Admin Privileges'
# <a href="mailto:adminplease@albumpl.us">Request Admin Privileges</a>
return false
# default thing to do is show the dialog - and register the event.
showNotYetAvailableMessage($(this).text())
return false
extraTestButtons.find('a').click ->
if $(this).text() == 'Live View'
# <a href="http://www.albumpl.us/gallery/#{gal_code}
return false
# default thing to do is show the dialog - and register the event.
showNotYetAvailableMessage($(this).text())
return false
您使用了太多的缩进,更糟糕的是,您的注释与它们对应的代码的缩进不一致。这会使您的代码很难阅读,甚至可能会使编译器出错—特别是如果您同时使用制表符和空格(不要这样做!)。
代替当前
if $(this).text() == 'Request Admin Privileges'
# <a href="mailto:adminplease@albumpl.us">Request Admin Privileges</a>
return false
# default thing to do is show the dialog - and register the event.
showNotYetAvailableMessage($(this).text())
写
if $(this).text() == 'Request Admin Privileges'
return false
showNotYetAvailableMessage($(this).text())
,甚至使用CoffeeScript的后缀条件
return false if $(this).text() == 'Request Admin Privileges'
showNotYetAvailableMessage($(this).text())
哇…如果你选择咖啡,那就写它的风格。
使用它的缩进样式和一些字符,如'is', 'not'等。不要使用额外的语法
if $(this).text() is "Request Admin Privilegies"
return false
showNotYetAvailableMessage $(this).text()
尝试使用方法,一切都是表达式,它返回一些东西。它对……是有用的。别的,开关. .语句。
对于我来说,使用像
这样的样式$ "div"
是可怕的:),需要一些努力复制你的代码,例如到jquery论坛,如果你有一些问题。
另一个不好的jQuery方法是使用
$(@)
不是$(this)
咖啡好极了!正确使用它!
相关文章:
- 我发现了一些只在移动设备上可见的垃圾邮件链接,我可以'找不到包含此垃圾邮件链接的脚本的位置
- 什么's使用链接和脚本标记引用JavaScript源之间的区别
- Javascript:在新页面中打开链接并运行脚本
- 如何通过分配单个变量来减少此脚本中的链接数
- jQuery Pan & Zoom 或 Magnify 脚本,具有热点或图像映射链接的能力
- 是否有脚本/代码可以一次将链接属性添加到多个链接
- 阅读第'页;s从chrome扩展中链接的脚本
- 脚本链接格式以实现跨浏览器兼容性
- 用于浏览器检测和url链接的脚本
- Javascript一页滚动脚本滚动到每个点击的链接一个接一个
- 多个脚本导致链接问题?Javascript、CSS、HTML、Jquery
- 我想更改wordpress标题中的脚本链接.它们在哪里定义
- 在脚本链接标记中使用注释
- 脚本/链接标签与 AJAX 加载
- 如何在新窗口中打开脚本/链接
- 在IE8中单击时,Java脚本链接将消失
- CasperJS不能正确触发动态脚本/链接调用的回调
- 如何从Javascript脚本链接和执行PHP文件
- IF / THEN咖啡脚本链接
- OpenShift -部署的应用程序不会从头标签加载脚本/链接