- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 yahoo ui 历史库。我没有找到避免用 Y.use 包装我的所有函数内容以便我可以访问历史对象的好方法。我尝试在 use() 命令之外全局声明它,但这似乎不起作用。如果您查看我的 showDashboard() 和 showReport1() 方法,您会发现我正在包装内容,对于使用历史记录的每个函数都必须这样做似乎是多余的。有一个更好的方法吗?
我见过的所有 yahoo 示例都根本没有 se 函数,而是将整个示例保存在一个单一的 use 方法中。
<div>
<a href="#" onclick="showDashboard(); return false;">Dashboard</a> |
<a href="#" onclick="showReport1(); return false;">Report 1</a>
</div>
<script type="text/javascript">
// Global reference to Yahoo UI object
var Y = YUI();
function showDashboard() {
Y.use('*', function (Y) {
var history = new Y.HistoryHash();
history.addValue("report", "dashboard");
});
}
function showReport1() {
Y.use('*', function (Y) {
var history = new Y.HistoryHash();
history.addValue('report', "report1");
//var x = { 'report': 'report1', 'date': '11/12/2012' };
//history.addValue("report", x);
});
}
Y.use('history', 'tabview', function (Y) {
var history = new Y.HistoryHash();
var tabview = new Y.TabView({ srcNode: '#demo' });
// Render the TabView widget to turn the static markup into an
// interactive TabView.
tabview.render();
// Set the selected report to the bookmarked history state, or to
// the first report if there's no bookmarked state.
tabview.selectChild(history.get('report') || 0);
// Store a new history state when the user selects a report.
tabview.after('selectionChange', function (e) {
// If the new tab index is greater than 0, set the "tab"
// state value to the index. Otherwise, remove the "tab"
// state value by setting it to null (this reverts to the
// default state of selecting the first tab).
history.addValue('report', e.newVal.get('index') || 0);
});
// Listen for history changes from back/forward navigation or
// URL changes, and update the report selection when necessary.
Y.on('history:change', function (e) {
// Ignore changes we make ourselves, since we don't need
// to update the selection state for those. We're only
// interested in outside changes, such as the ones generated
// when the user clicks the browser's back or forward buttons.
if (e.src === Y.HistoryHash.SRC_HASH) {
if (e.changed.report) {
// The new state contains a different report selection, so
// change the selected report.
tabview.selectChild(e.changed.report.newVal);
} else if (e.removed.report) {
// The report selection was removed in the new state, so
// select the first report by default.
tabview.selectChild(0);
}
}
if (e.changed.report) {
alert("New value: " + e.changed.report.newVal);
alert("Old value: " + e.changed.report.prevVal);
}
});
});
</script>
</form>
</body>
</html>
最佳答案
不是在点击时使用普通函数,而是使用 YUI 附加处理程序。如果您可以更改 HTML 代码 - 将 id 或 class 添加到链接,例如
<a id="btnShowDashboard" href="#">Dashboard</a>
然后在您的 use() 中为按钮添加点击处理程序
Y.use('history', 'tabview', 'node', 'event', function (Y) {
var bntShowDashboard = Y.one('#btnShowDashboard');
if (bntShowDashboard) {
bntShowDashboard.on('click', function(e) {
e.preventDefault();
var history = new Y.HistoryHash();
history.addValue("report", "dashboard");
});
}
...
})
这样你就可以确定在执行“历史记录”的那一刻被加载了。但是有一个缺点 - 在加载 YUI 模块之前,如果您单击链接,则什么也不会发生。
关于javascript - YUI 库 - 保持对对象的全局引用的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9266874/
在过去的两年里,我一直在广泛使用 jQuery 和 ExtJs 进行编程。我认为现在是时候花一些时间来学习令人印象深刻的 YUI 库了。 在从头开始学习方面什么是可取的? 我不打算在我 future
我们使用 YUI3 加载器来管理加载我们的 javascript 和 css 文件。作为每个页面上引导 js 代码的一部分,我们有如下内容: YUI({ ... groups: {
我有一个 YUI 数据表,我将以下数据放入表中: {key:"name", label:"name", editor: nameChoiceEditor}, {key:"group", label
我想向已经包含 Prototype 和 Scriptaculous 的页面添加日历控件。对我能找到的任何原型(prototype)都不满意,我正在考虑使用 YUI 日历小部件。 我这可能会导致什么问题
我可以使用多个下拉菜单和分页的 YUI 数据表来过滤静态数据集的行吗? http://www.mappingbahia.org/project/iguape_dataset.html 最佳答案 每个
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
在我们的 SSL 页面上使用 YUI 脚本会破坏 SSL 连接,因为它们通过 http 连接动态加载来自 yahoo(组合)的脚本。 由于我们只使用 YUI 3 的历史管理器,所以我想将代码托管在我们
我使用以下代码通过 YUI 在页面正文中创建一个 html 元素。此代码不会产生任何错误。 问题是,段落元素没有在 html 页面中创建。 YUI Test
YUI Compressor,在其(不是很广泛的)文档中将其作为一个选项: --disable-optimizations Disable all the built-in micro opt
如果我运行这样的测试用例,我的测试结果将显示在 YUI 测试控制台小部件中: YUI({debug: true}).use('test', 'event-base', 'test-console',
YUI.add 和 YUI().add 有什么区别? 最佳答案 在第一种情况下,您要注册一个模块可以加载到 YUI 沙箱中,在第二种情况下,您要构建一个沙箱,然后进行注册(这是一种非常不典型的用法)。
我一直在使用 YUI 库来开发网站。 YUI 3 于 9 月发布。 我仍然不确定是否必须为迁移做好准备。 第三版比第二版有什么优势? 您最近参与过这样的迁移吗? 最佳答案 我没有参与迁移,但我为 YU
将 Yahoo JS 和 CSS 库从版本 2 升级到版本 3 的迁移路径是什么? 特别是:CSS 和字体、按钮、TabView。 如能提供有关所遇到问题的更多信息、简化问题的提示等,我们将不胜感激。
我遇到的问题是它也跟踪日志阅读器中的所有事件。这使得它很难使用。当我向上向下滚动、在阅读器中单击或移动以检查事件时,它会在各处滚动以添加新事件。有没有办法过滤它以仅包含来自某些来源的某些事件?我可能做
这个问题主要是出于学术兴趣。 我今天开始使用 YUI 3,并偶然发现了它的沙箱概念。在彻底尝试在 DOM 中找到一些对象(比如我注册的事件处理程序)后,我不得不放弃。我只是找不到任何实例对象结束于此。
YUI 似乎非常专注于为浏览器和 node.js 提供所有相同的代码。 这非常强大,因为现在我可以在两端使用相同的测试,而不必重写/重新学习任何东西。 在测试方面,谷歌是否也专注于 node.js?
我正在尝试使用 Maven 的 YUI Compressor 插件来压缩我的 CSS 和 JavaScript,但我遇到了两个问题。 我的配置正确地压缩和聚合了 JavaScript 文件,但是如果我
我正在使用Yahoo.Yui.Compressor.Build.MsBuild压缩 css 和 javascript 文件。我已经安装了Yahoo.Yui.Compressor.Build.MsBui
我正在尝试使用 YUI 3.3.0 预览版 3 charting solution因为它不再使用 Flash,而是使用浏览器 Canvas 。到目前为止,我把这些和平的代码拼凑在一起(因为我是 YUI
我正在使用 YUI,需要获取元素的真实宽度。元素的宽度可以如下确定。 宽度 + 左边框 + 右边框 + 左填充 + 右填充 + 左边距 + 右边距。 下面是我想出的。它似乎正在工作。我只是想知道这是确
我是一名优秀的程序员,十分优秀!