/*
* d7lookup — plugin based on jQuery for platform SCAD7
*
* Copyright (c) 2019 Dobrynin P. Yu.
*
* Version: 1.0.0
*
* home page link:
* http://platforma.scad7.ru
*
* Добавить динамический список JSON
(function( $ ){
var methods = {
init : function( options ) {
var settings = $.extend({
‘url’ : »
,’ajob’ : »
,’term’ : »
}, options);
return this.each(function(index){
var $this = $(this), data = $this.data(‘d7lookup’);
if ( ! data) {
$(this).data(‘d7lookup’, {
target : $this
, url : settings.url
, ajob : settings.ajob
, term : settings.term
});
}
data = $this.data(‘d7lookup’);
// — создание списка option —
$.getJSON(data.url+’&ajob=’ + data.ajob + ‘&term=’ + data.term
, function(data) {
var items = [];
items.push(‘‘);
$.each(data, function(key,val){
items.push(‘‘);
});
$this.html( items.join(») );
});
}); //return
}//init
, destroy : function() {
return this.each(function(){
var $this = $(this), data = $this.data(‘d7lookup’);
$(window).unbind(‘.d7lookup’);
//data.target.removeAttr(data.attr);
$this.removeData(‘d7lookup’);
}); //return
}//destroy
, run : function run() {
return this.each(function() {
return this;
}); //return
}//run
};
$.fn.d7lookup= function( method ) {
if ( methods[method] ) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if ( typeof method === ‘object’ || ! method) {
return methods.init.apply( this, arguments );
} else {
$.error( ‘Метод с именем ‘ + method + ‘ не существует для jQuery.d7lookup’ );
}
};
})( jQuery )