本文整理汇总了Python中gluon.html.SCRIPT属性的典型用法代码示例。如果您正苦于以下问题:Python html.SCRIPT属性的具体用法?Python html.SCRIPT怎么用?Python html.SCRIPT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类gluon.html
的用法示例。
在下文中一共展示了html.SCRIPT属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fast_tz_detector
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SCRIPT [as 别名]
def fast_tz_detector():
current.response.files.append(URL('static', 'plugin_timezone/jstz.min.js'))
##//cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.4/jstz.min.js
script = """
jQuery(document).on('plugin_timezone.fast_tz_detector', function (e) {
var tz = jstz.determine();
if (typeof (tz) !== 'undefined') {
var name = tz.name()
jQuery.post('%s', {timezone : name});
}
});
jQuery(document).ready(function () {
jQuery(this).trigger('plugin_timezone.fast_tz_detector');
});
""" % URL()
if current.request.post_vars.timezone:
if current.request.post_vars.timezone in TZDICT:
if not current.session.plugin_timezone_tz:
current.session.plugin_timezone_tz = current.request.post_vars.timezone
return SCRIPT(script)
示例2: test_SCRIPT
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SCRIPT [as 别名]
def test_SCRIPT(self):
self.assertEqual(SCRIPT('<>', _a='1', _b='2').xml(),
'''<script a="1" b="2"><!--
<>
//--></script>''')
self.assertEqual(SCRIPT('<>').xml(),
'''<script><!--
<>
//--></script>''')
self.assertEqual(SCRIPT().xml(), b'<script></script>')
示例3: tz_nice_detector_widget
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SCRIPT [as 别名]
def tz_nice_detector_widget(field, value, **attributes):
options = []
value_missing = True
for tzn in TZSETS:
#retrieve offset
localized = datetime.datetime.now(pytz.timezone(tzn[0]))
if value == tzn[0]:
# This is the preselected value.
value_missing = False
options.append(
OPTION(tzn[1], _value=tzn[0], _selected="selected",
data=dict(localized=localized.strftime('%Y-%m-%d %H:%M'))))
else:
options.append(
OPTION(tzn[1], _value=tzn[0],
data=dict(localized=localized.strftime('%Y-%m-%d %H:%M'))))
_id = '%s_%s' % (field._tablename, field.name)
_name = field.name
if value_missing and 'autodetect' in attributes and attributes.pop('autodetect') is True:
current.response.files.append(URL('static', 'plugin_timezone/jstz.min.js'))
script = """
jQuery(document).ready(function () {
var tz = jstz.determine();
var nice_tz_select = jQuery('#%(_id)s');
nice_tz_select.on('change.plugin_timezone', function(e, data) {
var localized = jQuery('#%(_id)s option:selected').data('localized');
var placeholder = '#plugin_timezone_localized';
if (!jQuery(placeholder).length) nice_tz_select.after('<span id="plugin_timezone_localized" style="display: block" />');
if (typeof (data) !== 'undefined') {
localized = 'auto: ' + localized;
}
else {
manual = 'auto: ' + localized;
}
// jQuery(placeholder).html(localized);
});
if (typeof (tz) !== 'undefined') {
var name = tz.name();
nice_tz_select.val(name).trigger('change.plugin_timezone', [name]);
}
});
""" % dict(_id=_id)
return CAT(SELECT(*options, _id=_id, _name=_name, **attributes), SCRIPT(script))
return SELECT(*options, _id=_id, _name=_name, **attributes)