2015-04-04 06:28:51 +00:00
|
|
|
/*
|
|
|
|
|
* Installs class
|
|
|
|
|
*
|
|
|
|
|
* Dependences:
|
|
|
|
|
* - Waterfall plugin (waterfall.js)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
+function ($) { "use strict";
|
|
|
|
|
|
|
|
|
|
var InstallProcess = function () {
|
|
|
|
|
|
|
|
|
|
// Init
|
|
|
|
|
this.init()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InstallProcess.prototype.init = function() {
|
|
|
|
|
var self = this
|
|
|
|
|
|
|
|
|
|
this.dataSet = {}
|
|
|
|
|
|
2015-08-15 04:16:16 +00:00
|
|
|
$(document).ready(function() {
|
2015-04-04 06:28:51 +00:00
|
|
|
|
|
|
|
|
self.bindSearch('#pluginSearchInput')
|
|
|
|
|
self.bindSearch('#themeSearchInput')
|
|
|
|
|
|
|
|
|
|
self.bindSuggested('#suggestedPlugins')
|
|
|
|
|
self.bindSuggested('#suggestedThemes')
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Searching
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
InstallProcess.prototype.bindSearch = function(el) {
|
|
|
|
|
var $el = $(el),
|
|
|
|
|
$form = $el.closest('form'),
|
|
|
|
|
searchType = $el.data('searchType')
|
|
|
|
|
|
|
|
|
|
if ($el.length == 0) return
|
|
|
|
|
|
|
|
|
|
// Template for search results
|
2015-06-04 10:46:38 +00:00
|
|
|
var template = [
|
2015-04-04 06:28:51 +00:00
|
|
|
'<div class="product-details">',
|
|
|
|
|
'<div class="product-image"><img src="{{image}}" alt=""></div>',
|
2020-01-23 19:07:18 +00:00
|
|
|
'<div class="product-name ">{{name}} by {{author}}</div>',
|
2015-04-04 06:28:51 +00:00
|
|
|
'<div class="product-description text-overflow">{{description}}</div>',
|
|
|
|
|
'</div>'
|
2015-06-04 10:46:38 +00:00
|
|
|
].join('')
|
|
|
|
|
|
|
|
|
|
// This operation parses the template and caches
|
|
|
|
|
// the resulting token tree. All future calls to
|
|
|
|
|
// mustache.render can now skip the parsing step.
|
|
|
|
|
Mustache.parse(template)
|
|
|
|
|
|
|
|
|
|
var mTemplate = function (view, partials) {
|
|
|
|
|
return Mustache.render(template, view, partials)
|
|
|
|
|
}
|
2015-04-04 06:28:51 +00:00
|
|
|
|
|
|
|
|
// Source for product search
|
|
|
|
|
var engine = new Bloodhound({
|
|
|
|
|
name: 'products',
|
|
|
|
|
method: 'POST',
|
2015-04-21 10:02:24 +00:00
|
|
|
remote: {
|
|
|
|
|
url: window.location.pathname + '?search=' + searchType + '&query=%QUERY',
|
|
|
|
|
ajax: {
|
|
|
|
|
beforeSend: function() {
|
|
|
|
|
$('.icon', $form).hide()
|
|
|
|
|
$('.icon.loading', $form).show()
|
|
|
|
|
$el.data('searchReady', false)
|
|
|
|
|
},
|
|
|
|
|
complete: function() {
|
|
|
|
|
$('.icon', $form).show()
|
|
|
|
|
$('.icon.loading', $form).hide()
|
|
|
|
|
$el.data('searchReady', true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2015-04-04 06:28:51 +00:00
|
|
|
datumTokenizer: function(d) {
|
|
|
|
|
return Bloodhound.tokenizers.whitespace(d.val)
|
|
|
|
|
},
|
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
|
limit: 5
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
engine.initialize()
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Bind autocomplete to search field
|
|
|
|
|
*/
|
|
|
|
|
$(el)
|
|
|
|
|
.typeahead(null, {
|
|
|
|
|
displayKey: 'code',
|
|
|
|
|
source: engine.ttAdapter(),
|
|
|
|
|
minLength: 3,
|
|
|
|
|
templates: {
|
2015-06-04 10:46:38 +00:00
|
|
|
suggestion: mTemplate
|
2015-04-04 06:28:51 +00:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.on('typeahead:opened', function(){
|
|
|
|
|
$(el + ' .tt-dropdown-menu').css('width', $(el).width() + 'px')
|
|
|
|
|
})
|
|
|
|
|
.on('typeahead:selected', function(object, datum){
|
|
|
|
|
$form.submit()
|
|
|
|
|
})
|
|
|
|
|
.on('keypress', function(e) {
|
|
|
|
|
if (e.keyCode == 13) // ENTER key
|
|
|
|
|
$form.submit()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InstallProcess.prototype.searchSubmit = function(el) {
|
|
|
|
|
var
|
|
|
|
|
$el = $(el),
|
|
|
|
|
$input = $el.find('.product-search-input.tt-input:first')
|
|
|
|
|
|
2015-04-21 10:02:24 +00:00
|
|
|
if (!$input.data('searchReady'))
|
|
|
|
|
return
|
|
|
|
|
|
2015-04-04 06:28:51 +00:00
|
|
|
$el.popup()
|
|
|
|
|
|
|
|
|
|
$input.typeahead('val', '')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Suggested products
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
InstallProcess.prototype.bindSuggested = function(el) {
|
|
|
|
|
var
|
|
|
|
|
self = this,
|
|
|
|
|
handler = $(el).data('handler')
|
|
|
|
|
|
|
|
|
|
$.request(handler).done(function(data){
|
|
|
|
|
var result = data.result
|
|
|
|
|
if (!$.isArray(result)) return
|
|
|
|
|
self.renderSuggested(el, result)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InstallProcess.prototype.renderSuggested = function(el, suggestedProducts) {
|
|
|
|
|
var self = this,
|
|
|
|
|
$el = $(el),
|
|
|
|
|
$container = $el.closest('.suggested-products-container'),
|
|
|
|
|
partialView = $(el).data('view')
|
|
|
|
|
|
|
|
|
|
if (suggestedProducts.length == 0) {
|
|
|
|
|
$container.hide()
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$container.show()
|
|
|
|
|
$.each(suggestedProducts, function(index, product) {
|
|
|
|
|
self.renderPartial($el, partialView, product, { append:true })
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Helpers
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
InstallProcess.prototype.renderPartial = function($el, name, data, options) {
|
|
|
|
|
var container = $el,
|
|
|
|
|
template = $('[data-partial="' + name + '"]'),
|
|
|
|
|
contents = Mustache.to_html(template.html(), data)
|
|
|
|
|
|
|
|
|
|
options = $.extend(true, {
|
|
|
|
|
append: false
|
|
|
|
|
}, options)
|
|
|
|
|
|
|
|
|
|
if (options.append) container.append(contents)
|
|
|
|
|
else container.html(contents)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($.oc === undefined)
|
|
|
|
|
$.oc = {}
|
|
|
|
|
|
|
|
|
|
$.oc.installProcess = new InstallProcess;
|
|
|
|
|
|
|
|
|
|
}(window.jQuery);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* typeahead.js 0.10.1
|
|
|
|
|
* https://github.com/twitter/typeahead.js
|
|
|
|
|
* Copyright 2013 Twitter, Inc. and other contributors; Licensed MIT
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
!function(a){var b={isMsie:function(){return/(msie|trident)/i.test(navigator.userAgent)?navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2]:!1},isBlankString:function(a){return!a||/^\s*$/.test(a)},escapeRegExChars:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},isString:function(a){return"string"==typeof a},isNumber:function(a){return"number"==typeof a},isArray:a.isArray,isFunction:a.isFunction,isObject:a.isPlainObject,isUndefined:function(a){return"undefined"==typeof a},bind:a.proxy,each:function(b,c){function d(a,b){return c(b,a)}a.each(b,d)},map:a.map,filter:a.grep,every:function(b,c){var d=!0;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?void 0:!1}),!!d):d},some:function(b,c){var d=!1;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?!1:void 0}),!!d):d},mixin:a.extend,getUniqueId:function(){var a=0;return function(){return a++}}(),templatify:function(b){function c(){return String(b)}return a.isFunction(b)?b:c},defer:function(a){setTimeout(a,0)},debounce:function(a,b,c){var d,e;return function(){var f,g,h=this,i=arguments;return f=function(){d=null,c||(e=a.apply(h,i))},g=c&&!d,clearTimeout(d),d=setTimeout(f,b),g&&(e=a.apply(h,i)),e}},throttle:function(a,b){var c,d,e,f,g,h;return g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)},function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},noop:function(){}},c="0.10.1",d=function(){function a(a){this.maxSize=a||100,this.size=0,this.hash={},this.list=new c}function c(){this.head=this.tail=null}function d(a,b){this.key=a,this.val=b,this.prev=this.next=null}return b.mixin(a.prototype,{set:function(a,b){var c,e=this.list.tail;this.size>=this.maxSize&&(this.list.remove(e),delete this.hash[e.key]),(c=this.hash[a])?(c.val=b,this.list.moveToFront(c)):(c=new d(a,b),this.list.add(c),this.hash[a]=c,this.size++)},get:function(a){var b=this.hash[a];return b?(this.list.moveToFront(b),b.val):void 0}}),b.mixin(c.prototype,{add:function(a){this.head&&(a.next=this.head,this.head.prev=a),this.head=a,this.tail=this.tail||a},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev},moveToFront:function(a){this.remove(a),this.add(a)}}),a}(this),e=function(){function a(a){this.prefix=["__",a,"__"].join(""),this.ttlKey="__ttl__",this.keyMatcher=new RegExp("^"+this.prefix)}function c(){return(new Date).getTime()}function d(a){return JSON.stringify(b.isUndefined(a)?null:a)}function e(a){return JSON.parse(a)}var f,g;try{f=window.localStorage,f.setItem("~~~","!"),f.removeItem("~~~")}catch(h){f=null}return g=f&&window.JSON?{_prefix:function(a){return this.prefix+a},_ttlKey:function(a){return this._prefix(a)+this.ttlKey},get:function(a){return this.isExpired(a)&&this.remove(a),e(f.getItem(this._prefix(a)))},set:function(a,e,g){return b.isNumber(g)?f.setItem(this._ttlKey(a),d(c()+g)):f.removeItem(this._ttlKey(a)),f.setItem(this._prefix(a),d(e))},remove:function(a){return f.removeItem(this._ttlKey(a)),f.removeItem(this._prefix(a)),this},clear:function(){var a,b,c=[],d=f.length;for(a=0;d>a;a++)(b=f.key(a)).match(this.keyMatcher)&&c.push(b.replace(this.keyMatcher,""));for(a=c.length;a--;)this.remove(c[a]);return this},isExpired:function(a){var d=e(f.getItem(this._ttlKey(a)));return b.isNumber(d)&&c()>d?!0:!1}}:{get:b.noop,set:b.noop,remove:b.noop,clear:b.noop,isExpired:b.noop},b.mixin(a.prototype,g),a}(),f=function(){function c(b){b=b||{},this._send=b.transport?e(b.transport):a.ajax,this._get=b.rateLimiter?b.rateLimiter(this._get):this._get}function e(c){return function(d,e){function f(a){b.defer(function(){h.resolve(a)})}function g(a){b.defer(function(){h.reject(a)})}var h=a.Deferred();return c(d,e,f,g),h}}var f=0,g={},h=6,i=new d(10);return c.setMaxPendingRequests=function(a){h=a},c.resetCache=function(){i=new d(10)},b.mixin(c.prototype,{_get:function(a,b,c){function d(b){c&&c(b),i.set(a,b)}function e(){f--,delete g[a],k.onDeckRequestArgs&&(k._get.apply(k,k.onDeckRequestArgs),k.onDeckRequestArgs=null)}var j,k=this;(j
|