我正在使用syte作爲博客。我已經設置它,但是當我嘗試使用側邊導航按鈕,我得到這個JavaScript錯誤:Javascript錯誤對象函數沒有方法'url'
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庫,但它似乎沒有這樣做。這裏是compress.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技能缺乏,所以任何幫助將不勝感激!
你已經明顯在Github上創建了一個問題:https://github.com/rigoneri/syte/issues/79。不要忘記評論該票是無效的。 – 2012-07-26 21:30:51
JavaScript庫應該是自動導入並通過compress.py縮小。在這種情況下,它似乎並沒有導入他們..錯誤? – HighLife 2012-07-26 21:33:34
通過閱讀源代碼(['compress.py'#L40](https://github.com/rigoneri/syte/blob/master/syte/compress.py#L40),['compress.py'#L72 -80](https://github.com/rigoneri/syte/blob/master/syte/compress.py#L72-80)),你可以看到所有的JS文件都被連接到'combine.js'中。還有幾行,文件被壓縮,臨時'combine.js'文件被刪除。這不是很好嗎? – 2012-07-26 21:38:13