@@ -230,7 +230,7 @@ $(function () {
230230 //model
231231 //http://githut.info/
232232 var topProgramLan = [ { "id" :"22,106" , "language" :"JavaScript, CoffeeScript" } , { "id" :"133,135" , "language" :"CSS" } , { "id" :"3,39" , "language" :"HTML" } , { "id" :137 , "language" :"Swift" } , { "id" :35 , "language" :"Objective-C" } , { "id" :23 , "language" :"Java" } , { "id" :19 , "language" :"Python" } , { "id" :24 , "language" :"PHP" } , { "id" :32 , "language" :"Ruby" } , { "id" :28 , "language" :"C" } , { "id" :16 , "language" :"C++" } , { "id" :6 , "language" :"C#" } , { "id" :55 , "language" :"Go" } , { "id" :51 , "language" :"Perl" } , { "id" :"104,109" , "language" :"Clojure, ClojureScript" } , { "id" :40 , "language" :"Haskell" } , { "id" :54 , "language" :"Lua" } , { "id" :20 , "language" :"Matlab" } , { "id" :144 , "language" :"R" } , { "id" :47 , "language" :"Scala" } , { "id" :"69,78,146" , "language" :"Shell" } , { "id" :29 , "language" :"Lisp" } , { "id" :42 , "language" :"ActionScript" } ] ;
233- var searchcode = new function ( ) {
233+ var searchcodeModel = new function ( ) {
234234 var persistLangsName = 'codelf_langs_selected' ;
235235 var langs = localStorage . get ( persistLangsName ) , langQuery ;
236236 var page = 0 ;
@@ -307,7 +307,7 @@ $(function () {
307307 }
308308 } ;
309309
310- var youdaoTranslate = new function ( ) {
310+ var youdaoTranslateModel = new function ( ) {
311311 var lastVal ;
312312 var translateRequestCallback ;
313313 this . request = function ( val , callback ) {
@@ -332,7 +332,7 @@ $(function () {
332332 }
333333 }
334334 } ;
335- var DDMS = new function ( ) {
335+ var DDMSModel = new function ( ) {
336336 var persistKeyWordsName = 'codelf_ddms_keywords' ;
337337 var persistKeyWordsTimerName = persistKeyWordsName + '_timer' ;
338338 var cacheKeyWords = ( localStorage . get ( persistKeyWordsName ) || '' ) . split ( ',' ) ;
@@ -361,7 +361,59 @@ $(function () {
361361 }
362362 } ;
363363
364- var beanHelpers = new function ( ) {
364+ var bookmarkModel = new function ( ) {
365+ this . repos = new function ( ) {
366+ var _this = this ;
367+ var page = 1 ;
368+ var mainData = [ ] ;
369+ function storeRepos ( data ) {
370+ mainData = mainData . concat ( data ) ;
371+ }
372+ this . request = function ( callback ) {
373+ $ . ajax ( {
374+ type : 'GET' ,
375+ dataType : 'json' ,
376+ url : 'https://api.github.com/users/unbug/repos?per_page=100&page=' + page ,
377+ success : function ( data ) {
378+ if ( data && data . length ) {
379+ storeRepos ( data ) ;
380+ page ++ ;
381+ _this . request ( callback ) ;
382+ } else {
383+ callback && callback ( mainData ) ;
384+ }
385+ }
386+ } ) ;
387+ }
388+ } ;
389+
390+ this . stars = new function ( ) {
391+ var _this = this ;
392+ var page = 1 ;
393+ var mainData = [ ] ;
394+ function storeRepos ( data ) {
395+ mainData = mainData . concat ( data ) ;
396+ }
397+ this . request = function ( callback ) {
398+ $ . ajax ( {
399+ type : 'GET' ,
400+ dataType : 'json' ,
401+ url : 'https://api.github.com/users/unbug/starred?per_page=100&page=' + page ,
402+ success : function ( data ) {
403+ if ( data && data . length ) {
404+ storeRepos ( data ) ;
405+ page ++ ;
406+ _this . request ( callback ) ;
407+ } else {
408+ callback && callback ( mainData ) ;
409+ }
410+ }
411+ } ) ;
412+ }
413+ } ;
414+ } ;
415+
416+ var beanHelpersModel = new function ( ) {
365417 this . getRandomLabelType = function ( ) {
366418 var types = [ 'default' , 'primary' , 'success' , 'info' , 'warning' , 'warning' , 'danger' ] ;
367419 return randomList ( types , 1 ) [ 0 ] ;
@@ -472,7 +524,7 @@ $(function () {
472524
473525 function showSourceCode ( ) {
474526 renderSourceCode ( ) ;
475- searchcode . requestSourceCode ( this . dataset . id , renderSourceCode ) ;
527+ searchcodeModel . requestSourceCode ( this . dataset . id , renderSourceCode ) ;
476528 this . dataset . val && renderRelatedProperty ( this . dataset . val ) ;
477529 els . sourceCodeModal . modal ( 'show' ) ;
478530 }
@@ -487,12 +539,12 @@ $(function () {
487539 checked . each ( function ( ) {
488540 lang . push ( this . value ) ;
489541 } ) ;
490- searchcode . setLang ( lang . join ( ' ' ) ) ;
542+ searchcodeModel . setLang ( lang . join ( ' ' ) ) ;
491543 renderSearchBtn ( 'Search' ) ;
492544 }
493545 function onResetLang ( ) {
494546 els . searchDropdownMenu . find ( 'input' ) . removeAttr ( 'checked' ) ;
495- searchcode . setLang ( ) ;
547+ searchcodeModel . setLang ( ) ;
496548 renderSearchBtn ( 'Search' ) ;
497549 }
498550 function onSearch ( val ) {
@@ -519,7 +571,7 @@ $(function () {
519571 } ) ;
520572 els . lastVal = tmpval . join ( ' ' ) ;
521573 if ( tmpch . length ) {
522- youdaoTranslate . request ( tmpch . join ( ' ' ) , function ( tdata ) {
574+ youdaoTranslateModel . request ( tmpch . join ( ' ' ) , function ( tdata ) {
523575 //basic translate
524576 if ( tdata . basic && tdata . basic . explains ) {
525577 els . valHistory = tdata . basic . explains . join ( ' ' ) ;
@@ -563,21 +615,21 @@ $(function () {
563615 function saveKeyWordRegs ( ) {
564616 els . valRegs = [ ] ;
565617 els . lastVal . replace ( / \s + / ig, '+' ) . split ( '+' ) . forEach ( function ( key ) {
566- key . length && els . valRegs . push ( beanHelpers . getKeyWordReg ( key ) ) ;
618+ key . length && els . valRegs . push ( beanHelpersModel . getKeyWordReg ( key ) ) ;
567619 } ) ;
568620 }
569621
570622 function doSearch ( ) {
571623 if ( els . lastVal && els . lastVal . length ) {
572- searchcode . request ( els . lastVal , renderSearchResult ) ;
624+ searchcodeModel . request ( els . lastVal , renderSearchResult ) ;
573625 renderSearchResultHeader ( 'loading' ) ;
574626 renderSearchBtn ( ) ;
575627 } else {
576628 renderSearchResultHeader ( 'error' ) ;
577629 renderSearchBtn ( 'Search' ) ;
578630 }
579631
580- els . isGithub && DDMS . postKeyWords ( els . lastInputVal ) ;
632+ els . isGithub && DDMSModel . postKeyWords ( els . lastInputVal ) ;
581633 renderAnalytics ( 'q=' + els . lastInputVal ) ;
582634 }
583635
@@ -608,7 +660,7 @@ $(function () {
608660 }
609661
610662 function renderLangMunu ( ) {
611- var htm = [ ] , storeLang = searchcode . getLang ( ) ;
663+ var htm = [ ] , storeLang = searchcodeModel . getLang ( ) ;
612664 storeLang = storeLang ?storeLang . split ( ' ' ) :[ ] ;
613665 topProgramLan . forEach ( function ( key ) {
614666 htm . push ( els . searchDropdownMenuTpl
@@ -651,7 +703,7 @@ $(function () {
651703 vals . push ( el ) ;
652704 //render variable labels
653705 labels . push ( els . searchResultTpl
654- . replace ( '{label_type}' , beanHelpers . getRandomLabelType ( ) )
706+ . replace ( '{label_type}' , beanHelpersModel . getRandomLabelType ( ) )
655707 . replace ( / \{ v a l \} / g, el )
656708 . replace ( '{id}' , rkey . id )
657709 . replace ( '{repo}' , rkey . repo )
@@ -750,7 +802,7 @@ $(function () {
750802 els . sourceCodeModalDropdownTpl . replace ( / \{ i d \} / g, ids [ i ] )
751803 . replace ( / \{ r e p o \} / g, repos [ i ] )
752804 . replace ( / \{ l a n g \} / g, langs [ i ] )
753- . replace ( / \{ l a b e l _ t y p e \} / g, beanHelpers . getRandomLabelType ( ) )
805+ . replace ( / \{ l a b e l _ t y p e \} / g, beanHelpersModel . getRandomLabelType ( ) )
754806 ) ;
755807 }
756808 }
@@ -779,6 +831,13 @@ $(function () {
779831 window . _bd_share_config = { "common" :{ "bdSnsKey" :{ } , "bdText" :"" , "bdMini" :"2" , "bdMiniList" :false , "bdPic" :"" , "bdStyle" :"0" , "bdSize" :"16" } , "slide" :{ "type" :"slide" , "bdImg" :"5" , "bdPos" :"right" , "bdTop" :els . body . height ( ) / 2 - 80 } } ; with ( document ) 0 [ ( getElementsByTagName ( 'head' ) [ 0 ] || body ) . appendChild ( createElement ( 'script' ) ) . src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~ ( - new Date ( ) / 36e5 ) ] ;
780832 }
781833
834+ bookmarkModel . repos . request ( function ( data ) {
835+ console . log ( 'repos' , data . length , data ) ;
836+ } ) ;
837+ bookmarkModel . stars . request ( function ( data ) {
838+ console . log ( 'stars' , data . length , data ) ;
839+ } ) ;
840+
782841 init ( ) ;
783842 //end view and render
784843} ) ;
0 commit comments