- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试修改自动生成的 .js 文件以查询是否加载了某个外部文件,如果没有,则加载该文件。
更具体地说,我正在处理由 Tumult Hype 生成的一系列文档。该应用程序生成一系列 .js 文件。但是,有一项未包含的功能允许对生成的嵌入式代码进行完全响应式缩放。
Tumult Hype 在其支持知识库 http://hype.desk.com/customer/portal/articles/259191-responsive-size-for-your-project-resizing-your-document-to-fit-in-a-window-or-element 中定义了解决方案建议加载 jQuery 并将以下脚本添加到文档的头部:
<script type="text/javascript" language="javascript">
var alsoenlarge = true;
$(function(){
if(isScalePossible()){
$('body').css({overflow:'hidden'}); //no scroll bars
$('#scalecontainer').css({position: 'absolute', margin: 0}); //centering by hand after resize
// Run scale function on start
scaleSite();
scaleSite();
// run scale function on browser resize
$(window).resize(scaleSite);
}
});
function scaleSite()
{
windoww = $(window).width();
windowh = $(window).height();
sitew = $('#scalecontainer').width();
siteh = $('#scalecontainer').height();
f = windoww/sitew;
f = windowh/siteh<f?windowh/siteh:f;
if(!alsoenlarge && f>1) f = 1;
$('#scalecontainer').css({
"-moz-transform" : "scale("+f+")",
"-webkit-transform" : "scale("+f+")",
"-ms-transform" : "scale("+f+")",
"-o-transform" : "scale("+f+")",
"transform" : "scale("+f+")",
"left" : ((windoww-(sitew*f))/2)+"px",
"top" : ((windowh-(siteh*f))/2)+"px"
});
}
function isScalePossible()
{
can = 'MozTransform' in document.body.style;
if(!can) can = 'webkitTransform' in document.body.style;
if(!can) can = 'msTransform' in document.body.style;
if(!can) can = 'OTransform' in document.body.style;
if(!can) can = 'transform' in document.body.style;
if(!can) can = 'Transform' in document.body.style;
return can;
}
</script>
但是,由于此代码将在 Joomla 环境中使用,并且不需要在整个站点范围内使用,而仅在特定页面上需要,因此除非明确需要,否则我不希望调用该脚本。
Hype 生成的代码有几个部分。
有这样的html:
<!-- copy these lines to your document: -->
<div id="scaletest_hype_container" style="position:relative;overflow:hidden;width:1024px;height:800px;">
<script type="text/javascript" charset="utf-8" src="scaletest_Resources/scaletest_hype_generated_script.js?29990"></script>
</div>
<!-- end copy -->
此 html 导入一个名为 scaletest_hype_generated_script.js
的特定 .js 文件(名称的 scaletest 部分从炒作文档变为炒作文档)
然后该文档加载网络浏览器呈现炒作文件所需的所有资源。
scaletest_hype_generated_script.js
文件的第 25-40 行是一个查询,用于验证是否加载了另一个名为 HYPE.js
的 .js 文件,如果没有加载, 加载该文件。代码如下:
// load HYPE.js if it hasn't been loaded yet
if(typeof HYPE_108 == "undefined") {
if(typeof window.HYPE_108_DocumentsToLoad == "undefined") {
window.HYPE_108_DocumentsToLoad = new Array();
window.HYPE_108_DocumentsToLoad.push(HYPE_DocumentLoader);
var headElement = document.getElementsByTagName('head')[0];
var scriptElement = document.createElement('script');
scriptElement.type= 'text/javascript';
scriptElement.src = resourcesFolderName + '/' + 'HYPE.js?hype_version=108';
headElement.appendChild(scriptElement);
} else {
window.HYPE_108_DocumentsToLoad.push(HYPE_DocumentLoader);
}
return;
}
我想做的是在上面的代码之后立即向该文件添加 2 个额外的查询:
然后我会将上述脚本另存为外部 .js 文件,并将其相对于站点的根目录放置在名为 /hype
的目录中。该文件将被称为 scaleableHype.js
另外,我想修改HYPE.js
文件的路径。由于网站上有几十个炒作动画,调用同一个文件的多个副本是多余的。默认情况下,HYPE.js
文件在每个炒作内容的资源文件夹中。
目前我的目录结构如下:
/hype
|-/resourceFolder1
|--|--HYPE.js
|--|--PIE.htc
|--|--image1.jpg
|--|--documentName1_hype_generated_script.js
|-/resourceFolder2
|--|--HYOE.js
|--|--PIE.htc
|--|--pic1.png
|--|--documentName2_hype_generated_script.js
我想要脚本,例如 documentName1_hype_generated_script.js
和 documentName2_hype_generated_script.js
加载 HYPE.js< 的相同(不是多个)副本
文件,从而消除了重复。
如有任何建议,我们将不胜感激。谢谢
最佳答案
您可以尝试使用此代码来检测 documentName1_hype_generated_script.js 和 documentName2_hype_generated_script.js 是否已被加载,如果没有,则加载它。
<?php
if(!JFactory::getApplication()->get('HYPE')){
JFactory::getApplication()->set('HYPE',true);
$document =& JFactory::getDocument();
$document->addScript(JURI::root() . "path/to/HYPE.js");
}
if(!JFactory::getApplication()->get('jquery')){
JFactory::getApplication()->set('jquery',true);
$document =& JFactory::getDocument();
$document->addScript(JURI::root() . "path/to/jquery.js");
}
if(!JFactory::getApplication()->get('hypeScale')){
JFactory::getApplication()->set('hypeScale',true);
$document =& JFactory::getDocument();
$document->addScript(JURI::root() . "path/to/hypeScale.js");
}
?>
关于javascript - 如果尚未通过另一个 .js 文件加载,则导入/拉入外部 .js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13950223/
我正在尝试从 json 数据中获取事件日历。我只想突出显示日期,并在用户单击日期时在日历下方更新一个包含事件详细信息的 div。我的应用以以下形式提供 JSON: [ {"Date":"02/06
今天是我玩 GCR 和 GKE 的第一天。如果我的问题听起来很幼稚,请道歉。 所以我在 GCR 中创建了一个新的注册表。它是私有(private)的。使用 this文档,我使用命令获取了我的访问 to
我一直在尝试从 Meteor 内部的 Mongo 中提取一个数组,但我似乎无法让它工作。我能够很好地插入它。任何帮助将不胜感激。这是我的 html: {{#each employee.sch
我有一个 (datetime.timedelta(0, 7200) 的对象对于 2:00:00我正在尝试将其转换为 2.0两个小时。分别如果我有datetime.timedelta(0, 9000)
我刚刚开始学习 Hadoop,我想知道以下问题:假设我有一堆我想要分析的大型 MySQL 生产表。 似乎我必须将所有表转储到文本文件中,以便将它们带入 Hadoop 文件系统——这是否正确,或者是否有
我不想提交一些已更改的文件(例如 web.config)。在拉取并更新到新的变更集之前,我必须将它们搁置起来。拉取和更新后,我必须将它们取消搁置。 我目前正在使用 TortoiseHG。有没有任何扩展
这个项目的背景。一开始是一项简单的家庭作业,要求我存储 5 个邮政编码及其对应的城市。当用户在文本框中输入邮政编码时,会返回对应的城市,反之亦然。我编写了返回这些值的代码,但后来我决定将所有邮政编码及
最新的 Google Newsstand 应用程序具有 ActionBar 和 ViewPager 选项卡栏,当向下滚动下方的列表时,它们会缓慢地显示屏幕顶部。 重要的是,它以与滚动列表相同的速度缓和
此脚本可以出色地将电子邮件提取到我的工作表中。我的问题是该函数只提取列出的前两个字段。例如,getPlainBody、getSubject - 尽管需要更多字段。因此,我没有使用一个函数来提取我需要的
我正在提取一些会有所不同的 JSON 数据...例如: 返回的数据可能是: [{"userID":"2779","UserFullName":" Absolute Pro-Formance"},{"u
我正试图从 Firebase 获取报价,但我很挣扎。当然,我也不知道我在做什么。我需要一些帮助! 在 Firebase 中,我的报价设置如下: root --> quotes --> quoteID
我将 UIRefreshControl 与 UICollectionView 一起使用。刷新有效,但 View 在拉动后不会停留在顶部(与 uitableview 一样)。有没有办法让这个坚持下去,还
我用来提取提要标题的脚本是: "; foreach($x->channel->item as $entry) { echo "link' title='$entry->title'>" .
我一直无法从 excel 中获取单元格值并在 word 宏中使用它们(我正在尝试在 word doc 中的各种书签处插入来自工作表单元格的字符串值)。现在我只是想能够访问单元格值,但我想出了一个错误
我正在尝试为 PhoneGap 设置一个 JSON 查询,该查询会提取通过 Expression Engine template 创建的 JSONP .如果我直接导航到我的 JSON 页面,htt
所以我有一个 Xcode 项目,我从注册页面获取字段,然后推送它们进行解析。我有另一个 View ,其中我有标签,我想将这些自定义字段从 Parse 拉入其中。 这是我存储数据的方式: 让我的用户:P
在 Matlab 中,我使用类似于以下的语句从 mySQL 数据库中提取数据: SELECT PrimaryKeyVar, Var1, MyDate, Var2, Var3 FROM MyDataba
在系统限制下工作,我需要一种方法将本地 .php 或 .html 中的工作代码放入目标 div 中,而无需额外的库、jfiddle、iframe 等(jquery 就可以) 这是我失败的尝试。 文件的
设置场景: 我已经设置了一个多节点Kubernetes cluster并部署了Jenkins Helm Chart与 Jenkins Kubernetes plugin .我们在(公司)内部运行企业
Controller : def get_nodes ... render :text => nodes.to_json.to_s end 它呈现有效的 JSON(它由我的 chrome 插件
我是一名优秀的程序员,十分优秀!