Javascript错误Object函数没有方法'url'
Javascript error Object function has no method 'url'
我曾考虑将syte用作博客。我已经设置好了,但当我尝试使用侧面导航按钮时,我会收到以下javascript错误:
Object function (a,b){return new e.fn.init(a,b,h)} has no method 'url' [http://127.0.0.1:8000/static/js/components/links.js:15]
这里是links.js:
var $url;
function setupLinks() {
$('a').click(function(e) {
if (e.which == 2)
return;
e.preventDefault();
e.stopPropagation();
if (this.href == $url)
return;
var url = $.url(this.href.replace('/#!', ''));
$url = this.href;
if (this.id == 'home-link' && window.location.pathname == '/') {
$('#github-profile').remove();
$('#dribbble-profile').remove();
$('#twitter-profile').remove();
$('#instagram-profile').remove();
$('#lastfm-profile').remove();
$('.modal-backdrop').remove();
adjustSelection('home-link');
}
else if(this.id == 'instagram-link' && instagram_integration_enabled) {
$('#github-profile').remove();
$('#dribbble-profile').remove();
$('#twitter-profile').remove();
$('#lastfm-profile').remove();
$('.modal-backdrop').remove();
adjustSelection('instagram-link');
setupInstagram(this);
}
else if (twitter_integration_enabled && (url.attr('host') == 'twitter.com' || url.attr('host') == 'www.twitter.com')) {
$('#github-profile').remove();
$('#dribbble-profile').remove();
$('#instagram-profile').remove();
$('#lastfm-profile').remove();
$('.modal-backdrop').remove();
adjustSelection('twitter-link');
setupTwitter(url, this);
}
else if (github_integration_enabled && (url.attr('host') == 'github.com' || url.attr('host') == 'www.github.com')) {
$('#twitter-profile').remove();
$('#dribbble-profile').remove();
$('#instagram-profile').remove();
$('#lastfm-profile').remove();
$('.modal-backdrop').remove();
adjustSelection('github-link');
setupGithub(url, this);
}
else if (dribbble_integration_enabled && (url.attr('host') == 'dribbble.com' || url.attr('host') == 'www.dribbble.com')) {
$('#twitter-profile').remove();
$('#github-profile').remove();
$('#instagram-profile').remove();
$('#lastfm-profile').remove();
$('.modal-backdrop').remove();
adjustSelection('dribbble-link');
setupDribbble(url, this);
}
else if (lastfm_integration_enabled && (url.attr('host') == 'lastfm.com' || url.attr('host') == 'www.lastfm.com')) {
$('#twitter-profile').remove();
$('#github-profile').remove();
$('#dribbble-profile').remove();
$('#instagram-profile').remove();
$('.modal-backdrop').remove();
adjustSelection('lastfm-link');
setupLastfm(url, this);
}
else {
window.location = this.href;
}
});
}
function adjustSelection(el) {
$('.main-nav').children('li').removeClass('sel');
$('#' + el).parent().addClass('sel');
if (el == 'home-link')
$url = null;
}
这似乎是缺少javascript库的问题。Syte安装说明要求您在部署站点之前运行compress.py。它应该自动导入和压缩javascript库,但它似乎并没有这么做。这是压缩.py:
import os
import sys
import subprocess
import shlex
import traceback
path_to_here = os.path.abspath(os.path.dirname(__file__))
path_before_site = path_to_here[0:path_to_here.rfind('syte')]
sys.path.append(path_before_site)
os.environ['DJANGO_SETTINGS_MODULE'] = 'syte.settings'
from django.conf import settings
def compress_statics():
try:
#This won't work on windows.
subprocess.check_call(shlex.split('mkdir -p static/css static/js/min'))
except Exception:
print 'Make sure to create "syte > static > css" and "syte > static > js > min" before compressing statics.'
compress_styles()
compress_js()
def compress_styles():
less_path = 'static/less/styles.less'
css_path = 'static/css/'
try:
subprocess.check_call(shlex.split('lessc {0} {1}styles-{2}.min.css -yui-compress'
.format(less_path, css_path, settings.COMPRESS_REVISION_NUMBER)))
print 'CSS Styles Generated: styles-{0}.min.css'.format(settings.COMPRESS_REVISION_NUMBER)
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
stack_trace = traceback.format_exception(exc_type, exc_value, exc_traceback)
print stack_trace
def compress_js():
js_files = [
'libs/jquery.url.js',
'libs/require.js',
'libs/handlebars.js',
'libs/moment.min.js',
'libs/bootstrap-modal.js',
'libs/spin.min.js',
'libs/prettify.js',
'components/base.js',
'components/mobile.js',
'components/blog-posts.js',
'components/links.js',
]
if settings.TWITTER_INTEGRATION_ENABLED:
js_files.append('components/twitter.js')
if settings.GITHUB_INTEGRATION_ENABLED:
js_files.append('components/github.js')
if settings.DRIBBBLE_INTEGRATION_ENABLED:
js_files.append('components/dribbble.js')
if settings.INSTAGRAM_INTEGRATION_ENABLED:
js_files.append('components/instagram.js')
if settings.DISQUS_INTEGRATION_ENABLED:
js_files.append('components/disqus.js')
if settings.LASTFM_INTEGRATION_ENABLED:
js_files.append('components/lastfm.js')
combined = ''
for js in js_files:
f = open('static/js/' + js, 'r')
combined += f.read()
f.close()
f = open('static/js/combined.js', 'w')
f.write(combined)
f.close()
try:
subprocess.check_call(shlex.split('uglifyjs -o static/js/min/scripts-{0}.min.js static/js/combined.js'.format(settings.COMPRESS_REVISION_NUMBER)))
subprocess.check_call(shlex.split('rm -f static/js/combined.js'))
print 'JavaScript Combined and Minified: scripts-{0}.min.js'.format(settings.COMPRESS_REVISION_NUMBER)
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
stack_trace = traceback.format_exception(exc_type, exc_value, exc_traceback)
print stack_trace
if __name__ == "__main__":
compress_statics()
sys.exit()
我的javascript技能缺乏,所以任何帮助都将不胜感激!
您很可能没有在页面上包含依赖项,特别是jquery.url.js
包括所有列出的依赖关系,它应该起作用。
var url = $.url(this.href.replace('/#!', ''));
$.url不存在
问题是我在一个tumblr帖子中嵌入了javascript,这会造成干扰。删除了javascript,现在它被修复了。
相关文章:
- 如何使用javascript从同一浏览器下的其他页面获取URL?有可能吗
- 为什么dijit.form.Select有方法setStore(),而dijit.fform.FilteringSele
- Ajax 无法使用 jquery url post 方法
- 另一种在javascript中创建随机动态url的方法/阻止wpengine缓存
- 将长混合字符串变量从 javascript 传递到 GET url 变量的 url 友好方法是什么?
- 在没有表单的情况下将查询数据发布到 URL 的方法
- 任何检测用户何时高亮显示或复制全部/部分URL的方法
- JSPM-是否有方法或需要对捆绑文件进行版本化
- 在 Firefox 上,window.open(url) 和 window.location.href = url 有什
- Regex从文本中提取URL(有/没有协议和www或子域)
- 当用户试图删除indexedDB数据库时,是否有方法执行函数
- Box2dWeb中是否有方法将对象的位置.x输出到console.log()
- 如果url有特定的术语,比如/abc-def/usingjQuery,我必须删除特定的Cookie
- 内部问号或angularjs的url有问题
- 是否有方法在WebCrypto API中获取RSA密钥的组件
- 使用“破解”打开跨域URL的方法;window.show”;Javascript
- 是否有方法可以快速确定浏览器是否支持启用了cors的图像而不会污染浏览器?
- 在firefox中,在选项卡重定向之前获取URL的方法是什么
- 是否有方法以编程方式确定私钥是用DER还是PEM编码的?
- 在附加到webRequest事件时,是否有方法访问匹配的URL模式