// Requires that JQuery also be in scope
function endsWith(str, suffix) {
if ( typeof str === "undefined" )
return false;
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
function findParentClass(curElement, classSuffix) {
var mainDiv = $(curElement).parent();
while ( !endsWith(mainDiv.attr('class'), classSuffix) ) {
mainDiv = $(mainDiv).parent();
}
return mainDiv;
}
function findItems(listTop, prefix) {
var selector = '[class ^= "'+prefix+'.inputList"]';
return $(selector, listTop);
}
function findTemplate(listTop, prefix) {
var selector = '[class = "'+prefix+'.inputListTemplate"]';
return $(selector, listTop);
}
function reIndex(item, prefix, curInd, newInd) {
var itemObj = $(item);
var pre = prefix+'.'
var a = pre+curInd
var b = pre+newInd
// We have to change the raw html because IE doesn't allow the
// name field to be changed.
var newH = itemObj.html().replace(new RegExp(a, 'g'), b);
itemObj.html(newH);
itemObj.attr('data-ind', b);
}
function getIndicesElem(listTop, prefix) {
var indicesSelector = '[name = "'+prefix+'.indices"]';
return $(indicesSelector, listTop);
}
function getIndices(indicesElem) {
var indicesText = indicesElem.val().split(',');
if ( indicesText[0] == '' ) {
indicesText[0] = '-1';
}
return indicesText.map(function(n){return parseInt(n,10)});
}
function removeIndex(listTop, prefix, ind) {
var indicesElem = getIndicesElem(listTop, prefix);
var indices = getIndices(indicesElem);
var newIndices = [];
var i;
for ( i = 0; i < indices.length; i++ ) {
if ( indices[i] != ind ) {
newIndices.push(indices[i]);
}
}
var newIndicesString = "";
if ( newIndices.length > 0 ) {
newIndicesString = newIndices[0].toString();
for ( i = 1; i < newIndices.length; i++ ) {
newIndicesString += ',' + newIndices[i];
}
}
var a = indicesElem.val();
indicesElem.val(newIndicesString);
var b = indicesElem.val();
}
function addInputListItem(button, prefix) {
var listTop = findParentClass(button, 'inputList');
var indicesElem = getIndicesElem(listTop, prefix);
var indices = getIndices(indicesElem);
var nextIndex = Math.max.apply(Math, indices)+1;
var cur = indicesElem.val();
if ( cur != '' ) {
cur = cur + ',';
}
indicesElem.val(cur+nextIndex);
$('.inputListInstance', listTop).each(function(i, instanceTop) {
var template = findTemplate(instanceTop, prefix)[0];
var pathComponents = $(template).attr('data-ind').split('.');
var ind = parseInt(pathComponents[pathComponents.length-1]);
var newItem = $(template).clone(true);
reIndex(newItem, prefix, ind, nextIndex);
newItem.removeAttr('style')
.removeClass(prefix+'.inputListTemplate')
.addClass(prefix+'.inputListItem');
var items = findItems(instanceTop, prefix);
newItem.appendTo($(items[items.length-1]).parent());
})
}
function removeInputListItem(button, prefix) {
var listTop = findParentClass(button, 'inputList');
var curListItem = findParentClass(button, 'inputListItem');
var itemPrefix = curListItem.attr('data-ind');
var prefixArr = itemPrefix.split('.');
var curInd = parseInt(prefixArr[prefixArr.length-1]);
removeIndex(listTop, prefix, curInd);
$('.inputListInstance', listTop).each(function(i, instanceTop) {
var r = prefix + '.' + curInd;
$('[data-ind="' + r +'"]', instanceTop).remove();
});
}
没有合适的资源?快使用搜索试试~ 我知道了~
使用应用函子消费输入的一般方法___下载.zip
共66个文件
hs:34个
ghci:6个
changelog:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 119 浏览量
2023-04-18
00:19:52
上传
评论
收藏 83KB ZIP 举报
温馨提示
使用应用函子消费输入的一般方法___下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
使用应用函子消费输入的一般方法___下载.zip (66个子文件)
digestive-functors-master
README.markdown 1KB
.travis.yml 546B
digestive-functors
Snap.hs 2KB
src
Text
Digestive.hs 944B
Digestive
Form
Internal
Field.hs 4KB
Internal.hs 15KB
Encoding.hs 3KB
List.hs 3KB
View.hs 12KB
Form.hs 23KB
Util.hs 521B
Ref.hs 1KB
Types.hs 3KB
LICENSE 2KB
tests
TestSuite.hs 796B
Text
Digestive
Form
List
QTests.hs 793B
Encoding
Tests.hs 1KB
QTests.hs 2KB
QTests.hs 4KB
Field
Tests.hs 1KB
QTests.hs 3KB
View
Tests.hs 8KB
Types
QTests.hs 1KB
Tests
Fixtures.hs 8KB
Setup.hs 46B
.ghci 39B
digestive-functors.cabal 3KB
digestive-functors.lhs 13KB
CHANGELOG 1KB
stack.yaml.lock 2KB
stack.yaml 300B
examples
happstack.hs 1KB
tutorial.lhs 8KB
snap-heist.hs 3KB
snaplets
heist
templates
user.tpl 37B
date-form.tpl 112B
user-form.tpl 466B
.ghci 192B
dynamic-list.hs 3KB
digestive-functors-heist
src
Text
Digestive
Heist.hs 19KB
Heist
Compiled.hs 26KB
js
df-list.js 3KB
LICENSE 2KB
Setup.hs 46B
.ghci 11B
digestive-functors-heist.cabal 1KB
CHANGELOG 557B
.gitignore 68B
digestive-functors-blaze
src
Text
Digestive
Blaze
Html5.hs 6KB
LICENSE 2KB
Setup.hs 46B
.ghci 33B
digestive-functors-blaze.cabal 892B
CHANGELOG 277B
digestive-functors-snap
src
Text
Digestive
Snap.hs 4KB
LICENSE 2KB
Setup.hs 46B
.ghci 33B
digestive-functors-snap.cabal 1016B
CHANGELOG 173B
digestive-functors-happstack
src
Text
Digestive
Happstack.hs 1KB
LICENSE 2KB
Setup.hs 46B
.ghci 39B
digestive-functors-happstack.cabal 862B
CHANGELOG 183B
共 66 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功